]> source.dussan.org Git - archiva.git/commitdiff
update archetype for repository metadata
authorBrett Porter <brett@apache.org>
Wed, 30 Jul 2014 05:33:46 +0000 (15:33 +1000)
committerBrett Porter <brett@apache.org>
Wed, 30 Jul 2014 06:33:41 +0000 (16:33 +1000)
use mocks instead of full implementations for testing, cut down dependencies

archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/pom.xml
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/META-INF/maven/archetype-metadata.xml
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/main/java/SimpleArtifactConsumer.java
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/java/SimpleArtifactConsumerTest.java
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/log4j2-test.xml
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resources/archetype-resources/src/test/resources/spring-context.xml
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/main/resourcesstatic/archetype-resources/pom.xml
archiva-modules/archiva-base/archiva-consumers/archiva-consumer-archetype/src/test/resources/projects/compile/archetype.properties
pom.xml

index 630fb1b67bdd7865f0cdd2ecf3434d6e8d51e137..8456350af63cf9bbc81d47d1835930073121615c 100644 (file)
     </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
-      <artifactId>archiva-repository-admin-default</artifactId>
+      <artifactId>archiva-repository-admin-api</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
-      <artifactId>metadata-store-jcr</artifactId>
+      <artifactId>archiva-model</artifactId>
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>jcl-over-slf4j</artifactId>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-repository-layer</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-repository-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>maven2-repository</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.kubek2k</groupId>
+      <artifactId>springockito</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>
index 10c82acb7d95bb34af0ca5bd050cf14169bc2329..fdcb1f87403e2ed160a2d2733ed928339ca897ad 100644 (file)
     <requiredProperty key="springVersion">
       <defaultValue>${spring.version}</defaultValue>
     </requiredProperty>
-    <requiredProperty key="jackrabbitVersion">
-      <defaultValue>${jackrabbit.version}</defaultValue>
-    </requiredProperty>
     <requiredProperty key="guavaVersion">
       <defaultValue>${guava.version}</defaultValue>
     </requiredProperty>
-    <requiredProperty key="maven3xVersion">
-      <defaultValue>${maven3x.version}</defaultValue>
-    </requiredProperty>
     <requiredProperty key="redbackRegistryVersion">
       <defaultValue>${redback.registry.version}</defaultValue>
     </requiredProperty>
-    <requiredProperty key="redbackQuartzVersion">
-      <defaultValue>${redback.quartz.version}</defaultValue>
-    </requiredProperty>
-    <requiredProperty key="commonsDbcpVersion">
-      <defaultValue>${commons-dbcp.version}</defaultValue>
-    </requiredProperty>
-    <requiredProperty key="commonsPoolVersion">
-      <defaultValue>${commons-pool.version}</defaultValue>
-    </requiredProperty>
-    <requiredProperty key="luceneVersion">
-      <defaultValue>${lucene.version}</defaultValue>
+    <requiredProperty key="springockitoVersion">
+      <defaultValue>${springockito.version}</defaultValue>
     </requiredProperty>
-    <requiredProperty key="derbyVersion">
-      <defaultValue>${derbyVersion}</defaultValue>
+    <requiredProperty key="mockitoVersion">
+      <defaultValue>${mockito.version}</defaultValue>
     </requiredProperty>
   </requiredProperties>
 </archetype-descriptor>
index d5cd396e0a18513b07c943ada36a3950c4044483..940a4e0c90bbe16839c742c94daebf80c3d4c8bb 100644 (file)
@@ -28,13 +28,23 @@ import org.apache.archiva.configuration.FileTypes;
 import org.apache.archiva.consumers.AbstractMonitoredConsumer;
 import org.apache.archiva.consumers.ConsumerException;
 import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.archiva.metadata.repository.MetadataResolutionException;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.model.ArtifactReference;
 import org.apache.archiva.redback.components.registry.Registry;
 import org.apache.archiva.redback.components.registry.RegistryListener;
 
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RepositoryContentFactory;
+import org.apache.archiva.repository.RepositoryException;
+import org.apache.archiva.repository.layout.LayoutException;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import javax.annotation.PostConstruct;
 import javax.inject.Inject;
