KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > util > URISupportTest


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.util;
19
20 import java.net.URI JavaDoc;
21 import java.net.URISyntaxException JavaDoc;
22 import java.util.Map JavaDoc;
23
24 import org.apache.activemq.util.URISupport;
25 import org.apache.activemq.util.URISupport.CompositeData;
26
27 import junit.framework.TestCase;
28
29 /**
30  *
31  * @version $Revision: 1.1 $
32  */

33 public class URISupportTest extends TestCase {
34     
35     public void testEmptyCompositePath() throws Exception JavaDoc {
36         CompositeData data = URISupport.parseComposite(new URI JavaDoc("broker:()/localhost?persistent=false"));
37         assertEquals(0, data.getComponents().length);
38     }
39             
40     public void testCompositePath() throws Exception JavaDoc {
41         CompositeData data = URISupport.parseComposite(new URI JavaDoc("test:(path)/path"));
42         assertEquals("path", data.getPath());
43         data = URISupport.parseComposite(new URI JavaDoc("test:path"));
44         assertNull(data.getPath());
45     }
46
47     public void testSimpleComposite() throws Exception JavaDoc {
48         CompositeData data = URISupport.parseComposite(new URI JavaDoc("test:part1"));
49         assertEquals(1, data.getComponents().length);
50     }
51
52     public void testComposite() throws Exception JavaDoc {
53         CompositeData data = URISupport.parseComposite(new URI JavaDoc("test:(part1://host,part2://(sub1://part,sube2:part))"));
54         assertEquals(2, data.getComponents().length);
55     }
56
57     public void testParsingURI() throws Exception JavaDoc {
58         URI JavaDoc source = new URI JavaDoc("tcp://localhost:61626/foo/bar?cheese=Edam&x=123");
59         
60         Map JavaDoc 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 JavaDoc result = URISupport.removeQuery(source);
67         
68         assertEquals("result", new URI JavaDoc("tcp://localhost:61626/foo/bar"), result);
69     }
70     
71     protected void assertMapKey(Map JavaDoc map, String JavaDoc key, Object JavaDoc expected) {
72         assertEquals("Map key: " + key, map.get(key), expected);
73     }
74     
75     public void testParsingCompositeURI() throws URISyntaxException JavaDoc {
76         URISupport.parseComposite(new URI JavaDoc("broker://(tcp://localhost:61616)?name=foo"));
77     }
78     
79     public void testCheckParenthesis() throws Exception JavaDoc {
80         String JavaDoc str = "fred:(((ddd))";
81         assertFalse(URISupport.checkParenthesis(str));
82         str += ")";
83         assertTrue(URISupport.checkParenthesis(str));
84     }
85     
86 }
87
Popular Tags