1 5 6 package org.exoplatform.services.jcr.api.writing; 7 8 9 import javax.jcr.*; 10 import javax.jcr.nodetype.ConstraintViolationException; 11 import javax.jcr.nodetype.NodeDef; 12 import javax.jcr.nodetype.NodeType; 13 import javax.jcr.nodetype.NoSuchNodeTypeException; 14 import org.exoplatform.services.jcr.BaseTest; 15 16 21 public class AddNodeTest extends BaseTest{ 22 23 public void initRepository() throws RepositoryException { 24 Node root = ticket.getRootNode(); 25 Node file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file"); 26 Node contentNode = file.getNode("jcr:content"); 27 contentNode.setProperty("exo:content", new StringValue("this is the content")); 28 ticket.save(); 29 } 30 31 public void tearDown() throws RepositoryException { 32 ticket = repository.login(credentials, WORKSPACE); 33 Node root = ticket.getRootNode(); 34 root.remove("childNode"); 35 ticket.save(); 36 } 37 38 public void testAddNode() throws RepositoryException { 39 Node root = ticket.getRootNode(); 40 41 try { 42 root.addNode("notExisting/dummy"); 43 fail("exception should have been thrown"); 44 } catch (PathNotFoundException e) { 45 } 46 47 root.addNode("childNode"); 48 try { 49 ticket.save(); 50 fail("exception should have been thrown"); 51 } catch (ItemExistsException e) { 52 } 53 ticket = repository.login(credentials, WORKSPACE); 54 try { 55 root.addNode("childNode/childNode2/jcr:content/exo:content/arggg"); 56 fail("exception should have been thrown"); 57 } catch (ConstraintViolationException e) { 58 } 59 60 Node node = root.getNode("childNode/childNode2"); 61 try { 62 node.addNode("notJcrContentNode"); 63 fail("exception should have been thrown"); 64 } catch (ConstraintViolationException e) { 65 } 66 } 67 68 public void testAddNodeWithNodeType() throws RepositoryException { 69 Node root = ticket.getRootNode(); 70 Node node = root.getNode("childNode/childNode2"); 71 node.addNode("dummy", "nt:base"); 72 73 try { 74 ticket.save(); 75 fail("exception should have been thrown"); 76 } catch (ConstraintViolationException e) { 77 } 78 ticket = repository.login(credentials, WORKSPACE); 79 root = ticket.getRootNode(); 80 node = root.getNode("childNode"); 81 node.addNode("dummy", "nt:base"); 82 try { 83 ticket.save(); 84 fail("exception should have been thrown"); 85 } catch (ConstraintViolationException e) { 86 } 87 88 ticket = repository.login(credentials, WORKSPACE); 89 root = ticket.getRootNode(); 90 node = root.getNode("childNode"); 91 try { 92 node.addNode("dummy", "nt:dymyNT"); 93 fail("exception should have been thrown"); 94 } catch (NoSuchNodeTypeException e) { 95 } 96 97 } 98 99 public void testAddMultipleNodesWithUUID() throws RepositoryException { 100 101 Node root = ticket.getRootNode(); 102 root.addNode("mnode1", "nt:file"); 103 root.addNode("mnode2", "nt:file"); 104 root.addNode("mnode3", "nt:file"); 105 ticket.save(); 106 107 } 108 109 110 } 111 | Popular Tags |