1 5 6 package org.exoplatform.services.jcr.api.namespaces; 7 8 9 import javax.jcr.NamespaceRegistry; 10 import javax.jcr.NamespaceException; 11 12 import org.apache.commons.lang.ArrayUtils; 13 import org.exoplatform.services.jcr.BaseTest; 14 15 20 public class PrefixesTicketTest extends BaseTest { 21 22 private NamespaceRegistry namespaceRegistry; 23 24 public void init() throws Exception { 25 workspace = ticket.getWorkspace(); 26 namespaceRegistry = workspace.getNamespaceRegistry(); 27 } 28 29 public void testSetPrefix() throws NamespaceException { 30 try { 31 ticket.setPrefix("exo2", "http://dummy.com"); 32 fail("exception should have been thrown"); 33 } catch (NamespaceException e) { 34 } 35 36 ticket.setPrefix("exo2", "http://www.exoplatform.com/jcr/exo/1.0"); 37 assertEquals("http://www.exoplatform.com/jcr/exo/1.0", ticket.getURI("exo2")); 38 assertNull(ticket.getURI("exo")); 39 40 assertEquals("http://www.jcp.org/jcr/1.0", ticket.getURI("jcr")); 41 } 42 43 public void testGetPrefixes() throws NamespaceException { 44 String [] protectedNamespaces = {"jcr", "nt", "mix","pt", "sv", "exo2"}; 45 ticket.setPrefix("exo2", "http://www.exoplatform.com/jcr/exo/1.0"); 46 String [] prefixes = ticket.getPrefixes(); 47 assertEquals(prefixes.length, protectedNamespaces.length); 48 for (int i = 0; i < prefixes.length; i++) { 49 String prefix = prefixes[i]; 50 assertTrue(ArrayUtils.contains(protectedNamespaces, prefix)); 51 } 52 } 53 54 public void testGetURI() throws NamespaceException { 55 ticket.setPrefix("exo2", "http://www.exoplatform.com/jcr/exo/1.0"); 56 assertEquals("http://www.exoplatform.com/jcr/exo/1.0", ticket.getURI("exo2")); 57 assertNull(ticket.getURI("exo")); 58 assertEquals("http://www.jcp.org/jcr/1.0", ticket.getURI("jcr")); 59 } 60 61 62 } 63 | Popular Tags |