1 5 6 package org.exoplatform.services.jcr.api.reading; 7 8 9 import javax.jcr.*; 10 import org.exoplatform.services.jcr.BaseTest; 11 12 17 public class ItemTest extends BaseTest{ 18 19 public void initRepository() throws RepositoryException { 20 Node root = ticket.getRootNode(); 21 Node file; 22 file = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file"); 24 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 Node root = ticket.getRootNode(); 33 root.remove("childNode"); 34 ticket.save(); 35 } 36 37 public void testGetAncestor() throws RepositoryException { 38 Node root = ticket.getRootNode(); 39 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 40 41 Item item = property.getAncestor(0); 42 assertEquals(root.getPath(), item.getPath()); 43 44 item = property.getAncestor(1); 45 assertEquals("/childNode", item.getPath()); 46 assertEquals("childNode", item.getName()); 47 assertTrue(item instanceof Node); 48 49 item = property.getAncestor(2); 50 assertEquals("/childNode/childNode2", item.getPath()); 51 assertEquals("childNode2", item.getName()); 52 assertTrue(item instanceof Node); 53 54 item = property.getAncestor(4); 55 assertEquals(property, item); 56 assertTrue(item instanceof Property); 57 58 try { 59 item = property.getAncestor(5); 60 fail("exception should have been thrown"); 61 } catch (ItemNotFoundException e) { 62 } 63 } 64 65 public void testGetName() throws RepositoryException { 66 Node root = ticket.getRootNode(); 67 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 68 69 Item item = property.getAncestor(0); 70 assertEquals("", item.getName()); 71 72 item = property.getAncestor(1); 73 assertEquals("childNode", item.getName()); 74 } 75 76 public void testGetParent() throws RepositoryException { 77 Node root = ticket.getRootNode(); 78 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 79 Item item = property.getAncestor(4); 80 assertEquals("jcr:content", item.getParent().getName()); 81 } 82 83 public void testGetPath() throws RepositoryException { 84 Node root = ticket.getRootNode(); 85 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 86 Item item = property.getAncestor(3); 87 assertEquals("/childNode/childNode2/jcr:content", item.getPath()); 88 } 89 90 public void testGetParents() throws RepositoryException { 91 Node root = ticket.getRootNode(); 92 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 93 NodeIterator nodeIterator = property.getParents(); 94 System.out.println("ITRATOR >>>>>>>"+nodeIterator.getSize()); 95 Node node = nodeIterator.nextNode(); 96 assertEquals("jcr:content", node.getName()); 97 } 98 99 public void testGetPaths() throws RepositoryException { 100 Node root = ticket.getRootNode(); 101 System.out.println("UUID >>>>>>>"+root.getNode("childNode/childNode2/jcr:content").getUUID()); 102 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 103 Item item = property.getAncestor(3); 104 StringIterator stringIterator = item.getPaths(); 105 assertTrue("Size==0", stringIterator.getSize()>0); 106 assertTrue("Size==0", item.getPaths().getSize()>0); 107 assertEquals("/childNode/childNode2/jcr:content", stringIterator.nextString()); 109 } 110 111 public void testGetDepths() throws RepositoryException { 112 Node root = ticket.getRootNode(); 113 assertEquals(0, root.getDepth()); 114 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 115 assertEquals(4, property.getDepth()); 116 } 117 118 public void testGetTicket() throws RepositoryException { 119 Node root = ticket.getRootNode(); 120 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 121 assertEquals(ticket, property.getTicket()); 122 } 123 124 public void testIsNode() throws RepositoryException { 125 Node root = ticket.getRootNode(); 126 assertTrue(root.isNode()); 127 Property property = root.getProperty("childNode/childNode2/jcr:content/exo:content"); 128 assertFalse(property.isNode()); 129 } 130 131 } 132 | Popular Tags |