]> source.dussan.org Git - archiva.git/commitdiff
New test for group handler
authorMartin Stockhammer <martin_s@apache.org>
Tue, 6 Jul 2021 18:46:51 +0000 (20:46 +0200)
committerMartin Stockhammer <martin_s@apache.org>
Tue, 6 Jul 2021 18:46:51 +0000 (20:46 +0200)
archiva-modules/archiva-base/archiva-repository-api/src/main/java/org/apache/archiva/repository/RepositoryHandler.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/group/RepositoryGroupHandler.java
archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/archiva/repository/base/managed/ManagedRepositoryHandler.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/base/group/RepositoryGroupHandlerTest.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/java/org/apache/archiva/repository/mock/RepositoryProviderMock.java
archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva-group.xml [new file with mode: 0644]
archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context-group.xml [new file with mode: 0644]

index efd6c47f5bef79b226fee80c01fb12303e451473..058fd6543d227caf503e6d3f3585d322b75a304c 100644 (file)
@@ -22,7 +22,6 @@ import org.apache.archiva.repository.validation.CheckedResult;
 import org.apache.archiva.repository.validation.RepositoryChecker;
 import org.apache.archiva.repository.validation.RepositoryValidator;
 import org.apache.archiva.repository.validation.ValidationError;
-import org.apache.archiva.repository.validation.ValidationResponse;
 
 import java.util.Collection;
 import java.util.List;
@@ -57,7 +56,7 @@ public interface RepositoryHandler<R extends Repository, C>
      * Initializes the repository. E.g. starts scheduling and activate additional processes.
      * @param repository the repository to initialize
      */
-    void initialize( R repository );
+    void activateRepository( R repository );
 
     /**
      * Creates new instances from the archiva configuration. The instances are not registered in the registry.
@@ -77,7 +76,7 @@ public interface RepositoryHandler<R extends Repository, C>
     R newInstance( RepositoryType type, String id ) throws RepositoryException;
 
     /**
-     * Creates a new instance and updates the given configuration object.
+     * Creates a new instance based on the given configuration instance. The instance is not activated and not registered.
      *
      * @param repositoryConfiguration the configuration instance
      * @return a newly created instance
@@ -152,10 +151,11 @@ public interface RepositoryHandler<R extends Repository, C>
     void remove( String id, Configuration configuration ) throws RepositoryException;
 
     /**
-     * Returns the repository with the given identifier or <code>null</code>, if it is not registered.
+     * Returns the repository with the given identifier or <code>null</code>, if no repository is registered
+     * with the given id.
      *
      * @param id the repository id
-     * @return if the retrieval failed
+     * @return the repository instance or <code>null</code>
      */
     R get( String id );
 
@@ -222,12 +222,12 @@ public interface RepositoryHandler<R extends Repository, C>
     boolean has( String id );
 
     /**
-     * Initializes
+     * Initializes the handler. This method must be called before using the repository handler.
      */
     void init( );
 
     /**
-     * Closes the handler
+     * Closes the handler. After closing, the repository handler instance is not usable anymore.
      */
     void close( );
 
index 560eb722d4fb32b412d7a80ab28120364af206ea..40365765cb553446f188eca4fc5938aceb15c37e 100644 (file)
@@ -42,7 +42,6 @@ import org.apache.archiva.repository.storage.StorageAsset;
 import org.apache.archiva.repository.validation.RepositoryChecker;
 import org.apache.archiva.repository.validation.RepositoryValidator;
 import org.apache.archiva.repository.validation.ValidationError;
-import org.apache.archiva.repository.validation.ValidationResponse;
 import org.apache.commons.lang3.StringUtils;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -125,7 +124,7 @@ public class RepositoryGroupHandler
         this.repositoryGroups.putAll( newInstancesFromConfig( ) );
         for ( RepositoryGroup group : this.repositoryGroups.values( ) )
         {
-            initialize( group );
+            activateRepository( group );
         }
     }
 
@@ -147,7 +146,7 @@ public class RepositoryGroupHandler
     }
 
     @Override
