1 17 18 package org.apache.avalon.repository.util ; 19 20 import java.net.URL ; 21 import java.util.Properties ; 22 23 import javax.naming.directory.Attributes ; 24 25 import junit.framework.TestCase; 26 27 import org.apache.avalon.repository.Artifact; 28 29 30 35 public class RepositoryUtilsTest extends TestCase 36 { 37 38 public static void main(String [] args) 39 { 40 junit.textui.TestRunner.run(RepositoryUtilsTest.class); 41 } 42 43 46 protected void setUp() throws Exception 47 { 48 super.setUp(); 49 } 50 51 54 protected void tearDown() throws Exception 55 { 56 super.tearDown(); 57 } 58 59 63 public RepositoryUtilsTest(String arg0) 64 { 65 super(arg0); 66 } 67 68 69 final public void testGetAsAttributes() throws Exception 70 { 71 Properties l_props = 72 RepositoryUtils.getProperties( 73 new URL ( 74 "http://www.ibiblio.org/maven/avalon-repository/propertiess/repository.properties" ) ) ; 75 Attributes 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 89 { 90 95 Properties l_props = 96 RepositoryUtils.getProperties( new URL ( "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 174 { 175 String [] 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 |