You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@archiva.apache.org by jo...@apache.org on 2007/09/10 04:59:49 UTC
svn commit: r574120 [2/2] - in
/maven/archiva/trunk/archiva-base/archiva-repository-layer/src:
main/java/org/apache/maven/archiva/repository/content/
main/java/org/apache/maven/archiva/repository/layout/
main/java/org/apache/maven/archiva/repository/me...
Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java?rev=574120&r1=574119&r2=574120&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/layout/LegacyBidirectionalRepositoryLayoutTest.java Sun Sep 9 19:59:47 2007
@@ -19,15 +19,8 @@
* under the License.
*/
-import org.apache.commons.lang.StringUtils;
import org.apache.maven.archiva.model.ArchivaArtifact;
import org.apache.maven.archiva.model.ArtifactReference;
-import org.apache.maven.archiva.model.ProjectReference;
-import org.apache.maven.archiva.model.VersionedReference;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
/**
* LegacyBidirectionalRepositoryLayoutTest
@@ -38,474 +31,279 @@
public class LegacyBidirectionalRepositoryLayoutTest
extends AbstractBidirectionalRepositoryLayoutTestCase
{
- class LayoutExample
- {
- public String groupId;
-
- public String artifactId;
-
- public String version;
-
- public String classifier;
-
- public String type;
-
- public String pathArtifact;
-
- public String pathVersiond;
-
- public String pathProjectd;
-
- public LayoutExample( String groupId, String artifactId, String version, String classifier, String type )
- {
- super();
- this.groupId = groupId;
- this.artifactId = artifactId;
- this.version = version;
- this.classifier = classifier;
- this.type = type;
- }
-
- public void setDelimitedPath( String delimPath )
- {
- // Silly Test Writer! Don't end the path with a slash!
- if ( delimPath.endsWith( "/" ) )
- {
- delimPath = delimPath.substring( 0, delimPath.length() - 1 );
- }
-
- String parts[] = StringUtils.split( delimPath, '|' );
- switch ( parts.length )
- {
- case 3:
- this.pathArtifact = parts[0] + "/" + parts[1] + "/" + parts[2];
- case 2:
- this.pathVersiond = parts[0] + "/jars/maven-metadata.xml";
- case 1:
- this.pathProjectd = parts[0] + "/jars/maven-metadata.xml";
- break;
- default:
- fail( "Unknown number of path pieces, expected between 1 and 3, got <" + parts.length + "> on <"
- + delimPath + ">" );
- }
- }
-
- public boolean isSuitableForArtifactTest()
- {
- return ( this.type != null ) && ( this.classifier != null ) && ( this.version != null );
- }
-
- public boolean isSuitableForVersionedTest()
- {
- return ( this.type == null ) && ( this.classifier == null ) && ( this.version != null );
- }
-
- public boolean isSuitableForProjectTest()
- {
- return ( this.type == null ) && ( this.classifier == null ) && ( this.version == null );
- }
- }
+ private BidirectionalRepositoryLayout layout;
- class InvalidExample
+ public void testBadPathArtifactIdMissingA()
{
- public String path;
-
- public String reason;
-
- public boolean suitableForArtifactTests = true;
- public boolean suitableForVersionedTests = false;
- public boolean suitableForProjectTests = false;
-
- public InvalidExample( String path, String reason )
- {
- super();
- this.path = path;
- this.reason = reason;
- }
+ assertBadPath( "groupId/jars/-1.0.jar", "artifactId is missing" );
}
- private BidirectionalRepositoryLayout layout;
-
- protected void setUp()
- throws Exception
+ public void testBadPathArtifactIdMissingB()
{
- super.setUp();
-
- layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" );
+ assertBadPath( "groupId/jars/1.0.jar", "artifactId is missing" );
}
- public List /*<LayoutExample>*/getGoodExamples()
+ public void testBadPathMissingType()
{
- List ret = new ArrayList();
-
- LayoutExample example;
-
- // Artifact References
- example = new LayoutExample( "com.foo", "foo-tool", "1.0", null, "jar" );
- example.setDelimitedPath( "com.foo|jars|foo-tool-1.0.jar" );
- ret.add( example );
-
- example = new LayoutExample( "com.foo", "foo-client", "1.0", null, "ejb-client" );
- example.setDelimitedPath( "com.foo|ejbs|foo-client-1.0.jar" );
- ret.add( example );
-
- example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "sources", "jar" );
- example.setDelimitedPath( "com.foo.lib|source.jars|foo-lib-2.1-alpha-1-sources.jar" );
- ret.add( example );
-
- example = new LayoutExample( "com.foo.lib", "foo-lib", "2.1-alpha-1", "javadoc", "jar" );
- example.setDelimitedPath( "com.foo.lib|javadoc.jars|foo-lib-2.1-alpha-1-javadoc.jar" );
- ret.add( example );
-
- example = new LayoutExample( "com.foo", "foo-connector", "2.1-20060822.123456-35", null, "jar" );
- example.setDelimitedPath( "com.foo|jars|foo-connector-2.1-20060822.123456-35.jar" );
- ret.add( example );
-
- example = new LayoutExample( "org.apache.maven.test", "get-metadata-snapshot", "1.0-20050831.101112-1", null,
- "jar" );
- example.setDelimitedPath( "org.apache.maven.test|jars|get-metadata-snapshot-1.0-20050831.101112-1.jar" );
- ret.add( example );
-
- example = new LayoutExample( "commons-lang", "commons-lang", "2.1", null, "jar" );
- example.setDelimitedPath( "commons-lang|jars|commons-lang-2.1.jar" );
- ret.add( example );
-
- example = new LayoutExample( "org.apache.derby", "derby", "10.2.2.0", null, "jar" );
- example.setDelimitedPath( "org.apache.derby|jars|derby-10.2.2.0.jar" );
- ret.add( example );
-
- example = new LayoutExample( "org.apache.geronimo.specs", "geronimo-ejb_2.1_spec", "1.0.1", null, "jar" );
- example.setDelimitedPath( "org.apache.geronimo.specs|jars|geronimo-ejb_2.1_spec-1.0.1.jar" );
- ret.add( example );
-
- example = new LayoutExample( "org.apache.beehive", "beehive-ejb-control", "1.0.1", null, "jar" );
- example.setDelimitedPath( "org.apache.beehive|jars|beehive-ejb-control-1.0.1.jar" );
- ret.add( example );
-
- example = new LayoutExample( "commons-lang", "commons-lang", "2.3", "sources", "jar" );
- example.setDelimitedPath( "commons-lang|source.jars|commons-lang-2.3-sources.jar" );
- ret.add( example );
-
- example = new LayoutExample( "directory-clients", "ldap-clients", "0.9.1-SNAPSHOT", null, "pom" );
- example.setDelimitedPath( "directory-clients|poms|ldap-clients-0.9.1-SNAPSHOT.pom" );
- ret.add( example );
-
- // Versioned References (done here by setting classifier and type to null)
-
- // TODO: Not sure how to represent a VersionedReference as a legacy path.
-
- // Project References (done here by setting version, classifier, and type to null)
-
- // TODO: Not sure how to represent a ProjectReference as a legacy path.
-
- return ret;
- }
-
- public List /*<InvalidExample>*/getInvalidPaths()
- {
- List ret = new ArrayList();
-
- InvalidExample example;
-
- example = new InvalidExample( "invalid/invalid/1/invalid-1", "missing type" );
- example.suitableForArtifactTests = true;
- example.suitableForVersionedTests = false;
- example.suitableForProjectTests = true;
- ret.add( example );
-
- example = new InvalidExample( "org.apache.maven.test/jars/artifactId-1.0.jar.md5", "wrong package extension" );
- example.suitableForArtifactTests = true;
- example.suitableForVersionedTests = false;
- example.suitableForProjectTests = false;
- ret.add( example );
-
- example = new InvalidExample( "groupId/jars/-1.0.jar", "artifactId is missing" );
- example.suitableForArtifactTests = true;
- example.suitableForVersionedTests = false;
- example.suitableForProjectTests = true;
- ret.add( example );
-
- example = new InvalidExample( "groupId/jars/1.0.jar", "artifactId is missing" );
- example.suitableForArtifactTests = true;
- example.suitableForVersionedTests = false;
- example.suitableForProjectTests = true;
- ret.add( example );
-
- return ret;
+ assertBadPath( "invalid/invalid/1/invalid-1", "missing type" );
}
-
- public void testArtifactToPath()
+
+ public void testBadPathTooShort()
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForArtifactTest() )
- {
- ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version,
- example.classifier, example.type );
- assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, layout.toPath( artifact ) );
- }
- }
+ // NEW
+ assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
}
- public void testArtifactReferenceToPath()
+ public void testBadPathWrongPackageExtension()
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForArtifactTest() )
- {
- ArtifactReference reference = new ArtifactReference();
- reference.setGroupId( example.groupId );
- reference.setArtifactId( example.artifactId );
- reference.setVersion( example.version );
- reference.setClassifier( example.classifier );
- reference.setType( example.type );
-
- assertEquals( "ArtifactReference <" + reference + "> to path:", example.pathArtifact, layout
- .toPath( reference ) );
- }
- }
+ assertBadPath( "org.apache.maven.test/jars/artifactId-1.0.war", "wrong package extension" );
}
- public void testVersionedReferenceToPath()
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws LayoutException
+ */
+ /* TODO: MRM-432 - Needs to be fixed
+ public void testGoodButOddVersionSpecGanymedSsh2()
+ throws LayoutException
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForVersionedTest() || example.isSuitableForArtifactTest() )
- {
- VersionedReference reference = new VersionedReference();
- reference.setGroupId( example.groupId );
- reference.setArtifactId( example.artifactId );
- reference.setVersion( example.version );
-
- assertEquals( "VersionedReference <" + reference + "> to path:", example.pathVersiond, layout
- .toPath( reference ) );
- }
- }
+ String groupId = "ch.ethz.ganymed";
+ String artifactId = "ganymed-ssh2";
+ String version = "build210";
+ String classifier = null;
+ String type = "jar";
+ String path = "ch.ethz.ganymed/jars/ganymed-ssh2-build210.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+ */
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws LayoutException
+ */
+ public void testGoodButOddVersionSpecJavaxComm()
+ throws LayoutException
+ {
+ String groupId = "javax";
+ String artifactId = "comm";
+ String version = "3.0-u1";
+ String classifier = null;
+ String type = "jar";
+ String path = "javax/jars/comm-3.0-u1.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * [MRM-432] Oddball version spec.
+ * Example of an oddball / unusual version spec.
+ * @throws LayoutException
+ */
+ public void testGoodButOddVersionSpecJavaxPersistence()
+ throws LayoutException
+ {
+ String groupId = "javax.persistence";
+ String artifactId = "ejb";
+ String version = "3.0-public_review";
+ String classifier = null;
+ String type = "jar";
+ String path = "javax.persistence/jars/ejb-3.0-public_review.jar";
+
+ /*
+ * The version id of "public_review" can cause problems. is it part of
+ * the version spec? or the classifier?
+ */
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testProjectReferenceToPath()
+ public void testGoodCommonsLang()
+ throws LayoutException
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForProjectTest() || example.isSuitableForVersionedTest()
- || example.isSuitableForArtifactTest() )
- {
- ProjectReference reference = new ProjectReference();
- reference.setGroupId( example.groupId );
- reference.setArtifactId( example.artifactId );
-
- assertEquals( "ProjectReference <" + reference + "> to path:", example.pathProjectd, layout
- .toPath( reference ) );
- }
- }
+ String groupId = "commons-lang";
+ String artifactId = "commons-lang";
+ String version = "2.1";
+ String classifier = null;
+ String type = "jar";
+ String path = "commons-lang/jars/commons-lang-2.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testInvalidPathToArtifact()
+ public void testGoodDerby()
+ throws LayoutException
{
- Iterator it = getInvalidPaths().iterator();
- while ( it.hasNext() )
- {
- InvalidExample example = (InvalidExample) it.next();
-
- try
- {
- layout.toArtifact( example.path );
- fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of ["
- + example.reason + "]" );
- }
- catch ( LayoutException e )
- {
- /* expected path */
- }
- }
+ String groupId = "org.apache.derby";
+ String artifactId = "derby";
+ String version = "10.2.2.0";
+ String classifier = null;
+ String type = "jar";
+ String path = "org.apache.derby/jars/derby-10.2.2.0.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
+ }
+
+ /**
+ * Test the ejb-client type spec.
+ * Type specs are not a 1 to 1 map to the extension.
+ * This tests that effect.
+ * @throws LayoutException
+ */
+ public void testGoodFooEjbClient()
+ throws LayoutException
+ {
+ String groupId = "com.foo";
+ String artifactId = "foo-client";
+ String version = "1.0";
+ String classifier = null;
+ String type = "ejb"; // oddball type-spec (should result in jar extension)
+ String path = "com.foo/ejbs/foo-client-1.0.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testInvalidPathToArtifactReference()
+ /**
+ * Test the classifier.
+ * @throws LayoutException
+ */
+ public void testGoodFooLibJavadoc()
+ throws LayoutException
{
- Iterator it = getInvalidPaths().iterator();
- while ( it.hasNext() )
- {
- InvalidExample example = (InvalidExample) it.next();
-
- if( !example.suitableForArtifactTests )
- {
- continue;
- }
-
- try
- {
- layout.toArtifactReference( example.path );
- fail( "Should have thrown a LayoutException on the invalid path [" + example.path + "] because of ["
- + example.reason + "]" );
- }
- catch ( LayoutException e )
- {
- /* expected path */
- }
- }
+ String groupId = "com.foo.lib";
+ String artifactId = "foo-lib";
+ String version = "2.1-alpha-1";
+ String classifier = "javadoc";
+ String type = "javadoc.jar";
+ String path = "com.foo.lib/javadoc.jars/foo-lib-2.1-alpha-1-javadoc.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testInvalidPathToVersionedReference()
+ /**
+ * Test the classifier, and java-source type spec.
+ * @throws LayoutException
+ */
+ public void testGoodFooLibSources()
+ throws LayoutException
{
- Iterator it = getInvalidPaths().iterator();
- while ( it.hasNext() )
- {
- InvalidExample example = (InvalidExample) it.next();
+ String groupId = "com.foo.lib";
+ String artifactId = "foo-lib";
+ String version = "2.1-alpha-1";
+ String classifier = "sources";
+ String type = "java-source"; // oddball type-spec (should result in jar extension)
+ String path = "com.foo.lib/java-sources/foo-lib-2.1-alpha-1-sources.jar";
- if( !example.suitableForVersionedTests )
- {
- continue;
- }
-
- try
- {
- layout.toVersionedReference( example.path );
- fail( "Should have thrown a LayoutException on the invalid path [" + example.path
- + "] because of [" + example.reason + "]" );
- }
- catch ( LayoutException e )
- {
- /* expected path */
- }
- }
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testInvalidPathToProjectReference()
+ public void testGoodFooTool()
+ throws LayoutException
{
- Iterator it = getInvalidPaths().iterator();
- while ( it.hasNext() )
- {
- InvalidExample example = (InvalidExample) it.next();
+ String groupId = "com.foo";
+ String artifactId = "foo-tool";
+ String version = "1.0";
+ String classifier = null;
+ String type = "jar";
+ String path = "com.foo/jars/foo-tool-1.0.jar";
- if( !example.suitableForProjectTests )
- {
- continue;
- }
-
- try
- {
- layout.toProjectReference( example.path );
- fail( "Should have thrown a LayoutException on the invalid path [" + example.path
- + "] because of [" + example.reason + "]" );
- }
- catch ( LayoutException e )
- {
- /* expected path */
- }
- }
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testPathToArtifact()
+ public void testGoodGeronimoEjbSpec()
throws LayoutException
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForArtifactTest() )
- {
- ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact );
- assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier,
- example.type );
- }
- }
+ String groupId = "org.apache.geronimo.specs";
+ String artifactId = "geronimo-ejb_2.1_spec";
+ String version = "1.0.1";
+ String classifier = null;
+ String type = "jar";
+ String path = "org.apache.geronimo.specs/jars/geronimo-ejb_2.1_spec-1.0.1.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testPathToArtifactReference()
+ public void testGoodLdapClientsPom()
throws LayoutException
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForArtifactTest() )
- {
- ArtifactReference reference = layout.toArtifactReference( example.pathArtifact );
- assertArtifactReference( reference, example.groupId, example.artifactId, example.version,
- example.classifier, example.type );
- }
- }
+ String groupId = "directory-clients";
+ String artifactId = "ldap-clients";
+ String version = "0.9.1-SNAPSHOT";
+ String classifier = null;
+ String type = "pom";
+ String path = "directory-clients/poms/ldap-clients-0.9.1-SNAPSHOT.pom";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testPathToVersionedReference()
+ /**
+ * A timestamped versioned artifact, should reside in a SNAPSHOT baseversion directory.
+ * @throws LayoutException
+ */
+ public void testGoodSnapshotMavenTest()
throws LayoutException
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForVersionedTest() )
- {
- VersionedReference reference = layout.toVersionedReference( example.pathVersiond );
-
- String baseVersion = reference.getVersion();
-
- assertVersionedReference( reference, example.groupId, example.artifactId, baseVersion );
- }
- }
+ String groupId = "org.apache.archiva.test";
+ String artifactId = "redonkulous";
+ String version = "3.1-beta-1-20050831.101112-42";
+ String classifier = null;
+ String type = "jar";
+ String path = "org.apache.archiva.test/jars/redonkulous-3.1-beta-1-20050831.101112-42.jar";
+
+ assertLayout( path, groupId, artifactId, version, classifier, type );
}
- public void testPathToProjectReference()
+ /**
+ * Perform a roundtrip through the layout routines to determine success.
+ */
+ private void assertLayout( String path, String groupId, String artifactId, String version, String classifier,
+ String type )
throws LayoutException
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
- {
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForProjectTest() )
- {
- ProjectReference reference = layout.toProjectReference( example.pathProjectd );
+ ArchivaArtifact expectedArtifact = createArtifact( groupId, artifactId, version, classifier, type );
- assertProjectReference( reference, example.groupId, example.artifactId );
- }
- }
+ // --- Artifact Tests.
+ // Artifact to Path
+ assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( expectedArtifact ) );
+
+ // Path to Artifact.
+ ArchivaArtifact testArtifact = layout.toArtifact( path );
+ assertArtifact( testArtifact, groupId, artifactId, version, classifier, type );
+
+ // And back again, using test Artifact from previous step.
+ assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testArtifact ) );
+
+ // --- Artifact Reference Tests
+
+ // Path to Artifact Reference.
+ ArtifactReference testReference = layout.toArtifactReference( path );
+ assertArtifactReference( testReference, groupId, artifactId, version, classifier, type );
+
+ // And back again, using test Reference from previous step.
+ assertEquals( "Artifact <" + expectedArtifact + "> to path:", path, layout.toPath( testReference ) );
}
- public void testRoundtripArtifactToPathToArtifact()
- throws LayoutException
+ protected void assertBadPath( String path, String reason )
{
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
+ try
{
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForArtifactTest() )
- {
- ArchivaArtifact artifact = createArtifact( example.groupId, example.artifactId, example.version,
- example.classifier, example.type );
- String testPath = layout.toPath( artifact );
- assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath );
- ArchivaArtifact testArtifact = layout.toArtifact( testPath );
- assertArtifact( testArtifact, artifact.getGroupId(), artifact.getArtifactId(), artifact.getVersion(),
- artifact.getClassifier(), artifact.getType() );
- }
+ layout.toArtifact( path );
+ fail( "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
}
- }
-
- public void testRoundtripPathToArtifactToPath()
- throws LayoutException
- {
- Iterator it = getGoodExamples().iterator();
- while ( it.hasNext() )
+ catch ( LayoutException e )
{
- LayoutExample example = (LayoutExample) it.next();
- if ( example.isSuitableForArtifactTest() )
- {
- ArchivaArtifact artifact = layout.toArtifact( example.pathArtifact );
- assertArtifact( artifact, example.groupId, example.artifactId, example.version, example.classifier,
- example.type );
- String testPath = layout.toPath( artifact );
- assertEquals( "Artifact <" + artifact + "> to path:", example.pathArtifact, testPath );
- }
+ /* expected path */
}
}
+ protected void setUp()
+ throws Exception
+ {
+ super.setUp();
+
+ layout = (BidirectionalRepositoryLayout) lookup( BidirectionalRepositoryLayout.class.getName(), "legacy" );
+ }
}
Modified: maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java
URL: http://svn.apache.org/viewvc/maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java?rev=574120&r1=574119&r2=574120&view=diff
==============================================================================
--- maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java (original)
+++ maven/archiva/trunk/archiva-base/archiva-repository-layer/src/test/java/org/apache/maven/archiva/repository/metadata/MetadataToolsTest.java Sun Sep 9 19:59:47 2007
@@ -29,8 +29,6 @@
import org.apache.maven.archiva.policies.ChecksumPolicy;
import org.apache.maven.archiva.policies.ReleasesPolicy;
import org.apache.maven.archiva.policies.SnapshotsPolicy;
-import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayout;
-import org.apache.maven.archiva.repository.layout.BidirectionalRepositoryLayoutFactory;
import org.apache.maven.archiva.repository.layout.LayoutException;
import org.codehaus.plexus.PlexusTestCase;
import org.custommonkey.xmlunit.DetailedDiff;
@@ -56,8 +54,6 @@
public class MetadataToolsTest
extends PlexusTestCase
{
- private BidirectionalRepositoryLayoutFactory layoutFactory;
-
private MetadataTools tools;
protected MockConfiguration config;
@@ -228,6 +224,116 @@
assertUpdatedSnapshotVersionMetadata( "snap_shots_a", "1.0-alpha-11-SNAPSHOT", "20070316", "175232", "11" );
}
+ public void testToPathFromVersionReference()
+ {
+ VersionedReference reference = new VersionedReference();
+ reference.setGroupId( "com.foo" );
+ reference.setArtifactId( "foo-tool" );
+ reference.setVersion( "1.0" );
+
+ assertEquals( "com/foo/foo-tool/1.0/maven-metadata.xml", tools.toPath( reference ) );
+ }
+
+ public void testToPathFromProjectReference()
+ {
+ ProjectReference reference = new ProjectReference();
+ reference.setGroupId( "com.foo" );
+ reference.setArtifactId( "foo-tool" );
+
+ assertEquals( "com/foo/foo-tool/maven-metadata.xml", tools.toPath( reference ) );
+ }
+
+ public void testToProjectReferenceFooTools()
+ throws RepositoryMetadataException
+ {
+ assertProjectReference( "com.foo", "foo-tools", "com/foo/foo-tools/maven-metadata.xml" );
+ }
+
+ public void testToProjectReferenceAReallyLongPath()
+ throws RepositoryMetadataException
+ {
+ String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
+ String artifactId = "a";
+ String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/maven-metadata.xml";
+
+ assertProjectReference( groupId, artifactId, path );
+ }
+
+ public void testToProjectReferenceCommonsLang()
+ throws RepositoryMetadataException
+ {
+ String groupId = "commons-lang";
+ String artifactId = "commons-lang";
+ String path = "commons-lang/commons-lang/maven-metadata.xml";
+
+ assertProjectReference( groupId, artifactId, path );
+ }
+
+ private void assertProjectReference( String groupId, String artifactId, String path )
+ throws RepositoryMetadataException
+ {
+ ProjectReference reference = tools.toProjectReference( path );
+
+ assertNotNull( "Reference should not be null.", reference );
+ assertEquals( "ProjectReference.groupId", groupId, reference.getGroupId() );
+ assertEquals( "ProjectReference.artifactId", artifactId, reference.getArtifactId() );
+ }
+
+ public void testToVersionedReferenceFooTool()
+ throws RepositoryMetadataException
+ {
+ String groupId = "com.foo";
+ String artifactId = "foo-tool";
+ String version = "1.0";
+ String path = "com/foo/foo-tool/1.0/maven-metadata.xml";
+
+ assertVersionedReference( groupId, artifactId, version, path );
+ }
+
+ public void testToVersionedReferenceAReallyLongPath()
+ throws RepositoryMetadataException
+ {
+ String groupId = "net.i.have.a.really.long.path.just.for.the.hell.of.it";
+ String artifactId = "a";
+ String version = "1.1-alpha-1";
+ String path = "net/i/have/a/really/long/path/just/for/the/hell/of/it/a/1.1-alpha-1/maven-metadata.xml";
+
+ assertVersionedReference( groupId, artifactId, version, path );
+ }
+
+ public void testToVersionedReferenceCommonsLang()
+ throws RepositoryMetadataException
+ {
+ String groupId = "commons-lang";
+ String artifactId = "commons-lang";
+ String version = "2.1";
+ String path = "commons-lang/commons-lang/2.1/maven-metadata.xml";
+
+ assertVersionedReference( groupId, artifactId, version, path );
+ }
+
+ public void testToVersionedReferenceSnapshot()
+ throws RepositoryMetadataException
+ {
+ String groupId = "com.foo";
+ String artifactId = "foo-connector";
+ String version = "2.1-SNAPSHOT";
+ String path = "com/foo/foo-connector/2.1-SNAPSHOT/maven-metadata.xml";
+
+ assertVersionedReference( groupId, artifactId, version, path );
+ }
+
+ private void assertVersionedReference( String groupId, String artifactId, String version, String path )
+ throws RepositoryMetadataException
+ {
+ VersionedReference reference = tools.toVersionedReference( path );
+ assertNotNull( "Reference should not be null.", reference );
+
+ assertEquals( "VersionedReference.groupId", groupId, reference.getGroupId() );
+ assertEquals( "VersionedReference.artifactId", artifactId, reference.getArtifactId() );
+ assertEquals( "VersionedReference.version", version, reference.getVersion() );
+ }
+
private void assertAvailableVersions( String artifactId, String[] expectedVersions )
throws Exception
{
@@ -290,8 +396,7 @@
private void assertMetadata( String expectedMetadata, ArchivaRepository repository, ProjectReference reference )
throws LayoutException, IOException, SAXException, ParserConfigurationException
{
- BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repository.getLayoutType() );
- File metadataFile = new File( repository.getUrl().getPath(), layout.toPath( reference ) );
+ File metadataFile = new File( repository.getUrl().getPath(), tools.toPath( reference ) );
String actualMetadata = FileUtils.readFileToString( metadataFile, null );
XMLAssert.assertXMLEqual( expectedMetadata, actualMetadata );
@@ -300,17 +405,15 @@
private void assertMetadata( String expectedMetadata, ArchivaRepository repository, VersionedReference reference )
throws LayoutException, IOException, SAXException, ParserConfigurationException
{
- BidirectionalRepositoryLayout layout = layoutFactory.getLayout( repository.getLayoutType() );
- File metadataFile = new File( repository.getUrl().getPath(), layout.toPath( reference ) );
+ File metadataFile = new File( repository.getUrl().getPath(), tools.toPath( reference ) );
String actualMetadata = FileUtils.readFileToString( metadataFile, null );
DetailedDiff detailedDiff = new DetailedDiff( new Diff( expectedMetadata, actualMetadata ) );
if ( !detailedDiff.similar() )
{
+ // If it isn't similar, dump the difference.
assertEquals( expectedMetadata, actualMetadata );
}
- // assertTrue( "Metadata is similar: " + detailedDiff, detailedDiff.similar() );
- // XMLAssert.assertXMLEqual( expectedMetadata, actualMetadata );
}
private void assertMetadataPath( String expected, String actual )
@@ -485,7 +588,6 @@
{
super.setUp();
- layoutFactory = (BidirectionalRepositoryLayoutFactory) lookup( BidirectionalRepositoryLayoutFactory.class );
config = (MockConfiguration) lookup( ArchivaConfiguration.class.getName(), "mock" );
tools = (MetadataTools) lookup( MetadataTools.class );
}