-    public void initialize( RepositoryGroup repositoryGroup )
+    public void activateRepository( RepositoryGroup repositoryGroup )
     {
         StorageAsset indexDirectory = getMergedIndexDirectory( repositoryGroup );
         if ( !indexDirectory.exists( ) )
@@ -296,7 +295,7 @@ public class RepositoryGroupHandler
                 configuration.addRepositoryGroup( newCfg );
                 configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
                 setLastState( repositoryGroup, RepositoryState.SAVED );
-                initialize( repositoryGroup );
+                activateRepository( repositoryGroup );
             }
             finally
             {
@@ -357,7 +356,7 @@ public class RepositoryGroupHandler
                 configurationHandler.save( configuration, ConfigurationHandler.REGISTRY_EVENT_TAG );
                 updateReferences( currentRepository, repositoryGroupConfiguration );
                 setLastState( currentRepository, RepositoryState.REFERENCES_SET );
-                initialize( currentRepository );
+                activateRepository( currentRepository );
                 this.repositoryGroups.put( id, currentRepository );
                 setLastState( currentRepository, RepositoryState.REGISTERED );
             }
@@ -379,7 +378,7 @@ public class RepositoryGroupHandler
                     }
                     updateReferences( oldRepository, oldCfg  );
                     setLastState( oldRepository, RepositoryState.REFERENCES_SET );
-                    initialize( oldRepository );
+                    activateRepository( oldRepository );
                     repositoryGroups.put( id, oldRepository );
                     setLastState( oldRepository, RepositoryState.REGISTERED );
                 } else {
index c7b10c6e5881735655a8490634ee5e01f7c23f43..6cfb228ecad7c4c4ebcadfda56d37b20303ad98e 100644 (file)
@@ -77,13 +77,13 @@ implements RepositoryHandler<ManagedRepository, ManagedRepositoryConfiguration>
         this.managedRepositories.putAll( newInstancesFromConfig( ) );
         for ( ManagedRepository managedRepository : this.managedRepositories.values( ) )
         {
-            initialize( managedRepository );
+            activateRepository( managedRepository );
         }
 
     }
 
     @Override
-    public void initialize( ManagedRepository repository )
+    public void activateRepository( ManagedRepository repository )
     {
 
     }
index 0043ee00608801a965161a1a01bcf6f1801b8d26..09c1c1d8b39b58f21b136c9bfd9a709c61c81d8c 100644 (file)
@@ -18,20 +18,66 @@ package org.apache.archiva.repository.base.group;
  * under the License.
  */
 
+import org.apache.archiva.configuration.ArchivaConfiguration;
+import org.apache.archiva.indexer.merger.MergedRemoteIndexesScheduler;
+import org.apache.archiva.repository.Repository;
+import org.apache.archiva.repository.RepositoryRegistry;
+import org.apache.archiva.repository.base.ArchivaRepositoryRegistry;
+import org.apache.archiva.repository.base.ConfigurationHandler;
+import org.apache.archiva.repository.validation.RepositoryValidator;
 import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit.jupiter.SpringExtension;
+
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import java.util.List;
 
 import static org.junit.jupiter.api.Assertions.*;
 
 /**
  * @author Martin Stockhammer <martin_s@apache.org>
  */
