Search in sources :

Example 41 with NodeTypeTemplate

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

the class NodeTypeCreationTest method testNewNodeTypeTemplate.

public void testNewNodeTypeTemplate() throws Exception {
    String expandedName = "{" + NS_MIX_URI + "}" + "littlemixin";
    String jcrName = superuser.getNamespacePrefix(NS_MIX_URI) + ":littlemixin";
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
    ntt.setName(expandedName);
    assertEquals(jcrName, ntt.getName());
    ntt.setName(jcrName);
    assertEquals(jcrName, ntt.getName());
    ntt.setAbstract(false);
    assertFalse(ntt.isAbstract());
    try {
        ntt.setDeclaredSuperTypeNames(null);
        fail("null isn't a valid array of jcr name");
    } catch (ConstraintViolationException e) {
    // success
    }
    assertNotNull(ntt.getDeclaredSupertypeNames());
    assertEquals(0, ntt.getDeclaredSupertypeNames().length);
    ntt.setDeclaredSuperTypeNames(new String[] { mixReferenceable });
    assertNotNull(ntt.getDeclaredSupertypeNames());
    assertEquals(1, ntt.getDeclaredSupertypeNames().length);
    assertEquals(mixReferenceable, ntt.getDeclaredSupertypeNames()[0]);
    ntt.setMixin(true);
    assertTrue(ntt.isMixin());
    ntt.setOrderableChildNodes(true);
    assertTrue(ntt.hasOrderableChildNodes());
    ntt.setQueryable(false);
    assertFalse(ntt.isQueryable());
    ntt.setPrimaryItemName(null);
    assertNull(ntt.getPrimaryItemName());
    ntt.setPrimaryItemName(jcrPrimaryType);
    assertEquals(jcrPrimaryType, ntt.getPrimaryItemName());
    PropertyDefinitionTemplate pdTemplate = createBooleanPropTemplate();
    List pdefs = ntt.getPropertyDefinitionTemplates();
    pdefs.add(pdTemplate);
    assertNotNull(ntt.getDeclaredPropertyDefinitions());
    assertEquals(1, ntt.getDeclaredPropertyDefinitions().length);
    assertEquals(pdTemplate, ntt.getDeclaredPropertyDefinitions()[0]);
    pdefs = ntt.getPropertyDefinitionTemplates();
    assertEquals(1, pdefs.size());
    assertEquals(pdTemplate, pdefs.get(0));
    NodeDefinitionTemplate ndTemplate = ntm.createNodeDefinitionTemplate();
    List ndefs = ntt.getNodeDefinitionTemplates();
    ndefs.add(ndTemplate);
    assertNotNull(ntt.getDeclaredChildNodeDefinitions());
    assertEquals(1, ntt.getDeclaredChildNodeDefinitions().length);
    assertEquals(ndTemplate, ntt.getDeclaredChildNodeDefinitions()[0]);
    ndefs = ntt.getNodeDefinitionTemplates();
    assertEquals(1, ndefs.size());
    assertEquals(ndTemplate, ndefs.get(0));
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ConstraintViolationException(javax.jcr.nodetype.ConstraintViolationException) List(java.util.List)

Example 42 with NodeTypeTemplate

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

the class NodeTypeCreationTest method testRegisterNodeType.

public void testRegisterNodeType() throws Exception {
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
    ntt.setName("mix:foo");
    ntt.setAbstract(false);
    ntt.setMixin(true);
    ntt.setOrderableChildNodes(false);
    ntt.setQueryable(false);
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    pdt.setAutoCreated(false);
    pdt.setName("foo");
    pdt.setMultiple(false);
    pdt.setRequiredType(PropertyType.STRING);
    List pdefs = ntt.getPropertyDefinitionTemplates();
    pdefs.add(pdt);
    ntm.registerNodeType(ntt, true);
    try {
        ntm.registerNodeType(ntt, false);
        fail("NodeTypeExistsException expected.");
    } catch (NodeTypeExistsException e) {
    // success
    }
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) NodeTypeExistsException(javax.jcr.nodetype.NodeTypeExistsException) List(java.util.List)

Example 43 with NodeTypeTemplate

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

the class NodeTypeCreationTest method testNonEmptyNodeTypeTemplate.

public void testNonEmptyNodeTypeTemplate() throws Exception {
    NodeTypeDefinition ntd = ntm.getNodeType("nt:address");
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate(ntm.getNodeType("nt:address"));
    assertEquals(ntt.getName(), ntd.getName());
    assertEquals(ntt.isMixin(), ntd.isMixin());
    assertEquals(ntt.isAbstract(), ntd.isAbstract());
    assertEquals(ntt.hasOrderableChildNodes(), ntd.hasOrderableChildNodes());
    assertEquals(ntt.isQueryable(), ntd.isQueryable());
    assertEquals(ntt.getPrimaryItemName(), ntd.getPrimaryItemName());
    assertTrue(Arrays.equals(ntt.getDeclaredSupertypeNames(), ntd.getDeclaredSupertypeNames()));
    NodeDefinition[] nda = ntt.getDeclaredChildNodeDefinitions();
    NodeDefinition[] nda1 = ntd.getDeclaredChildNodeDefinitions();
    assertEquals(nda.length, nda1.length);
    for (int i = 0; i < nda.length; i++) {
        assertEquals(nda[i].getName(), nda1[i].getName());
        assertEquals(nda[i].allowsSameNameSiblings(), nda1[i].allowsSameNameSiblings());
        assertTrue(Arrays.equals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames()));
        assertEquals(nda[i].getDefaultPrimaryTypeName(), nda1[i].getDefaultPrimaryTypeName());
        assertEquals(nda[i].getRequiredPrimaryTypeNames(), nda1[i].getRequiredPrimaryTypeNames());
    }
    PropertyDefinition[] pda = ntt.getDeclaredPropertyDefinitions();
    PropertyDefinition[] pda1 = ntd.getDeclaredPropertyDefinitions();
    assertEquals(pda.length, pda1.length);
    for (int i = 0; i < pda.length; i++) {
        assertEquals(pda[i].getName(), pda1[i].getName());
        assertEquals(pda[i].getRequiredType(), pda1[i].getRequiredType());
        assertTrue(Arrays.equals(pda[i].getAvailableQueryOperators(), pda1[i].getAvailableQueryOperators()));
        assertTrue(Arrays.equals(pda[i].getValueConstraints(), pda1[i].getValueConstraints()));
        assertEquals(pda[i].isFullTextSearchable(), pda1[i].isFullTextSearchable());
        assertEquals(pda[i].isMultiple(), pda1[i].isMultiple());
        assertEquals(pda[i].isQueryOrderable(), pda1[i].isQueryOrderable());
    }
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) NodeDefinition(javax.jcr.nodetype.NodeDefinition) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition)