+import javax.inject.Named;
+
 import org.springframework.context.annotation.Scope;
 import org.springframework.stereotype.Service;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
@@ -81,18 +91,19 @@ public class SimpleArtifactConsumer
     /** current repository being scanned */
     private ManagedRepository repository;
 
-    public void beginScan( ManagedRepository repository )
-        throws ConsumerException
-    {
-        this.repository = repository;
-        log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
-    }
+    @Inject
+    @Named( value = "repositoryContentFactory#default" )
+    private RepositoryContentFactory repositoryContentFactory;
+
+    @Inject
+    private RepositorySessionFactory repositorySessionFactory;
+
+    private RepositorySession repositorySession;
 
     public void beginScan( ManagedRepository repository, Date whenGathered )
         throws ConsumerException
     {
-        this.repository = repository;
-        log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
+        beginScan( repository, whenGathered, true );
     }
 
     public void beginScan( ManagedRepository repository, Date whenGathered, boolean executeOnEntireRepo )
@@ -100,28 +111,45 @@ public class SimpleArtifactConsumer
     {
         this.repository = repository;
         log.info( "Beginning scan of repository [" + this.repository.getId() + "]" );
+
+        repositorySession = repositorySessionFactory.createSession();
     }
 
     public void processFile( String path )
         throws ConsumerException
     {
-        log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
+        processFile( path, true );
     }
 
     public void processFile( String path, boolean executeOnEntireRepo )
         throws ConsumerException
     {
         log.info( "Processing entry [" + path + "] from repository [" + this.repository.getId() + "]" );
+
+        try
+        {
+            ManagedRepositoryContent repositoryContent = repositoryContentFactory.getManagedRepositoryContent( repository.getId() );
+            ArtifactReference artifact = repositoryContent.toArtifactReference( path );
+
+            repositorySession.getRepository().getArtifacts( repository.getId(), artifact.getGroupId(),
+                                                            artifact.getArtifactId(), artifact.getVersion() );
+        }
+        catch ( RepositoryException | LayoutException | MetadataResolutionException e )
+        {
+            throw new ConsumerException( e.getLocalizedMessage(), e );
+        }
     }
 
     public void completeScan()
     {
-        log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
+        completeScan( true );
     }
 
     public void completeScan( boolean executeOnEntireRepo )
     {
         log.info( "Finished scan of repository [" + this.repository.getId() + "]" );
+
+        repositorySession.close();
     }
 
 
@@ -153,7 +181,7 @@ public class SimpleArtifactConsumer
     private void initIncludes()
     {
         includes.clear();
-        includes.addAll( filetypes.getFileTypePatterns( FileTypes.INDEXABLE_CONTENT ) );
+        includes.addAll( filetypes.getFileTypePatterns( FileTypes.ARTIFACTS ) );
     }
 
     @PostConstruct
index 413fed7edd6ae98e427406bb915f8cad48e2c254..095873c6262bc59ae0d5772f3c0334776666911e 100644 (file)
@@ -19,53 +19,65 @@ package $package;
  * under the License.
  */
 
-import java.io.File;
-
+import org.apache.archiva.admin.model.RepositoryAdminException;
 import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.archiva.consumers.KnownRepositoryContentConsumer;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import javax.inject.Inject;
+import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
 import org.junit.Before;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
-import junit.framework.TestCase;
+
+import javax.inject.Inject;
+import java.io.File;
+import java.util.Date;
+
+import static org.mockito.Mockito.*;
 
 /**
  * <code>SimpleArtifactConsumerTest</code>
  */
-@RunWith( SpringJUnit4ClassRunner.class )
-@ContextConfiguration( locations = {"classpath*:/META-INF/spring-context.xml","classpath:/spring-context.xml"} )
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context.xml" })
 public class SimpleArtifactConsumerTest
