aboutsummaryrefslogtreecommitdiffstats
path: root/archiva-modules/archiva-web/archiva-webdav
diff options
context:
space:
mode:
authorMartin Stockhammer <martin_s@apache.org>2019-02-10 12:53:02 +0100
committerMartin Stockhammer <martin_s@apache.org>2019-02-10 12:53:02 +0100
commit7a0e81d5156822c0e1b1a5b954be8f7f0199b2a3 (patch)
tree1c3a19eef8d5be83febae1a0df3649ac198ed7b0 /archiva-modules/archiva-web/archiva-webdav
parent21220fcd57d228a7a87694998e354493e92eb978 (diff)
downloadarchiva-7a0e81d5156822c0e1b1a5b954be8f7f0199b2a3.tar.gz
archiva-7a0e81d5156822c0e1b1a5b954be8f7f0199b2a3.zip
Fixing unit tests after refactoring
Diffstat (limited to 'archiva-modules/archiva-web/archiva-webdav')
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/pom.xml4
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java29
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java9
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java33
-rw-r--r--archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/OverridingRepositoryProxyHandler.java55
5 files changed, 86 insertions, 44 deletions
diff --git a/archiva-modules/archiva-web/archiva-webdav/pom.xml b/archiva-modules/archiva-web/archiva-webdav/pom.xml
index 0da5b2e0f..45ccdd810 100644
--- a/archiva-modules/archiva-web/archiva-webdav/pom.xml
+++ b/archiva-modules/archiva-web/archiva-webdav/pom.xml
@@ -89,6 +89,10 @@
</dependency>
<dependency>
<groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-proxy-maven</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
<artifactId>archiva-security</artifactId>
</dependency>
<dependency>
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
index 3abf50c3a..b229ec981 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/archiva/webdav/ArchivaDavResourceFactory.java
@@ -46,6 +46,7 @@ import org.apache.archiva.metadata.repository.storage.RepositoryStorage;
import org.apache.archiva.model.ArchivaRepositoryMetadata;
import org.apache.archiva.model.ArtifactReference;
import org.apache.archiva.policies.ProxyDownloadException;
+import org.apache.archiva.proxy.ProxyRegistry;
import org.apache.archiva.proxy.model.RepositoryProxyHandler;
import org.apache.archiva.redback.authentication.AuthenticationException;
import org.apache.archiva.redback.authentication.AuthenticationResult;
@@ -137,8 +138,7 @@ public class ArchivaDavResourceFactory
private RepositoryRequest repositoryRequest;
@Inject
- @Named( value = "repositoryProxyConnectors#default" )
- private RepositoryProxyHandler connectors;
+ private ProxyRegistry proxyRegistry;
@Inject
private MetadataTools metadataTools;
@@ -753,9 +753,13 @@ public class ArchivaDavResourceFactory
throws DavException
{
String path = resource.getPath();
+ if (!proxyRegistry.hasHandler(managedRepository.getRepository().getType())) {
+ throw new DavException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "No proxy handler found for repository type "+managedRepository.getRepository().getType());
+ }
+ RepositoryProxyHandler proxyHandler = proxyRegistry.getHandler(managedRepository.getRepository().getType()).get(0);
if ( repositoryRequest.isSupportFile( path ) )
{
- Path proxiedFile = connectors.fetchFromProxies( managedRepository, path );
+ Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path );
return ( proxiedFile != null );
}
@@ -763,14 +767,14 @@ public class ArchivaDavResourceFactory
// Is it a Metadata resource?
if ( repositoryRequest.isDefault( path ) && repositoryRequest.isMetadata( path ) )
{
- return connectors.fetchMetadataFromProxies( managedRepository, path ).isModified();
+ return proxyHandler.fetchMetadataFromProxies( managedRepository, path ).isModified();
}
// Is it an Archetype Catalog?
if ( repositoryRequest.isArchetypeCatalog( path ) )
{
// FIXME we must implement a merge of remote archetype catalog from remote servers.
- Path proxiedFile = connectors.fetchFromProxies( managedRepository, path );
+ Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, path );
return ( proxiedFile != null );
}
@@ -789,7 +793,7 @@ public class ArchivaDavResourceFactory
this.applicationContext.getBean( "repositoryStorage#" + repositoryLayout, RepositoryStorage.class );
repositoryStorage.applyServerSideRelocation( managedRepository, artifact );
- Path proxiedFile = connectors.fetchFromProxies( managedRepository, artifact );
+ Path proxiedFile = proxyHandler.fetchFromProxies( managedRepository, artifact );
resource.setPath( managedRepository.toPath( artifact ) );
@@ -917,6 +921,14 @@ public class ArchivaDavResourceFactory
+ path;
}
+ public void setProxyRegistry(ProxyRegistry proxyRegistry) {
+ this.proxyRegistry = proxyRegistry;
+ }
+
+ public ProxyRegistry getProxyRegistry() {
+ return this.proxyRegistry;
+ }
+
private static class LogicalResource
{
private String path;
@@ -1416,11 +1428,6 @@ public class ArchivaDavResourceFactory
this.repositoryRequest = repositoryRequest;
}
- public void setConnectors( RepositoryProxyHandler connectors )
- {
- this.connectors = connectors;
- }
-
public RemoteRepositoryAdmin getRemoteRepositoryAdmin()
{
return remoteRepositoryAdmin;
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
index 3b82377c2..a55d891bd 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/AbstractRepositoryServletTestCase.java
@@ -19,15 +19,10 @@ package org.apache.archiva.webdav;
* under the License.
*/
-import com.gargoylesoftware.htmlunit.HttpMethod;
-import com.gargoylesoftware.htmlunit.NicelyResynchronizingAjaxController;
-import com.gargoylesoftware.htmlunit.WebClient;
-import com.gargoylesoftware.htmlunit.WebRequest;
-import com.gargoylesoftware.htmlunit.WebResponse;
+import com.gargoylesoftware.htmlunit.*;
import junit.framework.TestCase;
import net.sf.ehcache.CacheManager;
import org.apache.archiva.admin.model.beans.ManagedRepository;
-import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
import org.apache.archiva.configuration.ArchivaConfiguration;
import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.ManagedRepositoryConfiguration;
@@ -101,8 +96,6 @@ public abstract class AbstractRepositoryServletTestCase
@Inject
protected ApplicationContext applicationContext;
- @Inject
- protected ManagedRepositoryAdmin managedRepositoryAdmin;
@Inject
RepositoryRegistry repositoryRegistry;
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
index b568076a0..22a99f3b0 100644
--- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/ArchivaDavResourceFactoryTest.java
@@ -34,8 +34,7 @@ import org.apache.archiva.configuration.Configuration;
import org.apache.archiva.configuration.FileTypes;
import org.apache.archiva.configuration.RepositoryGroupConfiguration;
import org.apache.archiva.metadata.repository.storage.maven2.ArtifactMappingProvider;
-import org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler;
-import org.apache.archiva.proxy.model.ProxyFetchResult;
+import org.apache.archiva.proxy.ProxyRegistry;
import org.apache.archiva.repository.EditableManagedRepository;
import org.apache.archiva.repository.ManagedRepositoryContent;
import org.apache.archiva.repository.RemoteRepository;
@@ -50,7 +49,6 @@ import org.apache.archiva.repository.RepositoryType;
import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent;
import org.apache.archiva.repository.content.maven2.RepositoryRequest;
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.jackrabbit.webdav.DavException;
import org.apache.jackrabbit.webdav.DavResourceLocator;
@@ -68,7 +66,6 @@ import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.ContextConfiguration;
import javax.inject.Inject;
-import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -139,6 +136,9 @@ public class ArchivaDavResourceFactoryTest
@Inject
RemoteRepositoryAdmin remoteRepositoryAdmin;
+ @Inject
+ ProxyRegistry proxyRegistry;
+
@Inject
DefaultRepositoryGroupAdmin defaultRepositoryGroupAdmin;
@@ -149,7 +149,7 @@ public class ArchivaDavResourceFactoryTest
@Inject
FileTypes fileTypes;
- private Path getProjectBase() {
+ public Path getProjectBase() {
if (this.projectBase.get()==null) {
String pathVal = System.getProperty("mvn.project.base.dir");
Path baseDir;
@@ -229,7 +229,9 @@ public class ArchivaDavResourceFactoryTest
resourceFactory.setArchivaConfiguration( archivaConfiguration );
resourceFactory.setRepositoryFactory( repoFactory );
resourceFactory.setRepositoryRequest( repoRequest );
- resourceFactory.setConnectors( new OverridingRepositoryProxyHandler() );
+ proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).clear();
+ proxyRegistry.getAllHandler().get(RepositoryType.MAVEN).add(new OverridingRepositoryProxyHandler(this));
+ resourceFactory.setProxyRegistry(proxyRegistry);
resourceFactory.setRemoteRepositoryAdmin( remoteRepositoryAdmin );
resourceFactory.setManagedRepositoryAdmin( defaultManagedRepositoryAdmin );
resourceFactory.setRepositoryRegistry( repositoryRegistry );
@@ -749,23 +751,4 @@ public class ArchivaDavResourceFactoryTest
}
}
- class OverridingRepositoryProxyHandler
- extends MavenRepositoryProxyHandler
- {
- @Override
- public ProxyFetchResult fetchMetadataFromProxies( ManagedRepositoryContent repository, String logicalPath )
- {
- Path target = Paths.get(repository.getRepoRoot(), logicalPath );
- try
- {
- FileUtils.copyFile( getProjectBase().resolve( "target/test-classes/maven-metadata.xml" ).toFile(), target.toFile() );
- }
- catch ( IOException e )
- {
-
- }
-
- return new ProxyFetchResult( target, true );
- }
- }
}
diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/OverridingRepositoryProxyHandler.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/OverridingRepositoryProxyHandler.java
new file mode 100644
index 000000000..75f6726b7
--- /dev/null
+++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/webdav/OverridingRepositoryProxyHandler.java
@@ -0,0 +1,55 @@
+package org.apache.archiva.webdav;
+
+/*
+ * 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.
+ */
+
+import org.apache.archiva.proxy.maven.MavenRepositoryProxyHandler;
+import org.apache.archiva.proxy.model.ProxyFetchResult;
+import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.commons.io.FileUtils;
+
+import java.io.IOException;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+
+class OverridingRepositoryProxyHandler
+ extends MavenRepositoryProxyHandler
+{
+ private ArchivaDavResourceFactoryTest archivaDavResourceFactoryTest;
+
+ public OverridingRepositoryProxyHandler(ArchivaDavResourceFactoryTest archivaDavResourceFactoryTest) {
+ this.archivaDavResourceFactoryTest = archivaDavResourceFactoryTest;
+ }
+
+ @Override
+ public ProxyFetchResult fetchMetadataFromProxies(ManagedRepositoryContent repository, String logicalPath )
+ {
+ Path target = Paths.get(repository.getRepoRoot(), logicalPath );
+ try
+ {
+ FileUtils.copyFile( archivaDavResourceFactoryTest.getProjectBase().resolve( "target/test-classes/maven-metadata.xml" ).toFile(), target.toFile() );
+ }
+ catch ( IOException e )
+ {
+
+ }
+
+ return new ProxyFetchResult( target, true );
+ }
+}