akarasulu 2003/11/06 21:30:46
Modified: repository/spi/src/java/org/apache/avalon/repository
ArtifactDatabaseImpl.java RepositoryUtils.java
Added: repository/spi/src/test/org/apache/avalon/repository
RepositoryUtilsTest.java
ArtifactDatabaseImplTest.java
Log:
Added test cases and some code
Revision Changes Path
1.1
avalon-sandbox/repository/spi/src/test/org/apache/avalon/repository/RepositoryUtilsTest.java
Index: RepositoryUtilsTest.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.repository;
import java.net.URL;
import java.util.Properties;
import javax.naming.directory.Attributes;
import junit.framework.TestCase;
/**
* @todo
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: akarasulu $
* @version $Revision: 1.1 $
*/
public class RepositoryUtilsTest extends TestCase
{
public static void main(String[] args)
{
junit.textui.TestRunner.run(RepositoryUtilsTest.class);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception
{
super.tearDown();
}
/**
* Constructor for RepositoryUtilsTest.
* @param arg0
*/
public RepositoryUtilsTest(String arg0)
{
super(arg0);
}
final public void testGetAsAttributes() throws Exception
{
Properties l_props =
RepositoryUtils.getProperties( new URL(
"http://www.ibiblio.org/maven/avalon-repository/propertiess/repository.properties" ) )
;
Attributes l_attrs = RepositoryUtils.getAsAttributes( l_props ) ;
assertEquals( ".repository", l_attrs.get( "cache.dir" ).get( 0 ) ) ;
assertEquals( "org.apache.avalon.repository.impl.DefaultFactory",
l_attrs.get( "factory" ).get( 0 ) ) ;
assertEquals( "http://ibiblio.org/maven",
l_attrs.get( "remote.repository.url" ).get( 0 ) ) ;
assertNotNull( l_attrs.get( "url" ).get( 0 ) ) ;
assertNotNull( l_attrs.get( "url" ).get( 1 ) ) ;
assertNotNull( l_attrs.get( "url" ).get( 2 ) ) ;
}
final public void testGetProperties() throws Exception
{
/* Test for these properties
* cache.dir=.repository
* factory=org.apache.avalon.repository.impl.DefaultFactory
* remote.repository.url.0=http://ibiblio.org/maven
*/
Properties l_props =
RepositoryUtils.getProperties( new URL(
"http://www.ibiblio.org/maven/avalon-repository/propertiess/repository.properties" ) )
;
assertEquals( ".repository", l_props.getProperty( "cache.dir" ) ) ;
assertEquals( "org.apache.avalon.repository.impl.DefaultFactory",
l_props.getProperty( "factory" ) ) ;
assertEquals( "http://ibiblio.org/maven",
l_props.getProperty( "remote.repository.url.0" ) ) ;
}
final public void testIsEnumerated()
{
assertFalse( "false for empty string \"\"",
RepositoryUtils.isEnumerated( "" ) ) ;
assertFalse( "false for \".\"",
RepositoryUtils.isEnumerated( "." ) ) ;
assertFalse( "false for \"nodot\"",
RepositoryUtils.isEnumerated( "nodot" ) ) ;
assertFalse( "false for \"before.\"",
RepositoryUtils.isEnumerated( "before." ) ) ;
assertFalse( "false for \".after\"",
RepositoryUtils.isEnumerated( ".after" ) ) ;
assertFalse( "false for \"123.\"",
RepositoryUtils.isEnumerated( "123." ) ) ;
assertFalse( "false for \".123\"",
RepositoryUtils.isEnumerated( ".123" ) ) ;
assertFalse( "false for \"123.asdf\"",
RepositoryUtils.isEnumerated( "123.asdf" ) ) ;
assertTrue( "true for \"asdf.123\"",
RepositoryUtils.isEnumerated( "asdf.123" ) ) ;
assertTrue( "true for \"asdf.1\"",
RepositoryUtils.isEnumerated( "asdf.1" ) ) ;
}
final public void testGetEnumeratedBase()
{
assertEquals( "",
RepositoryUtils.getEnumeratedBase( "" ) ) ;
assertEquals( ".",
RepositoryUtils.getEnumeratedBase( "." ) ) ;
assertEquals( "nodot",
RepositoryUtils.getEnumeratedBase( "nodot" ) ) ;
assertEquals( "before.",
RepositoryUtils.getEnumeratedBase( "before." ) ) ;
assertEquals( ".after",
RepositoryUtils.getEnumeratedBase( ".after" ) ) ;
assertEquals( "123.",
RepositoryUtils.getEnumeratedBase( "123." ) ) ;
assertEquals( ".123",
RepositoryUtils.getEnumeratedBase( ".123" ) ) ;
assertEquals( "123.asdf",
RepositoryUtils.getEnumeratedBase( "123.asdf" ) ) ;
assertEquals( "asdf",
RepositoryUtils.getEnumeratedBase( "asdf.123" ) ) ;
assertEquals( "asdf",
RepositoryUtils.getEnumeratedBase( "asdf.1" ) ) ;
}
}
1.1
avalon-sandbox/repository/spi/src/test/org/apache/avalon/repository/ArtifactDatabaseImplTest.java
Index: ArtifactDatabaseImplTest.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) 1999-2002 The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Apache Avalon", "Avalon Framework" and
"Apache Software Foundation" must not be used to endorse or promote
products derived from this software without prior written
permission. For written permission, please contact [EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.avalon.repository ;
import junit.framework.TestCase ;
/**
* Tests the ArtifactDatabaseImpl class.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Alex Karasulu</a>
* @author $Author: akarasulu $
* @version $Revision: 1.1 $
*/
public class ArtifactDatabaseImplTest extends TestCase
{
ArtifactDatabase m_adb = null ;
public static void main(String[] args)
{
junit.textui.TestRunner.run(ArtifactDatabaseImplTest.class);
}
/*
* @see TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
m_adb = new ArtifactDatabaseImpl( "http://ibiblio.org/maven" ) ;
}
/*
* @see TestCase#tearDown()
*/
protected void tearDown() throws Exception
{
super.tearDown();
}
/**
* Constructor for ArtifactDatabaseImplTest.
* @param arg0
*/
public ArtifactDatabaseImplTest(String arg0)
{
super(arg0);
}
public void testArtifactDatabaseImpl()
{
}
public void testGetArtifactAttributes() throws Exception
{
/* Disable until can create a dummy test project on dpml.net
Attributes l_attrs = m_adb.getArtifactAttributes( null ) ;
assertEquals( ".repository", l_attrs.get( "cache.dir" ).get( 0 ) ) ;
assertEquals( "org.apache.avalon.repository.impl.DefaultFactory",
l_attrs.get( "factory" ).get( 0 ) ) ;
assertEquals( "http://ibiblio.org/maven",
l_attrs.get( "remote.repository.url" ).get( 0 ) ) ;
assertNotNull( l_attrs.get( "url" ).get( 0 ) ) ;
assertNotNull( l_attrs.get( "url" ).get( 1 ) ) ;
assertNotNull( l_attrs.get( "url" ).get( 2 ) ) ;
*/
}
public void test() throws Exception
{
}
}
1.3 +3 -2
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/ArtifactDatabaseImpl.java
Index: ArtifactDatabaseImpl.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/ArtifactDatabaseImpl.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- ArtifactDatabaseImpl.java 7 Nov 2003 01:54:16 -0000 1.2
+++ ArtifactDatabaseImpl.java 7 Nov 2003 05:30:46 -0000 1.3
@@ -107,7 +107,8 @@
try
{
l_url = new URL( a_descriptor.getUrl( m_remoteRepoBase ) ) ;
- l_attrs = RepositoryUtils.getAsAttributes(
RepositoryUtils.getProperties( l_url ) ) ;
+ l_attrs = RepositoryUtils.getAsAttributes( RepositoryUtils
+ .getProperties( l_url ) ) ;
}
catch ( MalformedURLException e )
{
1.2 +33 -5
avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/RepositoryUtils.java
Index: RepositoryUtils.java
===================================================================
RCS file:
/home/cvs/avalon-sandbox/repository/spi/src/java/org/apache/avalon/repository/RepositoryUtils.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- RepositoryUtils.java 7 Nov 2003 01:54:16 -0000 1.1
+++ RepositoryUtils.java 7 Nov 2003 05:30:46 -0000 1.2
@@ -59,7 +59,9 @@
import java.util.Properties ;
import java.util.Enumeration ;
+import javax.naming.directory.Attribute;
import javax.naming.directory.Attributes ;
+import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes ;
@@ -95,10 +97,20 @@
if ( isEnumerated( l_key ) )
{
String l_keyBase = getEnumeratedBase( l_key ) ;
- l_attrs.put( l_keyBase, a_props.getProperty( l_key ) ) ;
+ Attribute l_attr = l_attrs.get( l_keyBase ) ;
+
+ if ( null == l_attr )
+ {
+ l_attr = new BasicAttribute( l_keyBase, false ) ;
+ }
+
+ l_attr.add( a_props.getProperty( l_key ) ) ;
+ l_attrs.put( l_attr ) ;
+ }
+ else
+ {
+ l_attrs.put( l_key, a_props.getProperty( l_key ) ) ;
}
-
- l_attrs.put( l_key, a_props.getProperty( l_key ) ) ;
}
return l_attrs ;
@@ -149,6 +161,12 @@
l_lastComponent = a_key.substring( l_lastDot + 1 ) ;
+ // names like .123 are not really considered enumerated without a base
+ if ( a_key.equals( a_key.substring( l_lastDot ) ) )
+ {
+ return false ;
+ }
+
try
{
Integer.parseInt( l_lastComponent ) ;
@@ -171,6 +189,16 @@
*/
public static String getEnumeratedBase( String a_key )
{
+ if ( null == a_key )
+ {
+ return null ;
+ }
+
+ if ( ! isEnumerated( a_key ) )
+ {
+ return a_key ;
+ }
+
int l_lastDot = a_key.lastIndexOf( '.' ) ;
String l_base = null ;
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]