Search in sources :

Example 1 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit-oak by apache.

the class PropertyTest method testMixTitleOnUnstructured.

public void testMixTitleOnUnstructured() throws Exception {
    Node n = testRootNode.addNode("unstructured", JcrConstants.NT_UNSTRUCTURED);
    n.addMixin("mix:title");
    superuser.save();
    // create jcr:title property with type LONG => declaring NT is nt:unstructured
    Property title = n.setProperty("jcr:title", 12345);
    assertEquals(PropertyType.LONG, title.getType());
    PropertyDefinition def = title.getDefinition();
    assertEquals(JcrConstants.NT_UNSTRUCTURED, def.getDeclaringNodeType().getName());
    assertEquals(PropertyType.UNDEFINED, def.getRequiredType());
    // changing value to STRING => ValueFormatException expected
    try {
        title.setValue("str");
        fail();
    } catch (ValueFormatException e) {
    // success
    }
    // re-setting property to STRING -> change definition => declaring NT is mix:title
    n.setProperty("jcr:title", "str");
    assertEquals(PropertyType.STRING, title.getType());
    assertEquals(PropertyType.STRING, title.getValue().getType());
    def = title.getDefinition();
    assertEquals("mix:title", def.getDeclaringNodeType().getName());
    assertEquals(PropertyType.STRING, def.getRequiredType());
}
Also used : Node(javax.jcr.Node) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 2 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit-oak by apache.

the class PropertyTest method testRequiredTypeLongChangeBoolean.

public void testRequiredTypeLongChangeBoolean() throws Exception {
    Property p = node.setProperty(LONG_PROP_NAME, 12345);
    assertEquals(PropertyType.LONG, p.getType());
    assertEquals(PropertyType.LONG, p.getValue().getType());
    PropertyDefinition def = p.getDefinition();
    assertEquals(PropertyType.LONG, def.getRequiredType());
    assertEquals(NT_NAME, def.getDeclaringNodeType().getName());
    superuser.save();
    try {
        p.setValue(true);
        fail("Conversion from BOOLEAN to LONG must throw ValueFormatException");
    } catch (ValueFormatException e) {
    // success
    }
    try {
        node.setProperty(LONG_PROP_NAME, true);
        fail("Conversion from BOOLEAN to LONG must throw ValueFormatException");
    } catch (ValueFormatException e) {
    // success
    }
}
Also used : ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 3 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit-oak by apache.

the class PropertyTest method testPathRequiredTypeLong.

public void testPathRequiredTypeLong() throws Exception {
    Value pathValue = superuser.getValueFactory().createValue("/path", PropertyType.PATH);
    try {
        Property p = node.setProperty(LONG_PROP_NAME, pathValue);
        fail("Conversion from PATH to LONG must throw ValueFormatException");
    } catch (ValueFormatException e) {
    // success
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 4 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit-oak by apache.

the class PropertyTest method testPathRequiredTypeBoolean.

public void testPathRequiredTypeBoolean() throws Exception {
    Value pathValue = superuser.getValueFactory().createValue("/path", PropertyType.PATH);
    try {
        Property p = node.setProperty(BOOLEAN_PROP_NAME, pathValue);
        fail("Conversion from PATH to BOOLEAN must throw ValueFormatException");
    } catch (ValueFormatException e) {
    // success
    }
}
Also used : Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) Property(javax.jcr.Property)

Example 5 with ValueFormatException

use of javax.jcr.ValueFormatException in project jackrabbit-oak by apache.

the class ACLTest method testMvRestrictions.

@Test
public void testMvRestrictions() throws Exception {
    ValueFactory vf = getValueFactory();
    Value[] vs = new Value[] { vf.createValue(JcrConstants.NT_FILE, PropertyType.NAME), vf.createValue(JcrConstants.NT_FOLDER, PropertyType.NAME) };
    Map<String, Value[]> mvRestrictions = Collections.singletonMap(REP_NT_NAMES, vs);
    Map<String, Value> restrictions = Collections.singletonMap(REP_GLOB, vf.createValue("/.*"));
    assertTrue(acl.addEntry(testPrincipal, testPrivileges, false, restrictions, mvRestrictions));
    assertFalse(acl.addEntry(testPrincipal, testPrivileges, false, restrictions, mvRestrictions));
    assertEquals(1, acl.getAccessControlEntries().length);
    JackrabbitAccessControlEntry ace = (JackrabbitAccessControlEntry) acl.getAccessControlEntries()[0];
    try {
        ace.getRestriction(REP_NT_NAMES);
        fail();
    } catch (ValueFormatException e) {
    // success
    }
    Value[] vvs = ace.getRestrictions(REP_NT_NAMES);
    assertArrayEquals(vs, vvs);
}
Also used : JackrabbitAccessControlEntry(org.apache.jackrabbit.api.security.JackrabbitAccessControlEntry) Value(javax.jcr.Value) ValueFormatException(javax.jcr.ValueFormatException) ValueFactory(javax.jcr.ValueFactory) Test(org.junit.Test)

Aggregations

ValueFormatException (javax.jcr.ValueFormatException)106 Value (javax.jcr.Value)53 Property (javax.jcr.Property)34 RepositoryException (javax.jcr.RepositoryException)16 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)12 Calendar (java.util.Calendar)10 ItemNotFoundException (javax.jcr.ItemNotFoundException)10 Node (javax.jcr.Node)10 QValue (org.apache.jackrabbit.spi.QValue)10 PathNotFoundException (javax.jcr.PathNotFoundException)6 Name (org.apache.jackrabbit.spi.Name)6 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)5 InternalValue (org.apache.jackrabbit.core.value.InternalValue)5 InputStream (java.io.InputStream)4 BigDecimal (java.math.BigDecimal)4 Date (java.util.Date)4 Path (org.apache.jackrabbit.spi.Path)4 ArrayList (java.util.ArrayList)3 HashSet (java.util.HashSet)3