+@ExtendWith( SpringExtension.class)
+@ContextConfiguration(locations = { "classpath*:/META-INF/spring-context.xml", "classpath:/spring-context-group.xml" })
 class RepositoryGroupHandlerTest
 {
 
+    @Inject
+    @Named("repositoryRegistry")
+    ArchivaRepositoryRegistry repositoryRegistry;
+
+    @Inject
+    ConfigurationHandler configurationHandler;
+
+    @Inject
+    @Named( "mergedRemoteIndexesScheduler#default" )
+    MergedRemoteIndexesScheduler mergedRemoteIndexesScheduler;
+
+    @Inject
+    List<RepositoryValidator<? extends Repository>> repositoryValidatorList;
+
+    @Inject
+    ArchivaConfiguration archivaConfiguration;
+
+
+    private RepositoryGroupHandler createHandler() {
+        RepositoryGroupHandler groupHandler = new RepositoryGroupHandler( repositoryRegistry, configurationHandler, mergedRemoteIndexesScheduler, repositoryValidatorList );
+        groupHandler.init();
+        return groupHandler;
+    }
 
     @Test
     void initializeFromConfig( )
     {
+        RepositoryGroupHandler groupHandler = createHandler( );
+        assertNotNull( groupHandler );
+        groupHandler.initializeFromConfig();
+        assertEquals( 1, groupHandler.getAll( ).size( ) );
+        assertNotNull( groupHandler.get( "test-group-01" ).getRepositories( ) );
+        assertEquals( "internal", groupHandler.get( "test-group-01" ).getRepositories( ).get( 0 ).getId() );
     }
 
     @Test
index c98ba066b4203477d6edcedc1b327ff3a80b22cc..5a4c9f5ae459cca4013f554aabaa894a503ac762 100644 (file)
@@ -25,6 +25,7 @@ import org.apache.archiva.configuration.RepositoryGroupConfiguration;
 import org.apache.archiva.event.EventHandler;
 import org.apache.archiva.repository.*;
 import org.apache.archiva.event.Event;
+import org.apache.archiva.repository.base.group.BasicRepositoryGroup;
 import org.apache.archiva.repository.event.RepositoryEvent;
 import org.apache.archiva.repository.features.ArtifactCleanupFeature;
 import org.apache.archiva.repository.features.IndexCreationFeature;
@@ -81,7 +82,15 @@ public class RepositoryProviderMock implements RepositoryProvider
 
     @Override
     public EditableRepositoryGroup createRepositoryGroup(String id, String name) {
-        return null;
+        try
+        {
+            return BasicRepositoryGroup.newFilesystemInstance( id, name, Paths.get( "target/groups" ) );
+        }
+        catch ( IOException e )
+        {
+            throw new RuntimeException( );
+        }
+
     }
 
     @Override
@@ -195,7 +204,15 @@ public class RepositoryProviderMock implements RepositoryProvider
 
     @Override
     public RepositoryGroup createRepositoryGroup(RepositoryGroupConfiguration configuration) throws RepositoryException {
-        return null;
+        EditableRepositoryGroup group = createRepositoryGroup( configuration.getId( ), configuration.getName( ) );
+        updateGroupInstance( group, configuration );
+        return group;
+    }
+
+    private void updateGroupInstance( EditableRepositoryGroup group, RepositoryGroupConfiguration configuration )
+    {
+        group.setMergedIndexTTL( configuration.getMergedIndexTtl() );
+        group.setSchedulingDefinition( configuration.getCronExpression() );
     }
 
     @Override
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva-group.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/archiva-group.xml
new file mode 100644 (file)
index 0000000..693d106
--- /dev/null
@@ -0,0 +1,212 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<configuration>
+  <version>3.0.0</version>
+  <managedRepositories>
+    <managedRepository>
+      <id>internal</id>
+      <name>Archiva Managed Internal Repository</name>
+      <description>This is internal repository.</description>
+      <location>${appserver.base}/repositories/internal</location>
+      <indexDir>${appserver.base}/repositories/internal/.indexer</indexDir>
+      <layout>default</layout>
+      <releases>true</releases>
+      <snapshots>false</snapshots>
+      <blockRedeployments>true</blockRedeployments>
+      <scanned>true</scanned>
+      <refreshCronExpression>0 0 * * * ?</refreshCronExpression>
+      <retentionPeriod>30</retentionPeriod>
+    </managedRepository>
+    <managedRepository>
+      <id>staging</id>
+      <name>Repository with staging</name>
+      <description>This is repository with staging.</description>
+      <location>${appserver.base}/repositories/internal</location>
+      <indexDir>${appserver.base}/repositories/internal/.indexer</indexDir>
+      <layout>default</layout>
+      <releases>true</releases>
+      <snapshots>false</snapshots>
+      <blockRedeployments>true</blockRedeployments>
+      <scanned>true</scanned>
+      <refreshCronExpression>0 0 * * * ?</refreshCronExpression>
+      <retentionPeriod>30</retentionPeriod>
+      <stageRepoNeeded>true</stageRepoNeeded>
+    </managedRepository>
+    <managedRepository>
+      <id>snapshots</id>
+      <name>Archiva Managed Snapshot Repository</name>
+      <location>${appserver.base}/repositories/snapshots</location>
+      <indexDir>${appserver.base}/repositories/snapshots/.indexer</indexDir>
+      <layout>default</layout>
+      <releases>false</releases>
+      <snapshots>true</snapshots>
+      <blockRedeployments>false</blockRedeployments>
+      <scanned>true</scanned>
+      <refreshCronExpression>0 0\,30 * * * ?</refreshCronExpression>
+      <retentionPeriod>30</retentionPeriod>
+    </managedRepository>
+  </managedRepositories>
+  <remoteRepositories>
+    <remoteRepository>
+      <id>central</id>
+      <name>Central Repository</name>
+      <url>https://repo.maven.apache.org/maven2</url>
+      <layout>default</layout>
+      <timeout>35</timeout>
+    </remoteRepository>
+  </remoteRepositories>
+  <repositoryGroups>
+    <repositoryGroup>
+      <id>test-group-01</id>
+      <name>Test Group 01</name>
+      <type>MAVEN</type>
+      <repositories>
+        <repository>internal</repository>
+      </repositories>
+    </repositoryGroup>
+  </repositoryGroups>
+
+  <proxyConnectors>
+    <proxyConnector>
+      <sourceRepoId>internal</sourceRepoId>
+      <targetRepoId>central</targetRepoId>
+      <proxyId/>
+      <policies>
+        <snapshots>disabled</snapshots>
+        <releases>once</releases>
+        <checksum>fix</checksum>
+        <cache-failures>cached</cache-failures>
+      </policies>
+      <whiteListPatterns>
+        <whiteListPattern>**/*</whiteListPattern>
+      </whiteListPatterns>
+    </proxyConnector>
+  </proxyConnectors>
+
+  <legacyArtifactPaths>
+    <legacyArtifactPath>
+        <path>jaxen/jars/jaxen-1.0-FCS-full.jar</path>
+        <artifact>jaxen:jaxen:1.0-FCS:full:jar</artifact>
+    </legacyArtifactPath>
+  </legacyArtifactPaths>
+
+  <repositoryScanning>
+    <fileTypes>
+      <fileType>
+        <id>artifacts</id>
+        <patterns>
+          <pattern>**/*.pom</pattern>
+          <pattern>**/*.jar</pattern>
+          <pattern>**/*.ear</pattern>
+          <pattern>**/*.war</pattern>
+          <pattern>**/*.car</pattern>
+          <pattern>**/*.sar</pattern>
+          <pattern>**/*.mar</pattern>
+          <pattern>**/*.rar</pattern>
+          <pattern>**/*.dtd</pattern>
+          <pattern>**/*.tld</pattern>
+          <pattern>**/*.tar.gz</pattern>
+          <pattern>**/*.tar.bz2</pattern>
+          <pattern>**/*.zip</pattern>
+        </patterns>
+      </fileType>
+      <fileType>
+        <id>indexable-content</id>
+        <patterns>
+          <pattern>**/*.txt</pattern>
+          <pattern>**/*.TXT</pattern>
+          <pattern>**/*.block</pattern>
+          <pattern>**/*.config</pattern>
+          <pattern>**/*.pom</pattern>
+          <pattern>**/*.xml</pattern>
+          <pattern>**/*.xsd</pattern>
+          <pattern>**/*.dtd</pattern>
+          <pattern>**/*.tld</pattern>
+        </patterns>
+      </fileType>
+      <fileType>
+        <id>auto-remove</id>
+        <patterns>
+          <pattern>**/*.bak</pattern>
+          <pattern>**/*~</pattern>
+          <pattern>**/*-</pattern>
+        </patterns>
+      </fileType>
+      <fileType>
+        <id>ignored</id>
+        <patterns>
+          <pattern>**/.htaccess</pattern>
+          <pattern>**/KEYS</pattern>
+          <pattern>**/*.rb</pattern>
+          <pattern>**/*.sh</pattern>
+          <pattern>**/.svn/**</pattern>
+          <pattern>**/.DAV/**</pattern>
+          <pattern>.index/**</pattern>
+          <pattern>.indexer/**</pattern>
+        </patterns>
+      </fileType>
+    </fileTypes>
+    <knownContentConsumers>
+      <knownContentConsumer>create-missing-checksums</knownContentConsumer>
+      <knownContentConsumer>validate-checksum</knownContentConsumer>
+      <knownContentConsumer>validate-signature</knownContentConsumer>
+      <knownContentConsumer>index-content</knownContentConsumer>
+      <knownContentConsumer>auto-remove</knownContentConsumer>
+      <knownContentConsumer>auto-rename</knownContentConsumer>
+      <knownContentConsumer>metadata-updater</knownContentConsumer>
+      <knownContentConsumer>create-archiva-metadata</knownContentConsumer>
+      <knownContentConsumer>duplicate-artifacts</knownContentConsumer>
+      <!--knownContentConsumer>repository-purge</knownContentConsumer-->
+    </knownContentConsumers>
+    <invalidContentConsumers>
+      <invalidContentConsumer>update-db-bad-content</invalidContentConsumer>
+    </invalidContentConsumers>
+  </repositoryScanning>
+
+  <webapp>
+    <ui>
+      <showFindArtifacts>true</showFindArtifacts>
+      <appletFindEnabled>true</appletFindEnabled>
+    </ui>
+  </webapp>
+
+  <redbackRuntimeConfiguration>
+    <userManagerImpls>
+      <userManagerImpl>jpa</userManagerImpl>
+    </userManagerImpls>
+    <rbacManagerImpls>
+      <rbacManagerImpl>cached</rbacManagerImpl>
+    </rbacManagerImpls>
+  </redbackRuntimeConfiguration>
+
+  <archivaDefaultConfiguration>
+    <defaultCheckPaths>
+      <defaultCheckPath>
+        <url>http://download.oracle.com/maven</url>
+        <path>com/sleepycat/je/license.txt</path>
+      </defaultCheckPath>
+      <defaultCheckPath>
+        <url>https://download.oracle.com/maven</url>
+        <path>com/sleepycat/je/license.txt</path>
+      </defaultCheckPath>
+    </defaultCheckPaths>
+  </archivaDefaultConfiguration>
+
+</configuration>
diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context-group.xml b/archiva-modules/archiva-base/archiva-repository-layer/src/test/resources/spring-context-group.xml
new file mode 100644 (file)
index 0000000..ccf6211
--- /dev/null
@@ -0,0 +1,57 @@
+<?xml version="1.0"?>
+
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you under the Apache License, Version 2.0 (the
+  ~ "License"); you may not use this file except in compliance
+  ~ with the License.  You may obtain a copy of the License at
+  ~
+  ~   http://www.apache.org/licenses/LICENSE-2.0
+  ~
+  ~ Unless required by applicable law or agreed to in writing,
+  ~ software distributed under the License is distributed on an
+  ~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  ~ KIND, either express or implied.  See the License for the
+  ~ specific language governing permissions and limitations
+  ~ under the License.
+  -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xmlns:context="http://www.springframework.org/schema/context"
+       xsi:schemaLocation="http://www.springframework.org/schema/beans
+           http://www.springframework.org/schema/beans/spring-beans.xsd
+           http://www.springframework.org/schema/context 
+           http://www.springframework.org/schema/context/spring-context.xsd"
+       default-lazy-init="true">
+
+  <context:annotation-config/>
+  <context:component-scan base-package="org.apache.archiva.repository.mock"/>
+
+
+  <bean name="commons-configuration" class="org.apache.archiva.components.registry.commons.CommonsConfigurationRegistry">
+    <property name="initialConfiguration">
+      <value>
+        <![CDATA[
+        <configuration>
+          <system/>
+          <xml fileName="archiva-group.xml" config-forceCreate="true"
+               config-optional="true"
+               config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
+        </configuration>
+        ]]>
+      </value>
+    </property>
+  </bean>
+
+
+  <bean name="taskScheduler#mergeRemoteIndexes"
+        class="org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler">
+    <property name="poolSize" value="4"/>
+    <property name="threadGroupName" value="mergeRemoteIndexes"/>
+  </bean>
+
+
+</beans>
\ No newline at end of file