Example 44 with NodeTypeTemplate

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

the class NodeTypeCreationTest method testRegisterNodeTypes.

public void testRegisterNodeTypes() throws Exception {
    NodeTypeDefinition[] defs = new NodeTypeDefinition[5];
    for (int i = 0; i < defs.length; i++) {
        NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
        ntt.setName("mix:foo" + i);
        ntt.setAbstract(false);
        ntt.setMixin(true);
        ntt.setOrderableChildNodes(false);
        ntt.setQueryable(false);
        PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
        pdt.setAutoCreated(false);
        pdt.setName("foo" + i);
        pdt.setMultiple(false);
        pdt.setRequiredType(PropertyType.STRING);
        List pdefs = ntt.getPropertyDefinitionTemplates();
        pdefs.add(pdt);
        defs[i] = ntt;
    }
    ntm.registerNodeTypes(defs, true);
    try {
        ntm.registerNodeTypes(defs, false);
        fail("NodeTypeExistsException expected.");
    } catch (NodeTypeExistsException e) {
    // success
    }
}
Also used : NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) NodeTypeExistsException(javax.jcr.nodetype.NodeTypeExistsException) NodeTypeDefinition(javax.jcr.nodetype.NodeTypeDefinition) List(java.util.List)

Example 45 with NodeTypeTemplate

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

the class CugValidatorTest method testNodeTypeWithCugNames.

@Test
public void testNodeTypeWithCugNames() throws Exception {
    ReadWriteNodeTypeManager ntMgr = new ReadWriteNodeTypeManager() {

        @Nonnull
        @Override
        protected Root getWriteRoot() {
            return root;
        }

        @CheckForNull
        @Override
        protected Tree getTypes() {
            return root.getTree(NODE_TYPES_PATH);
        }
    };
    NodeTypeTemplate ntTemplate = ntMgr.createNodeTypeTemplate();
    ntTemplate.setName("testNT");
    NodeDefinitionTemplate ndt = ntMgr.createNodeDefinitionTemplate();
    ndt.setName(REP_CUG_POLICY);
    ndt.setRequiredPrimaryTypeNames(new String[] { JcrConstants.NT_BASE });
    ntTemplate.getNodeDefinitionTemplates().add(ndt);
    ntMgr.registerNodeType(ntTemplate, true);
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) ReadWriteNodeTypeManager(org.apache.jackrabbit.oak.plugins.nodetype.write.ReadWriteNodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) Test(org.junit.Test)

Aggregations

NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)46 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)29 Node (javax.jcr.Node)17 PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)13 Test (org.junit.Test)12 Session (javax.jcr.Session)11 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)11 List (java.util.List)7 Workspace (javax.jcr.Workspace)7 NamespaceRegistry (javax.jcr.NamespaceRegistry)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)5 NodeTypeDefinition (javax.jcr.nodetype.NodeTypeDefinition)5 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)5 InputStream (java.io.InputStream)4 ArrayList (java.util.ArrayList)4 AccessDeniedException (javax.jcr.AccessDeniedException)4 RepositoryException (javax.jcr.RepositoryException)4 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)4 BigDecimal (java.math.BigDecimal)3