use of javax.jcr.nodetype.NodeDefinition in project sling by apache.
the class MockNodeTypeGenerator method getCompleteChildNodeDef.
public NodeDefinition getCompleteChildNodeDef(String name) {
NodeDefinition childNodeDef1 = mock(NodeDefinition.class);
NodeType requiredPrimaryType1 = getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME1);
NodeType requiredPrimaryType2 = getSimpleNodeTypeWithName(NODETYPE_REQ_PRIMARY_TYPE_NAME2);
NodeType[] reqPrimaryTypes = { requiredPrimaryType1, requiredPrimaryType2 };
when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes);
when(childNodeDef1.getName()).thenReturn(name);
when(childNodeDef1.getOnParentVersion()).thenReturn(OnParentVersionAction.VERSION);
when(childNodeDef1.getDefaultPrimaryType()).thenReturn(requiredPrimaryType1);
when(childNodeDef1.allowsSameNameSiblings()).thenReturn(Boolean.TRUE);
when(childNodeDef1.isAutoCreated()).thenReturn(Boolean.TRUE);
when(childNodeDef1.isMandatory()).thenReturn(Boolean.TRUE);
when(childNodeDef1.isProtected()).thenReturn(Boolean.TRUE);
return childNodeDef1;
}
use of javax.jcr.nodetype.NodeDefinition in project sling by apache.
the class ChildNodeDefGenerationTest method testCompleteChildNodeDefinitions.
@Test
public void testCompleteChildNodeDefinitions() throws ServletException, IOException, JSONException {
NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs");
NodeDefinition childNodeDef1 = getCompleteChildNodeDef("childNodeDef1");
NodeDefinition childNodeDef2 = getCompleteChildNodeDef("childNodeDef2");
NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 };
when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs);
when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
assertEqualsWithServletResult("testCompleteChildNodeDefinitions");
}
use of javax.jcr.nodetype.NodeDefinition in project sling by apache.
the class ChildNodeDefGenerationTest method testSimpleChildNodeDefinitions.
@Test
public void testSimpleChildNodeDefinitions() throws ServletException, IOException, JSONException {
NodeType ntWithChildNodeDefs = getSimpleNodeTypeWithName("ntWithChildNodeDefs");
NodeDefinition childNodeDef1 = getSimpleChildNodeDef("childNodeDef1");
NodeDefinition childNodeDef2 = getSimpleChildNodeDef("childNodeDef2");
NodeDefinition[] childNodeDefs = { childNodeDef1, childNodeDef2 };
when(ntWithChildNodeDefs.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
when(nodeTypeIterator.nextNodeType()).thenReturn(ntWithChildNodeDefs);
when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
assertEqualsWithServletResult("testSimpleChildNodeDefinitions");
}
use of javax.jcr.nodetype.NodeDefinition in project sling by apache.
the class DefaultNodeTypeTest method testIfDefaultsAreOmittedWithServlet.
/**
* Simulates a node type in the repository that has only default values and checks if they are omitted in the generated
* JSON file.
*/
@Test
public void testIfDefaultsAreOmittedWithServlet() throws JSONException, ServletException, IOException, ValueFormatException, IllegalStateException, RepositoryException {
NodeType nt1 = getSimpleNodeTypeWithName("testNodeType");
when(nodeTypeIterator.nextNodeType()).thenReturn(nt1);
when(nodeTypeIterator.hasNext()).thenReturn(Boolean.TRUE, Boolean.FALSE);
NodeType ntBase = mock(NodeType.class);
when(ntBase.getName()).thenReturn("nt:base");
NodeDefinition childNodeDef1 = mock(NodeDefinition.class);
NodeType[] reqPrimaryTypes = { ntBase };
when(childNodeDef1.getRequiredPrimaryTypes()).thenReturn(reqPrimaryTypes);
when(childNodeDef1.getName()).thenReturn("childNodeDef");
NodeDefinition[] childNodeDefs = { childNodeDef1 };
when(nt1.getDeclaredChildNodeDefinitions()).thenReturn(childNodeDefs);
String propertyName = "stringPropertyDef";
PropertyDefinition propertyDef = mock(PropertyDefinition.class);
when(propertyDef.getRequiredType()).thenReturn(PropertyType.STRING);
when(propertyDef.getName()).thenReturn(propertyName);
when(nt1.getDeclaredPropertyDefinitions()).thenReturn(new PropertyDefinition[] { propertyDef });
assertEqualsWithServletResult("testIfDefaultsAreOmittedWithServlet");
}
use of javax.jcr.nodetype.NodeDefinition in project sling by apache.
the class NewNodeDialog method validateInput.
protected void validateInput() {
final String firstInput = getText().getText();
final String secondInput = comboSelection;
try {
if (secondInput == null || secondInput.length() == 0) {
setErrorMessage("");
} else if (ntManager == null) {
setErrorMessage(null);
} else if (ntManager.isAllowedPrimaryChildNodeType(parentNodeType, secondInput)) {
// also check on the name, not only the type
if (allChildNodeDefs == null) {
setErrorMessage("No child node definitions found for " + parentNodeType);
} else {
boolean success = false;
for (int i = 0; i < allChildNodeDefs.length; i++) {
NodeDefinition aChildNodeDef = allChildNodeDefs[i];
if (aChildNodeDef.getName() != null && aChildNodeDef.getName().length() > 0) {
if (firstInput.equals(aChildNodeDef.getName())) {
setErrorMessage(null);
return;
}
} else {
// mark success if there's a child node definition without a name
// (ie then it can be any name)
success = true;
}
}
if (success) {
setErrorMessage(null);
return;
}
StringBuffer details = new StringBuffer();
for (NodeDefinition aChildNodeDef : allChildNodeDefs) {
if (details.length() != 0) {
details.append(", ");
}
details.append("(name=" + aChildNodeDef.getName() + ", required primary type(s)=");
String[] requiredPrimaryTypeNames = aChildNodeDef.getRequiredPrimaryTypeNames();
if (requiredPrimaryTypeNames == null) {
details.append("null");
} else {
for (int j = 0; j < requiredPrimaryTypeNames.length; j++) {
String rptn = requiredPrimaryTypeNames[j];
if (j > 0) {
details.append(",");
}
details.append(rptn);
}
}
details.append(")");
}
setErrorMessage("No matching child node definition found for " + parentNodeType + ". Expected one of: " + details);
}
} else {
setErrorMessage("Error: Invalid child node type of " + parentNodeType);
}
} catch (RepositoryException e) {
setErrorMessage("RepositoryException: " + e);
}
}
Aggregations