1 package org.exoplatform.services.jcr.api.nodetypes; 2 3 4 import javax.jcr.Node; 5 import javax.jcr.nodetype.ConstraintViolationException; 6 import javax.jcr.nodetype.NoSuchNodeTypeException; 7 import javax.jcr.nodetype.NodeType; 8 9 import org.exoplatform.services.jcr.BaseTest; 10 11 17 18 public class AssigningNodeTypeTest extends BaseTest { 19 20 protected Node root; 21 22 public void testAddNode() throws Exception { 23 24 Node node = root.addNode("node1", "nt:default"); 25 NodeType type = node.getPrimaryNodeType(); 26 assertEquals("nt:default", type.getName()); 27 try { 28 root.addNode("node2", "not:found"); 29 fail("exception should have been thrown"); 30 } catch (NoSuchNodeTypeException e) { 31 } 32 33 34 } 35 36 public void testAddMixin() throws Exception { 37 38 Node node = root.addNode("node1", "nt:default"); 39 assertEquals(0, node.getMixinNodeTypes().length); 40 41 node.addMixin("mix:referenceable"); 42 assertEquals(1, node.getMixinNodeTypes().length); 43 44 NodeType type = node.getMixinNodeTypes()[0]; 45 assertEquals("mix:referenceable", type.getName()); 46 47 try { 48 node.addMixin("mix:notfound"); 49 node.save(true); 50 fail("exception should have been thrown"); 51 } catch (ConstraintViolationException e) { 52 } 53 54 55 node.addMixin("mix:referenceable"); 57 assertEquals(1, node.getMixinNodeTypes().length); 58 59 60 } 61 62 public void testIfAddMixinAddsAutocreatedItems() throws Exception { 63 64 Node node = root.addNode("node1", "nt:default"); 65 node.addMixin("mix:referenceable"); 66 assertTrue("UUID is null! ",node.hasProperty("jcr:uuid")); 67 68 } 69 70 71 } 72 | Popular Tags |