1 package org.apache.maven.archiva.repositories;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import org.apache.maven.archiva.artifact.ManagedArtifact;
23 import org.apache.maven.archiva.artifact.ManagedEjbArtifact;
24 import org.apache.maven.archiva.artifact.ManagedJavaArtifact;
25 import org.codehaus.plexus.PlexusTestCase;
28 * DefaultActiveManagedRepositoriesTest
30 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
33 public class DefaultActiveManagedRepositoriesTest
34 extends PlexusTestCase
36 private ActiveManagedRepositories managedRepos;
38 protected void setUp()
43 managedRepos = (ActiveManagedRepositories) lookup( ActiveManagedRepositories.ROLE );
47 * Test a simple java find artifact with extras (sources / javadoc).
49 public void testFindArtifactJavaWithExtras()
51 ManagedArtifact artifact = managedRepos.findArtifact( "geronimo", "daytrader-wsappclient", "1.1", "jar" );
52 assertNotNull( artifact );
54 if ( !( artifact instanceof ManagedJavaArtifact ) )
56 fail( "Expected artifact to be type <" + ManagedJavaArtifact.class.getName() + "> but was actually <" +
57 artifact.getClass().getName() + ">." );
60 ManagedJavaArtifact javaArtifact = (ManagedJavaArtifact) artifact;
62 assertEquals( "test", javaArtifact.getRepositoryId() );
64 String pathPrefix = "geronimo/daytrader-wsappclient/1.1";
65 String pathArtifactVersion = "daytrader-wsappclient-1.1";
67 assertEquals( pathPrefix + "/" + pathArtifactVersion + ".jar", javaArtifact.getPath() );
68 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-javadoc.jar", javaArtifact.getJavadocPath() );
69 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-sources.jar", javaArtifact.getSourcesPath() );
73 * Test a simple java find artifact with no extras.
75 public void testFindArtifactJavaSimple()
77 ManagedArtifact artifact = managedRepos.findArtifact( "geronimo", "daytrader-streamer", "1.1", "jar" );
78 assertNotNull( artifact );
80 if ( !( artifact instanceof ManagedJavaArtifact ) )
82 fail( "Expected artifact to be type <" + ManagedJavaArtifact.class.getName() + "> but was actually <" +
83 artifact.getClass().getName() + ">." );
86 ManagedJavaArtifact javaArtifact = (ManagedJavaArtifact) artifact;
88 assertEquals( "test", javaArtifact.getRepositoryId() );
90 String pathPrefix = "geronimo/daytrader-streamer/1.1";
91 String pathArtifactVersion = "daytrader-streamer-1.1";
93 assertEquals( pathPrefix + "/" + pathArtifactVersion + ".jar", javaArtifact.getPath() );
94 assertNull( "should have no javadoc jar.", javaArtifact.getJavadocPath() );
95 assertNull( "should have no sources jar.", javaArtifact.getSourcesPath() );
99 * Test a java find of a snapshot artifact that uses a timestamp format.
101 public void testFindArtifactJavaSnapshotTimestamp()
103 ManagedArtifact artifact = managedRepos.findArtifact( "org.apache.geronimo.daytrader", "daytrader-wsappclient",
104 "2.0-20070201.183230-5", "jar" );
105 assertNotNull( artifact );
107 if ( !( artifact instanceof ManagedJavaArtifact ) )
109 fail( "Expected artifact to be type <" + ManagedJavaArtifact.class.getName() + "> but was actually <" +
110 artifact.getClass().getName() + ">." );
113 ManagedJavaArtifact javaArtifact = (ManagedJavaArtifact) artifact;
115 assertEquals( "test", javaArtifact.getRepositoryId() );
117 String pathPrefix = "org/apache/geronimo/daytrader/daytrader-wsappclient/2.0-SNAPSHOT";
118 String pathArtifactVersion = "daytrader-wsappclient-2.0-20070201.183230-5";
120 assertEquals( pathPrefix + "/" + pathArtifactVersion + ".jar", javaArtifact.getPath() );
121 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-javadoc.jar", javaArtifact.getJavadocPath() );
122 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-sources.jar", javaArtifact.getSourcesPath() );
126 * Test a java find of a snapshot artifact.
128 public void testFindArtifactJavaSnapshot()
130 ManagedArtifact artifact = managedRepos.findArtifact( "org.apache.geronimo.daytrader", "daytrader-wsappclient",
131 "2.0-SNAPSHOT", "jar" );
132 assertNotNull( artifact );
134 if ( !( artifact instanceof ManagedJavaArtifact ) )
136 fail( "Expected artifact to be type <" + ManagedJavaArtifact.class.getName() + "> but was actually <" +
137 artifact.getClass().getName() + ">." );
140 ManagedJavaArtifact javaArtifact = (ManagedJavaArtifact) artifact;
142 assertEquals( "test", javaArtifact.getRepositoryId() );
144 String pathPrefix = "org/apache/geronimo/daytrader/daytrader-wsappclient/2.0-SNAPSHOT";
145 String pathArtifactVersion = "daytrader-wsappclient-2.0-SNAPSHOT";
147 assertEquals( pathPrefix + "/" + pathArtifactVersion + ".jar", javaArtifact.getPath() );
148 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-javadoc.jar", javaArtifact.getJavadocPath() );
149 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-sources.jar", javaArtifact.getSourcesPath() );
153 * Test a ejb find of a snapshot artifact that also has a client jar available.
155 public void testFindArtifactEjbSnapshot()
157 ManagedArtifact artifact =
158 managedRepos.findArtifact( "org.apache.geronimo.daytrader", "daytrader-ejb", "2.0-SNAPSHOT", "ejb" );
159 assertNotNull( artifact );
161 if ( !( artifact instanceof ManagedEjbArtifact ) )
163 fail( "Expected artifact to be type <" + ManagedEjbArtifact.class.getName() + "> but was actually <" +
164 artifact.getClass().getName() + ">." );
167 ManagedEjbArtifact ejbArtifact = (ManagedEjbArtifact) artifact;
169 assertEquals( "test", ejbArtifact.getRepositoryId() );
171 String pathPrefix = "org/apache/geronimo/daytrader/daytrader-ejb/2.0-SNAPSHOT";
172 String pathArtifactVersion = "daytrader-ejb-2.0-SNAPSHOT";
174 assertEquals( pathPrefix + "/" + pathArtifactVersion + ".jar", ejbArtifact.getPath() );
175 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-client.jar", ejbArtifact.getClientPath() );
176 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-javadoc.jar", ejbArtifact.getJavadocPath() );
177 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-sources.jar", ejbArtifact.getSourcesPath() );
181 * Test a simple java find artifact with no extras.
183 public void testFindArtifactWar()
185 ManagedArtifact artifact = managedRepos.findArtifact( "geronimo", "daytrader-web", "1.1", "war" );
186 assertNotNull( artifact );
188 if ( !( artifact instanceof ManagedJavaArtifact ) )
190 fail( "Expected artifact to be type <" + ManagedJavaArtifact.class.getName() + "> but was actually <" +
191 artifact.getClass().getName() + ">." );
194 ManagedJavaArtifact warArtifact = (ManagedJavaArtifact) artifact;
196 assertEquals( "test", warArtifact.getRepositoryId() );
198 String pathPrefix = "geronimo/daytrader-web/1.1";
199 String pathArtifactVersion = "daytrader-web-1.1";
201 assertEquals( pathPrefix + "/" + pathArtifactVersion + ".war", warArtifact.getPath() );
202 assertEquals( pathPrefix + "/" + pathArtifactVersion + "-javadoc.jar", warArtifact.getJavadocPath() );
203 assertNull( "should have no sources jar.", warArtifact.getSourcesPath() );