KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > avalon > repository > util > RepositoryUtilsTest


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

17
18 package org.apache.avalon.repository.util ;
19
20 import java.net.URL JavaDoc;
21 import java.util.Properties JavaDoc;
22
23 import javax.naming.directory.Attributes JavaDoc;
24
25 import junit.framework.TestCase;
26
27 import org.apache.avalon.repository.Artifact;
28
29
30 /**
31  * @todo
32  * @author <a HREF="mailto:dev@avalon.apache.org">Avalon Development Team</a>
33  * @version $Revision: 1.3 $
34  */

35 public class RepositoryUtilsTest extends TestCase
36 {
37
38     public static void main(String JavaDoc[] args)
39     {
40         junit.textui.TestRunner.run(RepositoryUtilsTest.class);
41     }
42
43     /*
44      * @see TestCase#setUp()
45      */

46     protected void setUp() throws Exception JavaDoc
47     {
48         super.setUp();
49     }
50
51     /*
52      * @see TestCase#tearDown()
53      */

54     protected void tearDown() throws Exception JavaDoc
55     {
56         super.tearDown();
57     }
58
59     /**
60      * Constructor for RepositoryUtilsTest.
61      * @param arg0
62      */

63     public RepositoryUtilsTest(String JavaDoc arg0)
64     {
65         super(arg0);
66     }
67     
68     
69     final public void testGetAsAttributes() throws Exception JavaDoc
70     {
71         Properties JavaDoc l_props =
72             RepositoryUtils.getProperties(
73               new URL JavaDoc(
74                 "http://www.ibiblio.org/maven/avalon-repository/propertiess/repository.properties" ) ) ;
75         Attributes JavaDoc l_attrs = RepositoryUtils.getAsAttributes( l_props ) ;
76         assertEquals( ".repository", l_attrs.get( "cache.dir" ).get( 0 ) ) ;
77
78         assertEquals( "org.apache.avalon.repository.impl.DefaultFactory",
79                 l_attrs.get( "factory" ).get( 0 ) ) ;
80         assertEquals( "http://ibiblio.org/maven",
81                 l_attrs.get( "remote.repository.url" ).get( 0 ) ) ;
82
83         assertNotNull( l_attrs.get( "url" ).get( 0 ) ) ;
84         assertNotNull( l_attrs.get( "url" ).get( 1 ) ) ;
85         assertNotNull( l_attrs.get( "url" ).get( 2 ) ) ;
86     }
87
88     final public void testGetProperties() throws Exception JavaDoc
89     {
90         /* Test for these properties
91          * cache.dir=.repository
92          * factory=org.apache.avalon.repository.impl.DefaultFactory
93          * remote.repository.url.0=http://ibiblio.org/maven
94          */

95         Properties JavaDoc l_props =
96             RepositoryUtils.getProperties( new URL JavaDoc( "http://www.ibiblio.org/maven/avalon-repository/propertiess/repository.properties" ) ) ;
97         assertEquals( ".repository", l_props.getProperty( "cache.dir" ) ) ;
98         assertEquals( "org.apache.avalon.repository.impl.DefaultFactory",
99                 l_props.getProperty( "factory" ) ) ;
100         assertEquals( "http://ibiblio.org/maven",
101                 l_props.getProperty( "remote.repository.url.0" ) ) ;
102     }
103
104
105     final public void testIsEnumerated()
106     {
107         assertFalse( "false for empty string \"\"",
108                 RepositoryUtils.isEnumerated( "" ) ) ;
109
110         assertFalse( "false for \".\"",
111                 RepositoryUtils.isEnumerated( "." ) ) ;
112         
113         assertFalse( "false for \"nodot\"",
114                 RepositoryUtils.isEnumerated( "nodot" ) ) ;
115         
116         assertFalse( "false for \"before.\"",
117                 RepositoryUtils.isEnumerated( "before." ) ) ;
118         
119         assertFalse( "false for \".after\"",
120                 RepositoryUtils.isEnumerated( ".after" ) ) ;
121         
122         assertFalse( "false for \"123.\"",
123                 RepositoryUtils.isEnumerated( "123." ) ) ;
124         
125         assertFalse( "false for \".123\"",
126                 RepositoryUtils.isEnumerated( ".123" ) ) ;
127         
128         assertFalse( "false for \"123.asdf\"",
129                 RepositoryUtils.isEnumerated( "123.asdf" ) ) ;
130         
131         assertTrue( "true for \"asdf.123\"",
132                 RepositoryUtils.isEnumerated( "asdf.123" ) ) ;
133         
134         assertTrue( "true for \"asdf.1\"",
135                 RepositoryUtils.isEnumerated( "asdf.1" ) ) ;
136     }
137
138     
139     final public void testGetEnumeratedBase()
140     {
141         assertEquals( "",
142                 RepositoryUtils.getEnumeratedBase( "" ) ) ;
143
144         assertEquals( ".",
145                 RepositoryUtils.getEnumeratedBase( "." ) ) ;
146         
147         assertEquals( "nodot",
148                 RepositoryUtils.getEnumeratedBase( "nodot" ) ) ;
149         
150         assertEquals( "before.",
151                 RepositoryUtils.getEnumeratedBase( "before." ) ) ;
152         
153         assertEquals( ".after",
154                 RepositoryUtils.getEnumeratedBase( ".after" ) ) ;
155         
156         assertEquals( "123.",
157                 RepositoryUtils.getEnumeratedBase( "123." ) ) ;
158         
159         assertEquals( ".123",
160                 RepositoryUtils.getEnumeratedBase( ".123" ) ) ;
161         
162         assertEquals( "123.asdf",
163                 RepositoryUtils.getEnumeratedBase( "123.asdf" ) ) ;
164         
165         assertEquals( "asdf",
166                 RepositoryUtils.getEnumeratedBase( "asdf.123" ) ) ;
167         
168         assertEquals( "asdf",
169                 RepositoryUtils.getEnumeratedBase( "asdf.1" ) ) ;
170     }
171     
172     
173     public void testGetDelimited() throws Exception JavaDoc
174     {
175         String JavaDoc [] l_processed = null ;
176         assertNull( RepositoryUtils.getDelimited( ',', null) ) ;
177         assertNull( RepositoryUtils.getDelimited( ',', "") ) ;
178
179         l_processed = RepositoryUtils.getDelimited( ',',
180                 "asdf" ) ;
181         assertEquals( "asdf", l_processed[0] ) ;
182
183         l_processed = RepositoryUtils.getDelimited( ',',
184                 "asdf,1234" ) ;
185         assertEquals( "asdf", l_processed[0] ) ;
186         assertEquals( "1234", l_processed[1] ) ;
187         
188         l_processed = RepositoryUtils.getDelimited( ',',
189                 "asdf,1234,abcd" ) ;
190         assertEquals( "asdf", l_processed[0] ) ;
191         assertEquals( "1234", l_processed[1] ) ;
192         assertEquals( "abcd", l_processed[2] ) ;
193     }
194 }
195
Popular Tags