use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class CanSetPropertyBooleanTest method testValueConstraintNotSatisfiedMultiple.
/**
* Tests if canSetProperty(String propertyName, Value[] values) returns
* false if values do not satisfy the value constraints of the property def
*/
public void testValueConstraintNotSatisfiedMultiple() throws NotExecutableException, ParseException, RepositoryException {
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(session, PropertyType.BOOLEAN, true, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No multiple boolean property def with " + "testable value constraints has been found");
}
Value value = NodeTypeUtil.getValueAccordingToValueConstraints(session, propDef, false);
if (value == null) {
throw new NotExecutableException("No multiple boolean property def with " + "testable value constraints has been found");
}
NodeType nodeType = propDef.getDeclaringNodeType();
Value[] values = new Value[] { value };
assertFalse("canSetProperty(String propertyName, Value[] values) must " + "return false if values do not match the value constraints.", nodeType.canSetProperty(propDef.getName(), values));
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class QueryImpl method getColumns.
/**
* Returns the columns for this query.
*
* @return array of columns.
* @throws RepositoryException if an error occurs.
*/
protected ColumnImpl[] getColumns() throws RepositoryException {
SessionImpl session = sessionContext.getSessionImpl();
QueryObjectModelFactory qomFactory = session.getWorkspace().getQueryManager().getQOMFactory();
// get columns
Map<Name, ColumnImpl> columns = new LinkedHashMap<Name, ColumnImpl>();
for (Name name : root.getSelectProperties()) {
String pn = sessionContext.getJCRName(name);
ColumnImpl col = (ColumnImpl) qomFactory.column(sessionContext.getJCRName(DEFAULT_SELECTOR_NAME), pn, pn);
columns.put(name, col);
}
if (columns.size() == 0) {
// use node type constraint
LocationStepQueryNode[] steps = root.getLocationNode().getPathSteps();
final Name[] ntName = new Name[1];
steps[steps.length - 1].acceptOperands(new DefaultQueryNodeVisitor() {
public Object visit(AndQueryNode node, Object data) throws RepositoryException {
return node.acceptOperands(this, data);
}
public Object visit(NodeTypeQueryNode node, Object data) {
ntName[0] = node.getValue();
return data;
}
}, null);
if (ntName[0] == null) {
ntName[0] = NameConstants.NT_BASE;
}
NodeTypeImpl nt = session.getNodeTypeManager().getNodeType(ntName[0]);
PropertyDefinition[] propDefs = nt.getPropertyDefinitions();
for (PropertyDefinition pd : propDefs) {
QPropertyDefinition propDef = ((PropertyDefinitionImpl) pd).unwrap();
if (!propDef.definesResidual() && !propDef.isMultiple()) {
columns.put(propDef.getName(), columnForName(propDef.getName()));
}
}
}
// add jcr:path and jcr:score if not selected already
if (!columns.containsKey(NameConstants.JCR_PATH)) {
columns.put(NameConstants.JCR_PATH, columnForName(NameConstants.JCR_PATH));
}
if (!columns.containsKey(NameConstants.JCR_SCORE)) {
columns.put(NameConstants.JCR_SCORE, columnForName(NameConstants.JCR_SCORE));
}
return columns.values().toArray(new ColumnImpl[columns.size()]);
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class SetPropertyAssumeTypeTest method setUpNodeWithUndefinedProperty.
//--------------------------< internal >------------------------------------
private void setUpNodeWithUndefinedProperty(boolean multiple) throws NotExecutableException {
try {
// locate a property definition of type undefined
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.UNDEFINED, multiple, false, false, false);
if (propDef == null) {
throw new NotExecutableException("No testable property of type " + "UNDEFINED has been found.");
}
// create a node of type propDef.getDeclaringNodeType()
String nodeType = propDef.getDeclaringNodeType().getName();
testNode = testRootNode.addNode(nodeName1, nodeType);
testPropName = propDef.getName();
} catch (RepositoryException e) {
throw new NotExecutableException("Not able to set up test items.");
}
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class SetPropertyConstraintViolationExceptionTest method testBooleanProperty.
/**
* Tests if setProperty(String name, boolean value) and setProperty(String
* name, Value value) where value is a BooleanValue throw a
* ConstraintViolationException either immediately (by setProperty()), or on
* save, if the change would violate a node type constraint
*/
public void testBooleanProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.BOOLEAN, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No boolean property def with " + "testable value constraints has been found");
}
// find a Value that does not satisfy the ValueConstraints of propDef
Value valueNotSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
if (valueNotSatisfied == null) {
throw new NotExecutableException("No boolean property def with " + "testable value constraints has been found");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
Node node;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
testRootNode.getSession().save();
} catch (ConstraintViolationException e) {
// implementation specific constraints do not allow to set up test environment
throw new NotExecutableException("Not able to create required test items.");
}
// test of signature setProperty(String name, boolean value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied.getBoolean());
node.save();
fail("setProperty(String name, boolean value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
// test of signature setProperty(String name, Value value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied);
node.save();
fail("setProperty(String name, boolean value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
}
use of javax.jcr.nodetype.PropertyDefinition in project jackrabbit by apache.
the class SetPropertyConstraintViolationExceptionTest method testDoubleProperty.
/**
* Tests if setProperty(String name, double value) and setProperty(String
* name, Value value) where value is a DoubleValue throw a
* ConstraintViolationException either immediately (by setProperty()), or on
* save, if the change would violate a node type constraint
*/
public void testDoubleProperty() throws NotExecutableException, RepositoryException {
// locate a PropertyDefinition with ValueConstraints
PropertyDefinition propDef = NodeTypeUtil.locatePropertyDef(superuser, PropertyType.DOUBLE, false, false, true, false);
if (propDef == null) {
throw new NotExecutableException("No double property def with " + "testable value constraints has been found");
}
// find a Value that does not satisfy the ValueConstraints of propDef
Value valueNotSatisfied = NodeTypeUtil.getValueAccordingToValueConstraints(superuser, propDef, false);
if (valueNotSatisfied == null) {
throw new NotExecutableException("No double property def with " + "testable value constraints has been found");
}
// create a sub node of testRootNode of type propDef.getDeclaringNodeType()
Node node;
try {
String nodeType = propDef.getDeclaringNodeType().getName();
node = testRootNode.addNode(nodeName2, nodeType);
testRootNode.getSession().save();
} catch (ConstraintViolationException e) {
// implementation specific constraints do not allow to set up test environment
throw new NotExecutableException("Not able to create required test items.");
}
// test of signature setProperty(String name, double value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied.getDouble());
node.save();
fail("setProperty(String name, double value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
// test of signature setProperty(String name, Value value)
try {
node.setProperty(propDef.getName(), valueNotSatisfied);
node.save();
fail("setProperty(String name, Value value) must throw a " + "ConstraintViolationException if the change would violate a " + "node type constraint either immediately or on save");
} catch (ConstraintViolationException e) {
// success
}
}
Aggregations