1 18 package org.apache.activemq.util; 19 20 import java.net.URI ; 21 import java.net.URISyntaxException ; 22 import java.util.Map ; 23 24 import org.apache.activemq.util.URISupport; 25 import org.apache.activemq.util.URISupport.CompositeData; 26 27 import junit.framework.TestCase; 28 29 33 public class URISupportTest extends TestCase { 34 35 public void testEmptyCompositePath() throws Exception { 36 CompositeData data = URISupport.parseComposite(new URI ("broker:()/localhost?persistent=false")); 37 assertEquals(0, data.getComponents().length); 38 } 39 40 public void testCompositePath() throws Exception { 41 CompositeData data = URISupport.parseComposite(new URI ("test:(path)/path")); 42 assertEquals("path", data.getPath()); 43 data = URISupport.parseComposite(new URI ("test:path")); 44 assertNull(data.getPath()); 45 } 46 47 public void testSimpleComposite() throws Exception { 48 CompositeData data = URISupport.parseComposite(new URI ("test:part1")); 49 assertEquals(1, data.getComponents().length); 50 } 51 52 public void testComposite() throws Exception { 53 CompositeData data = URISupport.parseComposite(new URI ("test:(part1://host,part2://(sub1://part,sube2:part))")); 54 assertEquals(2, data.getComponents().length); 55 } 56 57 public void testParsingURI() throws Exception { 58 URI source = new URI ("tcp://localhost:61626/foo/bar?cheese=Edam&x=123"); 59 60 Map map = URISupport.parseParamters(source); 61 62 assertEquals("Size: " + map, 2, map.size()); 63 assertMapKey(map, "cheese", "Edam"); 64 assertMapKey(map, "x", "123"); 65 66 URI result = URISupport.removeQuery(source); 67 68 assertEquals("result", new URI ("tcp://localhost:61626/foo/bar"), result); 69 } 70 71 protected void assertMapKey(Map map, String key, Object expected) { 72 assertEquals("Map key: " + key, map.get(key), expected); 73 } 74 75 public void testParsingCompositeURI() throws URISyntaxException { 76 URISupport.parseComposite(new URI ("broker://(tcp://localhost:61616)?name=foo")); 77 } 78 79 public void testCheckParenthesis() throws Exception { 80 String str = "fred:(((ddd))"; 81 assertFalse(URISupport.checkParenthesis(str)); 82 str += ")"; 83 assertTrue(URISupport.checkParenthesis(str)); 84 } 85 86 } 87 | Popular Tags |