setpropertyvaluetest.java

来自「jsr170接口的java实现。是个apache的开源项目。」· Java 代码 · 共 512 行 · 第 1/2 页

JAVA
512
字号
                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if modifying properties with <code>Node.setProperty(String,     * Value[])</code> works with <code>Session.save()</code>     */    public void testModifyValueArrayPropertySession() throws Exception {        testNode.setProperty(propertyName2, vArray1);        superuser.save();        testNode.setProperty(propertyName2, vArray2);        superuser.save();        assertEquals("Modifying properties with Node.setProperty(String, Value[]) and Session.save() not working",                Arrays.asList(vArray2),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if adding properties with <code>Node.setProperty(String,     * Value[])</code> works with <code>parentNode.save()</code>     */    public void testNewValueArrayPropertyParent() throws Exception {        testNode.setProperty(propertyName2, vArray1);        testRootNode.save();        assertEquals("Setting properties with Node.setProperty(String, Value[]) and parentNode.save() not working",                Arrays.asList(vArray1),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if modifying properties with <code>Node.setProperty(String,     * Value[])</code> works with <code>parentNode.save()</code>     */    public void testModifyValueArrayPropertyParent() throws Exception {        testNode.setProperty(propertyName2, vArray1);        testRootNode.save();        testNode.setProperty(propertyName2, vArray2);        testRootNode.save();        assertEquals("Modifying properties with Node.setProperty(String, Value[]) and parentNode.save() not working",                Arrays.asList(vArray2),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if <code>Node.setProperty(String, Value[])</code> throws a {@link     * javax.jcr.ValueFormatException} when trying to set a multi-value property     * to an array of values with different types     */    public void testSetMixedValueArrayValueFormatException() throws Exception {        try {            testNode.setProperty(propertyName2, vArrayMixed);            fail("setProperty(String, mixedValueArray[]) not throwing a ValueFormatException");        } catch (ValueFormatException success) {        }    }    /**     * Tests if <code>Node.setProperty(String, Value[])</code> throws a {@link     * javax.jcr.ValueFormatException} when trying to set an existing     * single-valued property to a multi-value     */    public void testSetSingleValueArrayValueFormatException() throws Exception {        // prerequisite: existing single-valued property        if (!testNode.hasProperty(propertyName1)) {            testNode.setProperty(propertyName1, v1);            testNode.getParent().save();        }        try {            testNode.setProperty(propertyName1, vArray1);            fail("setProperty(singleValueProperty, Value[]) not throwing a ValueFormatException");        } catch (ValueFormatException success) {        }    }    /**     * Tests if removing a <code>Value[]</code> property with     * <code>Node.setProperty(String, null)</code> works with     * <code>Session.save()</code>     */    public void testRemoveValueArrayPropertySession() throws Exception {        testNode.setProperty(propertyName2, vArray1);        superuser.save();        testNode.setProperty(propertyName2, (Value[]) null);        superuser.save();        assertFalse("Removing property with Node.setProperty(String, (Value[])null) and Session.save() not working",                testNode.hasProperty(propertyName2));    }    /**     * Tests if removing a <code>Value[]</code> property with     * <code>Node.setProperty(String, null)</code> works with     * <code>parentNode.save()</code>     */    public void testRemoveValueArrayPropertyParent() throws Exception {        testNode.setProperty(propertyName2, vArray1);        testRootNode.save();        testNode.setProperty(propertyName2, (Value[]) null);        testRootNode.save();        assertFalse("Removing property with Node.setProperty(String, (Value[])null) and parentNode.save() not working",                testNode.hasProperty(propertyName2));    }    /**     * Tests if <code>Node.setProperty(String, Value[])</code> saves an array of     * null values as an empty Value[]     */    public void testSetNullValueArray() throws Exception {        testNode.setProperty(propertyName2, vArrayNull);        superuser.save();        assertEquals("Node.setProperty(String, nullValueArray[]) did not set the property to an empty Value[]",                Arrays.asList(new Value[0]),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if <code>Node.setProperty(String, Value[])</code> correctly compacts     * the value array by removing all null values     */    public void testCompactValueArrayWithNulls() throws Exception {        testNode.setProperty(propertyName2, vArrayWithNulls);        superuser.save();        assertEquals("Node.setProperty(String, valueArrayWithNulls[]) did not compact the value array by removing the null values",                2,                testNode.getProperty(propertyName2).getValues().length);    }    /**     * Value[] with PropertyType     */    /**     * Tests if adding properties with <code>Node.setProperty(String, Value[],     * int)</code> works with <code>Session.save()</code>     */    public void testNewValueArrayPropertySessionWithPropertyType() throws Exception {        testNode.setProperty(propertyName2, vArray1, PropertyType.STRING);        superuser.save();        assertEquals("Setting properties with Node.setProperty(String, Value[], int) and Session.save() not working",                Arrays.asList(vArray1),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if modifying properties with <code>Node.setProperty(String,     * Value[], int)</code> works with <code>Session.save()</code>     */    public void testModifyValueArrayPropertySessionWithPropertyType() throws Exception {        testNode.setProperty(propertyName2, vArray1, PropertyType.STRING);        superuser.save();        testNode.setProperty(propertyName2, vArray2, PropertyType.STRING);        superuser.save();        assertEquals("Modifying properties with Node.setProperty(String, Value[], int) and Session.save() not working",                Arrays.asList(vArray2),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if adding properties with <code>Node.setProperty(String, Value[],     * int)</code> works with <code>parentNode.save()</code>     */    public void testNewValueArrayPropertyParentWithPropertyType() throws Exception {        testNode.setProperty(propertyName2, vArray1, PropertyType.STRING);        testRootNode.save();        assertEquals("Setting properties with Node.setProperty(String, Value[], int) and parentNode.save() not working",                Arrays.asList(vArray1),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if modifying properties with <code>Node.setProperty(String,     * Value[], int)</code> works with <code>parentNode.save()</code>     */    public void testModifyValueArrayPropertyParentWithPropertyType() throws Exception {        testNode.setProperty(propertyName2, vArray1, PropertyType.STRING);        testRootNode.save();        testNode.setProperty(propertyName2, vArray2, PropertyType.STRING);        testRootNode.save();        assertEquals("Modifying properties with Node.setProperty(String, Value[], int) and parentNode.save() not working",                Arrays.asList(vArray2),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }    /**     * Tests if <code>Node.setProperty(String, Value[], int)</code> throws a     * {@link javax.jcr.ValueFormatException} when trying to set a multi-value     * property to an array of values with different types     */    public void testSetMixedValueArrayValueFormatExceptionWithPropertyType() throws Exception {        try {            testNode.setProperty(propertyName2, vArrayMixed, PropertyType.STRING);            fail("setProperty(String, mixedValueArray[], int) not throwing a ValueFormatException");        } catch (ValueFormatException success) {        }    }    /**     * Tests if <code>Node.setProperty(String, Value[], int)</code> throws a     * {@link javax.jcr.ValueFormatException} when trying to set an existing     * single-valued property to a multi-value     */    public void testSetSingleValueArrayValueFormatExceptionWithPropertyType() throws Exception {        // prerequisite: existing single-valued property        if (!testNode.hasProperty(propertyName1)) {            testNode.setProperty(propertyName1, v1);            testNode.getParent().save();        }        try {            testNode.setProperty(propertyName1, vArray1, PropertyType.STRING);            fail("setProperty(singleValueProperty, Value[], int) not throwing a ValueFormatException");        } catch (ValueFormatException success) {        }    }    /**     * Tests if removing a <code>Value[]</code> property with     * <code>Node.setProperty(String, null, int)</code> works with     * <code>Session.save()</code>     */    public void testRemoveValueArrayPropertySessionWithPropertyType() throws Exception {        testNode.setProperty(propertyName2, vArray1, PropertyType.STRING);        superuser.save();        testNode.setProperty(propertyName2, (Value[]) null, PropertyType.STRING);        superuser.save();        assertFalse("Removing property with Node.setProperty(String, (Value[])null, int) and Session.save() not working",                testNode.hasProperty(propertyName2));    }    /**     * Tests if removing a <code>Value[]</code> property with     * <code>Node.setProperty(String, null, int)</code> works with     * <code>parentNode.save()</code>     */    public void testRemoveValueArrayPropertyParentWithPropertyType() throws Exception {        testNode.setProperty(propertyName2, vArray1, PropertyType.STRING);        testRootNode.save();        testNode.setProperty(propertyName2, (Value[]) null, PropertyType.STRING);        testRootNode.save();        assertFalse("Removing property with Node.setProperty(String, (Value[])null, int) and parentNode.save() not working",                testNode.hasProperty(propertyName2));    }    /**     * Tests if <code>Node.setProperty(String, Value[], int)</code> saves an     * array of null values as an empty Value[]     */    public void testSetNullValueArrayWithPropertyType() throws Exception {        testNode.setProperty(propertyName2, vArrayNull, PropertyType.STRING);        superuser.save();        assertEquals("Node.setProperty(String, nullValueArray[], int) did not set the property to an empty Value[]",                Arrays.asList(new Value[0]),                Arrays.asList(testNode.getProperty(propertyName2).getValues()));    }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?