-    extends TestCase
 {
     @Inject
     private SimpleArtifactConsumer consumer;
 
-    private File repoDir;
+    @Inject
+    private ManagedRepositoryAdmin managedRepositoryAdmin;
+
+    @Inject
+    private RepositorySessionFactory repositorySessionFactory;
 
     private ManagedRepository testRepository;
 
     private Logger log = LoggerFactory.getLogger( SimpleArtifactConsumer.class );
 
+    private MetadataRepository metadataRepository;
+
     @Before
     public void setUp()
         throws Exception
     {
-        super.setUp();
-        String consumerRole = KnownRepositoryContentConsumer.class.getName();
-
         setUpMockRepository();
 
-    }
-
+        RepositorySession repositorySession = mock( RepositorySession.class );
+        when( repositorySessionFactory.createSession() ).thenReturn( repositorySession );
 
+        metadataRepository = mock( MetadataRepository.class );
+        when( repositorySession.getRepository() ).thenReturn( metadataRepository );
+    }
 
     private void setUpMockRepository()
+        throws RepositoryAdminException
     {
-        repoDir = new java.io.File( "target/test-consumer-repo" );
+        File repoDir = new File( "target/test-consumer-repo" );
         repoDir.mkdirs();
         repoDir.deleteOnExit();
 
@@ -73,6 +85,8 @@ public class SimpleArtifactConsumerTest
         testRepository.setName( "Test-Consumer-Repository" );
         testRepository.setId( "test-consumer-repository" );
         testRepository.setLocation( repoDir.getAbsolutePath() );
+
+        when( managedRepositoryAdmin.getManagedRepository( testRepository.getId() ) ).thenReturn( testRepository );
     }
 
     @Test
@@ -81,17 +95,21 @@ public class SimpleArtifactConsumerTest
     {
         log.info( "Beginning scan of repository [test-consumer-repository]" );
 
-        consumer.beginScan( testRepository );
-
+        consumer.beginScan( testRepository, new Date() );
     }
 
     @Test
     public void testProcessFile()
         throws Exception
     {
-        consumer.beginScan( testRepository );
+        consumer.beginScan( testRepository, new Date() );
         consumer.processFile( "org/simple/test/testartifact/testartifact/1.0/testartifact-1.0.pom" );
         consumer.processFile( "org/simple/test/testartifact/testartifact/1.1/testartifact-1.1.pom" );
+
+        verify( metadataRepository ).getArtifacts( testRepository.getId(), "org.simple.test.testartifact",
+                                                   "testartifact", "1.0" );
+        verify( metadataRepository ).getArtifacts( testRepository.getId(), "org.simple.test.testartifact",
+                                                   "testartifact", "1.1" );
     }
 
 }
index 814779b2d1852e56bdcce2660fbbf4b86ea127a3..1b662d7f27a1b0dea14ad58932271afb27aaf372 100644 (file)
@@ -19,7 +19,7 @@
   -->
 
 
-<configuration status="debug">
+<configuration>
   <appenders>
     <Console name="console" target="SYSTEM_OUT">
       <PatternLayout pattern="%d [%t] %-5p %c %x - %m%n"/>
@@ -27,7 +27,7 @@
   </appenders>
   <loggers>
 
-    <logger name="org.springframework" level="info"/>
+    <logger name="org.springframework" level="error"/>
 
     <root level="info">
       <appender-ref ref="console"/>
index 3b08f16d93d5598a8f75aedfe2c5868b09197e94..f17d5b4d664af081bb32f2367197c3936f0655a7 100644 (file)
   -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:mockito="http://www.mockito.org/spring/mockito"
        xsi:schemaLocation="http://www.springframework.org/schema/beans
-           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd"
+           http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+           http://www.mockito.org/spring/mockito http://www.mockito.org/spring/mockito.xsd"
        default-lazy-init="true">
-  <bean id="jcr-config" class="org.apache.archiva.metadata.repository.jcr.ArchivaJcrRepositoryConfig" factory-method="create">
-    <constructor-arg value="${appserver.base}/conf/foo.xml"/>
-    <constructor-arg value="${appserver.base}/data/jcr"/>
-  </bean>
 
-  <bean id="jcr-repository" class="org.apache.jackrabbit.core.RepositoryImpl" destroy-method="shutdown" lazy-init="true">
-    <constructor-arg ref="jcr-config"/>
-  </bean>
+  <mockito:mock id="mockManagedRepositoryAdmin" class="org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin" />
+  <mockito:mock id="mockRemoteRepositoryAdmin" class="org.apache.archiva.admin.model.remote.RemoteRepositoryAdmin" />
+  <mockito:mock id="mockRepositorySessionFactory" class="org.apache.archiva.metadata.repository.RepositorySessionFactory" />
 
