Search in sources :

Example 11 with PropertyDefinitionTemplate

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

the class CompatibilityIssuesTest method testBinaryCoercion.

@Test
public void testBinaryCoercion() throws RepositoryException, IOException {
    Session session = getAdminSession();
    // node type with default child-node type of to nt:base
    String ntName = "binaryCoercionTest";
    NodeTypeManager ntm = session.getWorkspace().getNodeTypeManager();
    NodeTypeTemplate ntt = ntm.createNodeTypeTemplate();
    ntt.setName(ntName);
    PropertyDefinitionTemplate propertyWithType = ntm.createPropertyDefinitionTemplate();
    propertyWithType.setName("javaObject");
    propertyWithType.setRequiredType(PropertyType.STRING);
    PropertyDefinitionTemplate unnamed = ntm.createPropertyDefinitionTemplate();
    unnamed.setName("*");
    unnamed.setRequiredType(PropertyType.UNDEFINED);
    List<PropertyDefinition> properties = ntt.getPropertyDefinitionTemplates();
    properties.add(propertyWithType);
    properties.add(unnamed);
    ntm.registerNodeType(ntt, false);
    Node node = session.getRootNode().addNode("testNodeForBinary", ntName);
    ByteArrayOutputStream bos = serializeObject("testValue");
    node.setProperty("javaObject", session.getValueFactory().createBinary(new ByteArrayInputStream(bos.toByteArray())));
    Assert.assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(bos.toByteArray()), node.getProperty("javaObject").getStream()));
}
Also used : NodeTypeManager(javax.jcr.nodetype.NodeTypeManager) NodeTypeTemplate(javax.jcr.nodetype.NodeTypeTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate) ByteArrayInputStream(java.io.ByteArrayInputStream) Node(javax.jcr.Node) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PropertyDefinition(javax.jcr.nodetype.PropertyDefinition) Session(javax.jcr.Session) Test(org.junit.Test)

Example 12 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate 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 13 with PropertyDefinitionTemplate

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

the class NodeTypeCreationTest method testResidualNames.

public void testResidualNames() throws Exception {
    String residualName = "*";
    NodeDefinitionTemplate ndt = ntm.createNodeDefinitionTemplate();
    ndt.setName(residualName);
    assertEquals(residualName, ndt.getName());
    PropertyDefinitionTemplate pdt = ntm.createPropertyDefinitionTemplate();
    pdt.setName(residualName);
    assertEquals(residualName, pdt.getName());
}
Also used : NodeDefinitionTemplate(javax.jcr.nodetype.NodeDefinitionTemplate) PropertyDefinitionTemplate(javax.jcr.nodetype.PropertyDefinitionTemplate)

Example 14 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate 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 15 with PropertyDefinitionTemplate

use of javax.jcr.nodetype.PropertyDefinitionTemplate 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)

Aggregations

PropertyDefinitionTemplate (javax.jcr.nodetype.PropertyDefinitionTemplate)21 NodeTypeTemplate (javax.jcr.nodetype.NodeTypeTemplate)13 NodeTypeManager (javax.jcr.nodetype.NodeTypeManager)8 List (java.util.List)5 Node (javax.jcr.Node)5 Session (javax.jcr.Session)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)4 NodeDefinitionTemplate (javax.jcr.nodetype.NodeDefinitionTemplate)4 Test (org.junit.Test)4 Value (javax.jcr.Value)3 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 NodeTypeExistsException (javax.jcr.nodetype.NodeTypeExistsException)2 JackrabbitWorkspace (org.apache.jackrabbit.api.JackrabbitWorkspace)2 AbstractRepositoryTest (org.apache.jackrabbit.oak.jcr.AbstractRepositoryTest)2