Package org.apache.sling.api.resource

Examples of org.apache.sling.api.resource.PersistableValueMap


    }

    public void testPut()
    throws Exception {
        this.rootNode.getSession().refresh(false);
        final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
        assertContains(pvm, initialSet());
        assertNull(pvm.get("something"));

        // now put two values and check set again
        pvm.put("something", "Another value");
        pvm.put("string", "overwrite");

        final Map<String, Object> currentlyStored = this.initialSet();
        currentlyStored.put("something", "Another value");
        currentlyStored.put("string", "overwrite");
        assertContains(pvm, currentlyStored);

        pvm.save();
        assertContains(pvm, currentlyStored);

        final PersistableValueMap pvm2 = new JcrModifiablePropertyMap(this.rootNode);
        assertContains(pvm2, currentlyStored);
    }
View Full Code Here


    }

    public void testReset()
    throws Exception {
        this.rootNode.getSession().refresh(false);
        final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
        assertContains(pvm, initialSet());
        assertNull(pvm.get("something"));

        // now put two values and check set again
        pvm.put("something", "Another value");
        pvm.put("string", "overwrite");

        final Map<String, Object> currentlyStored = this.initialSet();
        currentlyStored.put("something", "Another value");
        currentlyStored.put("string", "overwrite");
        assertContains(pvm, currentlyStored);

        pvm.reset();
        assertContains(pvm, initialSet());

        final PersistableValueMap pvm2 = new JcrModifiablePropertyMap(this.rootNode);
        assertContains(pvm2, initialSet());
    }
View Full Code Here

    }

    public void testSerializable()
    throws Exception {
        this.rootNode.getSession().refresh(false);
        final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
        assertContains(pvm, initialSet());
        assertNull(pvm.get("something"));

        // now put a serializable object
        final List<String> strings = new ArrayList<String>();
        strings.add("a");
        strings.add("b");
        pvm.put("something", strings);

        // check if we get the list again
        @SuppressWarnings("unchecked")
        final List<String> strings2 = (List<String>) pvm.get("something");
        assertEquals(strings, strings2);

        pvm.save();

        final PersistableValueMap pvm2 = new JcrModifiablePropertyMap(this.rootNode);
        // check if we get the list again
        @SuppressWarnings("unchecked")
        final List<String> strings3 = (List<String>) pvm2.get("something", Serializable.class);
        assertEquals(strings, strings3);

    }
View Full Code Here

    }

    public void testExceptions() throws Exception {
        this.rootNode.getSession().refresh(false);
        final PersistableValueMap pvm = new JcrModifiablePropertyMap(this.rootNode);
        try {
            pvm.put(null, "something");
            fail("Put with null key");
        } catch (NullPointerException iae) {}
        try {
            pvm.put("something", null);
            fail("Put with null value");
        } catch (NullPointerException iae) {}
        try {
            pvm.put("something", pvm);
            fail("Put with non serializable");
        } catch (IllegalArgumentException iae) {}
    }
View Full Code Here

    public void testMixins() throws Exception {
        this.rootNode.getSession().refresh(false);
        final Node testNode = this.rootNode.addNode("testMixins" + System.currentTimeMillis());
        testNode.getSession().save();
        final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode);

        final String[] types = pvm.get("jcr:mixinTypes", String[].class);
        final Set<String> exNodeTypes = getMixinNodeTypes(testNode);

        assertEquals(exNodeTypes.size(), (types == null ? 0 : types.length));
        if ( types != null ) {
            for(final String name : types) {
                assertTrue(exNodeTypes.contains(name));
            }
            String[] newTypes = new String[types.length + 1];
            System.arraycopy(types, 0, newTypes, 0, types.length);
            newTypes[types.length] = "mix:referenceable";
            pvm.put("jcr:mixinTypes", newTypes);
        } else {
            pvm.put("jcr:mixinTypes", "mix:referenceable");
        }
        pvm.save();

        final Set<String> newNodeTypes = getMixinNodeTypes(testNode);
        assertEquals(newNodeTypes.size(), exNodeTypes.size() + 1);
    }
View Full Code Here

    public void testNamesReverse() throws Exception {
        this.rootNode.getSession().refresh(false);

        final Node testNode = this.rootNode.addNode("nameTest" + System.currentTimeMillis());
        testNode.getSession().save();
        final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode);
        pvm.put(TEST_PATH, VALUE);
        pvm.put(PROP1, VALUE1);
        pvm.put(PROP2, VALUE2);
        pvm.put(PROP3, VALUE3);
        pvm.save();

        // read with property map
        final ValueMap vm = this.createPropertyMap(testNode);
        assertEquals(VALUE, vm.get(TEST_PATH));
        assertEquals(VALUE1, vm.get(PROP1));
View Full Code Here

        final Node testNode = this.rootNode.addNode("nameUpdateTest"
                + System.currentTimeMillis());
        testNode.setProperty(PROP3, VALUE);
        testNode.getSession().save();

        final PersistableValueMap pvm = new JcrModifiablePropertyMap(testNode);
        pvm.put(PROP3, VALUE3);
        pvm.put("jcr:a:b", VALUE3);
        pvm.put("jcr:", VALUE3);
        pvm.save();

        // read with property map
        final ValueMap vm = this.createPropertyMap(testNode);
        assertEquals(VALUE3, vm.get(PROP3));
        assertEquals(VALUE3, vm.get("jcr:a:b"));
View Full Code Here

        assertNotNull("Expected ValueMap adapter", valueMap);
        assertEquals(target, valueMap.get(RedirectResource.PROP_SLING_TARGET));
        assertEquals(status, ((Integer) valueMap.get(RedirectResource.PROP_SLING_STATUS)).intValue());
        assertEquals(status, valueMap.get(RedirectResource.PROP_SLING_STATUS, Integer.class).intValue());

        final PersistableValueMap persistableValueMap = res.adaptTo(PersistableValueMap.class);
        assertNull("Unexpected PersistableValueMap adapter",
            persistableValueMap);
    }
View Full Code Here

TOP

Related Classes of org.apache.sling.api.resource.PersistableValueMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.