-  <bean name="scheduler" class="org.apache.archiva.redback.components.scheduler.DefaultScheduler">
-    <property name="properties">
-      <props>
-        <prop key="org.quartz.scheduler.instanceName">scheduler1</prop>
-        <prop key="org.quartz.threadPool.class">org.quartz.simpl.SimpleThreadPool</prop>
-        <prop key="org.quartz.threadPool.threadCount">2</prop>
-        <prop key="org.quartz.threadPool.threadPriority">4</prop>
-        <prop key="org.quartz.jobStore.class">org.quartz.simpl.RAMJobStore</prop>
-      </props>
-    </property>
-  </bean>
-
-  <alias name="userConfiguration#redback" alias="userConfiguration#default"/>
-</beans>
+  <alias alias="repositorySessionFactory#jcr" name="mockRepositorySessionFactory" />
+</beans>
\ No newline at end of file
index fc7edf915f89d449a9c10fcfeb857ffb0286ab3b..a12b75d2d83cb00705a4524f119a10829440f2da 100644 (file)
     <archiva.version>${archivaVersion}</archiva.version>
     <slf4j.version>${slf4jVersion}</slf4j.version>
     <log4j.version>${log4jVersion}</log4j.version>
-    <jackrabbit.version>${jackrabbitVersion}</jackrabbit.version>
     <spring.version>${springVersion}</spring.version>
-    <guava.version>${guavaVersion}</guava.version>
-    <maven3x.version>${maven3xVersion}</maven3x.version>
     <redback.registry.version>${redbackRegistryVersion}</redback.registry.version>
