Search in sources :

Example 1 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit by apache.

the class NodeTypeCreationTest method testEmptyPropertyDefinitionTemplate.

public void testEmptyPropertyDefinitionTemplate() throws Exception {
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    assertNull(pdt.getName());
    assertFalse(pdt.isAutoCreated());
    assertFalse(pdt.isMandatory());
    assertFalse(pdt.isProtected());
    assertEquals(OnParentVersionAction.COPY, pdt.getOnParentVersion());
    assertNull(pdt.getDeclaringNodeType());
    assertEquals(PropertyType.STRING, pdt.getRequiredType());
    assertFalse(pdt.isMultiple());
    assertNull(pdt.getValueConstraints());
    assertNull(pdt.getDefaultValues());
// the following methods cannot be tested as default value is
// implementation specific:
// - getAvailableQueryOperators
// - isFullTextSearchable
// - isQueryOrderable
}
Also used : PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate)

Example 2 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit by apache.

the class NodeTypeCreationTest method testSetDefaultValues.

public void testSetDefaultValues() throws Exception {
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    pdt.setRequiredType(PropertyType.LONG);
    pdt.setDefaultValues(null);
    assertNull(pdt.getDefaultValues());
    pdt.setDefaultValues(new Value[0]);
    assertNotNull(pdt.getDefaultValues());
    assertEquals(0, pdt.getDefaultValues().length);
    pdt.setDefaultValues(new Value[] { superuser.getValueFactory().createValue(24) });
    assertNotNull(pdt.getDefaultValues());
    assertEquals(1, pdt.getDefaultValues().length);
    assertEquals(24, pdt.getDefaultValues()[0].getLong());
    assertEquals(PropertyType.LONG, pdt.getDefaultValues()[0].getType());
}
Also used : PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate)

Example 3 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit by apache.

the class NodeTypeCreationTest method testInvalidJCRNames.

public void testInvalidJCRNames() throws Exception {
    String invalidName = ":ab[2]";
    // invalid name(s) passed to NT-template methods
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
    try {
        ntt.setName(invalidName);
        fail("ConstraintViolationException expected. Nt-name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ntt.setDeclaredSuperTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
        fail("ConstraintViolationException expected. One of the super type names is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ntt.setPrimaryItemName(invalidName);
        fail("ConstraintViolationException expected. Primary item name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    // invalid name(s) passed to NodeDefinitionTemplate
    NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
    try {
        ndt.setName(invalidName);
        fail("ConstraintViolationException expected. Name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ndt.setRequiredPrimaryTypeNames(new String[] { "{" + NS_MIX_URI + "}" + "littlemixin", invalidName });
        fail("ConstraintViolationException expected. One of the required primary type names is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    try {
        ndt.setDefaultPrimaryTypeName(invalidName);
        fail("ConstraintViolationException expected. Default primary type name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
    // invalid name(s) passed to PropertyDefinitionTemplate
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    try {
        pdt.setName(invalidName);
        fail("ConstraintViolationException expected. Name is invalid");
    } catch (ConstraintViolationException e) {
    // success
    }
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 4 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit by apache.

the class NodeTypeCreationTest method testPropertyDefinitionTemplate.

public void testPropertyDefinitionTemplate() throws Exception {
    PropertyDefinitionTemplate pdt = createBooleanPropTemplate();
    assertEquals(jcrPropName, pdt.getName());
    try {
        pdt.setName(null);
        fail("null isn't a valid JCR name");
    } catch (ConstraintViolationException e) {
    // success
    }
    assertEquals(false, pdt.isAutoCreated());
    assertEquals(false, pdt.isMandatory());
    assertEquals(OnParentVersionAction.IGNORE, pdt.getOnParentVersion());
    assertEquals(false, pdt.isProtected());
    assertEquals(PropertyType.BOOLEAN, pdt.getRequiredType());
    assertEquals(null, pdt.getValueConstraints());
    assertEquals(null, pdt.getDefaultValues());
    assertEquals(false, pdt.isMultiple());
    String[] qo = pdt.getAvailableQueryOperators();
    assertEquals(1, qo.length);
    assertEquals(QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO, qo[0]);
    assertEquals(false, pdt.isFullTextSearchable());
    assertEquals(false, pdt.isQueryOrderable());
}
Also used : PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException)

Example 5 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate in project jackrabbit by apache.

the class NodeTypeCreationTest method createBooleanPropTemplate.

private PropertyDefinitionTemplate createBooleanPropTemplate() throws RepositoryException {
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    pdt.setName(expandedPropName);
    pdt.setAutoCreated(false);
    pdt.setMandatory(false);
    pdt.setOnParentVersion(OnParentVersionAction.IGNORE);
    pdt.setProtected(false);
    pdt.setRequiredType(PropertyType.BOOLEAN);
    pdt.setValueConstraints(null);
    pdt.setDefaultValues(null);
    pdt.setMultiple(false);
    pdt.setAvailableQueryOperators(new String[] { QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO });
    pdt.setFullTextSearchable(false);
    pdt.setQueryOrderable(false);
    return pdt;
}
Also used : PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate)

Aggregations

PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)37 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)15 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)9 Node (javax.jcr.Node)7 Session (javax.jcr.Session)7 List (java.util.List)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Value (javax.jcr.Value)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)4 Test (org.junit.Test)4 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStream (java.io.InputStream)2 BigDecimal (java.math.BigDecimal)2 Binary (javax.jcr.Binary)2 NamespaceRegistry (javax.jcr.NamespaceRegistry)2 RepositoryException (javax.jcr.RepositoryException)2 NodeType (javax.jcr.nodetype.NodeType)2 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)2