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
}
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());
}
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
}
}
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());
}
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;
}
Aggregations