-    <redback.quartz.version>${redbackQuartzVersion}</redback.quartz.version>
-    <commons.dbcp.version>${commonsDbcpVersion}</commons.dbcp.version>
-    <commons.pool.version>${commonsPoolVersion}</commons.pool.version>
-    <lucene.version>${luceneVersion}</lucene.version>
-    <derby.version>${derbyVersion}</derby.version>
+    <guava.version>${guavaVersion}</guava.version>
+    <springockito.version>${springockitoVersion}</springockito.version>
+    <mockito.version>${mockitoVersion}</mockito.version>
   </properties>
   <dependencies>
     <dependency>
       <artifactId>archiva-repository-admin-api</artifactId>
       <version>${archiva.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-model</artifactId>
+      <version>${archiva.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-repository-layer</artifactId>
+      <version>${archiva.version}</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>metadata-repository-api</artifactId>
+      <version>${archiva.version}</version>
+    </dependency>
     <dependency>
       <groupId>org.apache.archiva.redback.components.registry</groupId>
       <artifactId>spring-registry-api</artifactId>
     </dependency>
     <dependency>
       <groupId>org.apache.archiva</groupId>
-      <artifactId>metadata-store-jcr</artifactId>
+      <artifactId>maven2-repository</artifactId>
       <version>${archiva.version}</version>
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.jackrabbit</groupId>
-      <artifactId>jackrabbit-core</artifactId>
-      <version>${jackrabbit.version}</version>
-      <scope>test</scope>
-      <exclusions>
-        <exclusion>
-          <groupId>commons-logging</groupId>
-          <artifactId>commons-logging</artifactId>
-        </exclusion>
-      </exclusions>
-    </dependency>
-    <dependency>
-      <groupId>org.apache.archiva.redback.components</groupId>
-      <artifactId>spring-quartz</artifactId>
-      <version>${redback.quartz.version}</version>
-      <scope>test</scope>
-    </dependency>
-    <dependency>
-      <groupId>org.slf4j</groupId>
-      <artifactId>jcl-over-slf4j</artifactId>
-      <version>${slf4j.version}</version>
+      <groupId>org.apache.logging.log4j</groupId>
+      <artifactId>log4j-core</artifactId>
+      <version>${log4j.version}</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <scope>test</scope>
     </dependency>
     <dependency>
-      <groupId>org.apache.logging.log4j</groupId>
-      <artifactId>log4j-core</artifactId>
-      <version>${log4j.version}</version>
+      <groupId>org.kubek2k</groupId>
+      <artifactId>springockito</artifactId>
+      <version>${springockito.version}</version>
       <scope>test</scope>
     </dependency>
   </dependencies>
         <version>${guava.version}</version>
       </dependency>
       <dependency>
-        <groupId>org.apache.maven</groupId>
-        <artifactId>maven-model</artifactId>
-        <version>${maven3x.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>commons-dbcp</groupId>
-        <artifactId>commons-dbcp</artifactId>
-        <version>${commons.dbcp.version}</version>
-        <scope>runtime</scope>
-      </dependency>
-      <dependency>
-        <groupId>commons-pool</groupId>
-        <artifactId>commons-pool</artifactId>
-        <version>${commons.pool.version}</version>
-        <scope>runtime</scope>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.lucene</groupId>
-        <artifactId>lucene-core</artifactId>
-        <version>${lucene.version}</version>
-      </dependency>
-      <dependency>
-        <groupId>org.apache.derby</groupId>
-        <artifactId>derby</artifactId>
-        <version>${derby.version}</version>
+        <groupId>org.mockito</groupId>
+        <artifactId>mockito-all</artifactId>
+        <version>${mockito.version}</version>
       </dependency>
     </dependencies>
   </dependencyManagement>
           <target>1.7</target>
         </configuration>
       </plugin>
-      <plugin>
-        <groupId>org.apache.maven.plugins</groupId>
-        <artifactId>maven-surefire-plugin</artifactId>
-        <configuration>
-          <systemPropertyVariables>
-            <appserver.base>${project.build.directory}/appserver-base</appserver.base>
-            <archiva.user.configFileName>${project.build.directory}/archiva.xml</archiva.user.configFileName>
-            <test.resources.path>${project.build.testOutputDirectory}</test.resources.path>
-            <redback.jdbc.url>jdbc:derby:memory:users-test;create=true</redback.jdbc.url>
-            <redback.jdbc.driver.name>org.apache.derby.jdbc.EmbeddedDriver</redback.jdbc.driver.name>
-            <java.io.tmpdir>${project.build.directory}/temp</java.io.tmpdir>
-          </systemPropertyVariables>
-        </configuration>
-      </plugin>
     </plugins>
   </build>
   <!--repositories>
index 7b7766421ad6fe7dc008a427784d060786b4710f..68595074aaf49d1d231c7cad0b87f88c4e43d3e9 100644 (file)
@@ -24,13 +24,8 @@ package=org.apache.archiva.consumer.its
 archivaVersion=${archivaVersion}
 log4jVersion=${log4j.version}
 slf4jVersion=${slf4j.version}
-jackrabbitVersion=${jackrabbit.version}
 springVersion=${spring.version}
 guavaVersion=${guava.version}
-maven3xVersion=${maven3x.version}
 redbackRegistryVersion=${redback.registry.version}
-redbackQuartzVersion=${redback.quartz.version}
-commonsDbcpVersion=${commons-dbcp.version}
-commonsPoolVersion=${commons-pool.version}
-luceneVersion=${lucene.version}
-derbyVersion=${derbyVersion}
+springockitoVersion=${springockito.version}
+mockitoVersion=${mockito.version}
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index a8b86041d89afb0c2680fb4b5d02e02828300ceb..2b64c12537048f393019ed5bbac4ad519671d8ba 100644 (file)
--- a/pom.xml
+++ b/pom.xml
     <tomcat7Version>7.0.54</tomcat7Version>
 
     <release.preparationGoals>clean install</release.preparationGoals>
+    <springockito.version>1.0.9</springockito.version>
+    <mockito.version>1.9.0</mockito.version>
   </properties>
 
   <dependencyManagement>
       <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-all</artifactId>
-        <version>1.8.5</version>
+        <version>${mockito.version}</version>
         <scope>test</scope>
       </dependency>
       <dependency>
         <groupId>org.mockito</groupId>
         <artifactId>mockito-core</artifactId>
-        <version>1.8.5</version>
+        <version>${mockito.version}</version>
+        <scope>test</scope>
+      </dependency>
+      <dependency>
+        <groupId>org.kubek2k</groupId>
+        <artifactId>springockito</artifactId>
+        <version>${springockito.version}</version>
         <scope>test</scope>
       </dependency>
       <dependency>