1 5 6 package org.exoplatform.services.jcr.api.accessing; 7 8 9 import javax.jcr.*; 10 import org.exoplatform.services.jcr.BaseTest; 11 12 17 public class TicketTest extends BaseTest{ 18 19 public void testGetRepository(){ 20 assertEquals(ticket.getRepository(), repository); 21 } 22 23 public void testGetCredential(){ 24 assertEquals(ticket.getCredentials(), credentials); 25 } 26 27 public void testGetWorkspace(){ 28 assertEquals(ticket.getWorkspace().getTicket(), ticket); 29 } 30 31 public void testImpersonate() throws LoginException { 32 assertNotSame(ticket, ticket.impersonate(new SimpleCredentials("user", new char[0]))); 33 } 34 35 public void testGetRootNode() throws RepositoryException { 36 assertEquals("/", ticket.getRootNode().getPath()); 37 } 38 39 public void testGetNodeByAbsolutePath() throws RepositoryException { 40 Node root = ticket.getRootNode(); 41 root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file"); 42 assertNotNull(ticket.getNodeByAbsPath("/childNode/childNode2")); 43 } 44 45 public void testGetNodeByUUID() throws RepositoryException { 46 47 Node root = ticket.getRootNode(); 48 try { 49 Node child = root.addNode("childNode", "nt:folder").addNode("childNode2", "nt:file"); 50 51 Node contentNode = child.getNode("jcr:content"); 52 contentNode.setProperty("exo:content", new StringValue("this is the content")); 53 ticket.save(); 55 child = child.getNode("jcr:content"); 56 assertNotNull(child.getUUID()); 57 Node n = ticket.getNodeByUUID(child.getUUID()); 58 assertNotNull(n); 59 assertEquals(child.getPath(), n.getPath()); 60 } finally { 61 root.remove("childNode"); 62 ticket.save(); 63 } 64 65 } 66 67 public void testGetPrefixes(){ 68 String [] prefixes = ticket.getPrefixes(); 69 for (int i = 0; i < prefixes.length; i++) { 70 String prefixe = prefixes[i]; 71 if(!isInNamespaceRegistery(prefixe)) 72 fail("Prefix " + prefixe + " should be in registry"); 73 } 74 } 75 76 public void testSetPrefix() throws NamespaceException { 77 ticket.setPrefix("exo", "http://www.jcp.org/jcr/1.0"); 78 assertTrue(isInNamespaceRegistery("exo")); 79 80 try { 81 ticket.setPrefix("unknown", "http://www.exoplatform.com/jcr/unknown/1.0"); 82 fail("exception should have been thrown"); 83 } catch (NamespaceException e) { 84 } 85 } 86 87 public void testGetURI() throws NamespaceException { 88 assertNotNull(ticket.getURI("jcr")); 89 90 try { 91 ticket.getURI("ano"); 92 fail("exception should have been thrown"); 93 } catch (NamespaceException e) { 94 } 95 } 96 97 private boolean isInNamespaceRegistery(String namespace){ 98 NamespaceRegistry registry = ticket.getWorkspace().getNamespaceRegistry(); 99 String [] namespaces = registry.getPrefixes(); 100 for (int i = 0; i < namespaces.length; i++) { 101 String s = namespaces[i]; 102 if(s.equals(namespace)) 103 return true; 104 } 105 return false; 106 } 107 108 } 109 | Popular Tags |