]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1496] Broken remote repository confuses Archiva
authorOlivier Lamy <olamy@apache.org>
Fri, 30 Sep 2011 09:40:59 +0000 (09:40 +0000)
committerOlivier Lamy <olamy@apache.org>
Fri, 30 Sep 2011 09:40:59 +0000 (09:40 +0000)
fixed with wagon 2.0 upgrade but add a unit test.

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1177570 13f79535-47bb-0310-9956-ffa450edef68

23 files changed:
archiva-modules/archiva-web/archiva-rest/archiva-rest-services/pom.xml
archiva-modules/archiva-web/archiva-webapp/pom.xml
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/DownloadArtifactsTest.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestRepositorySessionFactory.java [deleted file]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/AbstractActionTestCase.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/BrowseActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/DeleteArtifactActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/SearchActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/ShowArtifactActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/DeleteManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/EditManagedRepositoryActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/admin/repositories/RepositoriesActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/action/reports/GenerateReportActionTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/web/tags/DependencyTreeTest.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestMetadataResolver.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context-DependencyTreeTest.xml
archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context-artifacts-download.xml [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context-rss-servlet.xml
archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context.xml

index 120d30eadeaaf13b4fb59413e4863d3d0c662062..8ab8092ead8bacc02300bb671c9728a9fd1d73e4 100644 (file)
@@ -30,7 +30,7 @@
 
   <properties>
     <jettyVersion>7.4.5.v20110725</jettyVersion>
-    <archiva.baseRestUrl></archiva.baseRestUrl>
+    <archiva.base.admUrl></archiva.baseRestUrl>
     <rest.admin.pwd></rest.admin.pwd>
   </properties>
 
index c4a985fb5da1537d93af9ea283f616186903002b..82de2ddfb210618f1e7d5ea62e438cba778fa666 100644 (file)
   <artifactId>archiva-webapp</artifactId>
   <packaging>war</packaging>
   <name>Archiva Web :: Application</name>
+
+  <properties>
+    <jettyVersion>7.4.5.v20110725</jettyVersion>
+    <archiva.baseRestUrl></archiva.baseRestUrl>
+    <rest.admin.pwd></rest.admin.pwd>
+  </properties>
+
   <dependencies>
     <dependency>
       <groupId>org.apache.archiva</groupId>
       <groupId>org.apache.archiva</groupId>
       <artifactId>archiva-rest-services</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.archiva</groupId>
+      <artifactId>archiva-rest-api</artifactId>
+    </dependency>
     <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
         </exclusion>
       </exclusions>
     </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-server</artifactId>
+      <version>${jettyVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.eclipse.jetty</groupId>
+      <artifactId>jetty-plus</artifactId>
+      <version>${jettyVersion}</version>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>org.codehaus.redback</groupId>
+      <artifactId>redback-rest-services</artifactId>
+      <classifier>tests</classifier>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
   <build>
     <resources>
           <systemPropertyVariables>
             <plexus.home>${project.build.outputDirectory}</plexus.home>
             <appserver.base>${project.build.outputDirectory}</appserver.base>
+            <archiva.baseRestUrl>${archiva.baseRestUrl}</archiva.baseRestUrl>
+            <rest.admin.pwd>${rest.admin.pwd}</rest.admin.pwd>
           </systemPropertyVariables>
         </configuration>
       </plugin>
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/DownloadArtifactsTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/DownloadArtifactsTest.java
new file mode 100644 (file)
index 0000000..4bc623f
--- /dev/null
@@ -0,0 +1,327 @@
+package org.apache.archiva;
+/*
+ * 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 junit.framework.TestCase;
+import org.apache.archiva.admin.model.beans.RemoteRepository;
+import org.apache.archiva.rest.api.services.ProxyConnectorService;
+import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
+import org.apache.archiva.webdav.RepositoryServlet;
+import org.apache.commons.lang.StringUtils;
+import org.apache.cxf.common.util.Base64Utility;
+import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
+import org.apache.cxf.jaxrs.client.WebClient;
+import org.apache.cxf.transport.servlet.CXFServlet;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.redback.integration.security.role.RedbackRoleConstants;
+import org.codehaus.redback.rest.api.services.RoleManagementService;
+import org.codehaus.redback.rest.api.services.UserService;
+import org.codehaus.redback.rest.services.FakeCreateAdminService;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.session.SessionHandler;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.servlet.ServletHolder;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.ContextLoaderListener;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+/**
+ * @author Olivier Lamy
+ */
+@RunWith( JUnit4.class )
+public class DownloadArtifactsTest
+    extends TestCase
+{
+
+    protected static Logger log = LoggerFactory.getLogger( DownloadArtifactsTest.class );
+
+    public String authorizationHeader = getAdminAuthzHeader();
+
+    public Server server = null;
+
+    public Server redirectServer = null;
+
+    public int port;
+
+    public int redirectPort;
+
+    public static String encode( String uid, String password )
+    {
+        return "Basic " + Base64Utility.encode( ( uid + ":" + password ).getBytes() );
+    }
+
+    public static String getAdminAuthzHeader()
+    {
+        String adminPwdSysProps = System.getProperty( "rest.admin.pwd" );
+        if ( StringUtils.isBlank( adminPwdSysProps ) )
+        {
+            return encode( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, FakeCreateAdminService.ADMIN_TEST_PWD );
+        }
+        return encode( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME, adminPwdSysProps );
+    }
+
+    protected String getSpringConfigLocation()
+    {
+        return "classpath*:META-INF/spring-context.xml classpath*:spring-context-artifacts-download.xml";
+    }
+
+
+    protected String getRestServicesPath()
+    {
+        return "restServices";
+    }
+
+    static String previousAppServerBase;
+
+    @BeforeClass
+    public static void setAppServerBase()
+    {
+
+        previousAppServerBase = System.getProperty( "appserver.base" );
+        System.setProperty( "appserver.base", "target/" + DownloadArtifactsTest.class.getName() );
+    }
+
+
+    @AfterClass
+    public static void resetAppServerBase()
+    {
+
+        System.setProperty( "appserver.base", previousAppServerBase );
+    }
+
+    @Before
+    public void startServer()
+        throws Exception
+    {
+
+        System.setProperty( "redback.admin.creation.file", "target/auto-admin-creation.properties" );
+        this.server = new Server( 0 );
+
+        ServletContextHandler context = new ServletContextHandler();
+
+        context.setContextPath( "/" );
+
+        context.setInitParameter( "contextConfigLocation", getSpringConfigLocation() );
+
+        ContextLoaderListener contextLoaderListener = new ContextLoaderListener();
+
+        context.addEventListener( contextLoaderListener );
+
+        ServletHolder sh = new ServletHolder( CXFServlet.class );
+
+        SessionHandler sessionHandler = new SessionHandler();
+
+        context.setSessionHandler( sessionHandler );
+
+        context.addServlet( sh, "/" + getRestServicesPath() + "/*" );
+
+        ServletHolder repoSh = new ServletHolder( RepositoryServlet.class );
+        context.addServlet( repoSh, "/repository/*" );
+
+        server.setHandler( context );
+        this.server.start();
+        Connector connector = this.server.getConnectors()[0];
+        this.port = connector.getLocalPort();
+        log.info( "start server on port " + this.port );
+
+        //redirect handler
+
+        this.redirectServer = new Server( 0 );
+        ServletHolder shRedirect = new ServletHolder( RedirectServlet.class );
+        ServletContextHandler contextRedirect = new ServletContextHandler();
+
+        contextRedirect.setContextPath( "/" );
+        contextRedirect.addServlet( shRedirect, "/*" );
+
+        redirectServer.setHandler( contextRedirect );
+        redirectServer.start();
+        this.redirectPort = redirectServer.getConnectors()[0].getLocalPort();
+        log.info( "redirect server port {}", redirectPort );
+
+        FakeCreateAdminService fakeCreateAdminService = getFakeCreateAdminService();
+
+        Boolean res = fakeCreateAdminService.createAdminIfNeeded();
+        assertTrue( res.booleanValue() );
+
+
+    }
+
+    @After
+    public void tearDown()
+        throws Exception
+    {
+        System.clearProperty( "redback.admin.creation.file" );
+        super.tearDown();
+    }
+
+    @Test
+    public void downloadWithRemoteRedirect()
+        throws Exception
+    {
+        RemoteRepository remoteRepository = getRemoteRepositoriesService().getRemoteRepository( "central" );
+        remoteRepository.setUrl( "http://localhost:" + redirectPort );
+        getRemoteRepositoriesService().updateRemoteRepository( remoteRepository );
+
+        RoleManagementService roleManagementService = getRoleManagementService( authorizationHeader );
+
+        if ( !roleManagementService.templatedRoleExists( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER,
+                                                         "internal" ) )
+        {
+            roleManagementService.createTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal" );
+        }
+
+        getUserService( authorizationHeader ).createGuestUser();
+        roleManagementService.assignRole( ArchivaRoleConstants.TEMPLATE_GUEST, "guest" );
+
+        roleManagementService.assignTemplatedRole( ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, "internal",
+                                                   "guest" );
+
+        getUserService( authorizationHeader ).removeFromCache( "guest" );
+
+        URL url = new URL( "http://localhost:" + port + "/repository/internal/junit/junit/4.9/junit-4.9.jar" );
+        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
+        //urlConnection.setRequestProperty( "Authorization", authorizationHeader );
+        InputStream is = urlConnection.getInputStream();
+        File file = new File( "target/junit-4.9.jar" );
+        if ( file.exists() )
+        {
+            file.delete();
+        }
+
+        FileWriter fw = new FileWriter( file );
+        IOUtil.copy( is, fw );
+        // assert jar contains org/junit/runners/JUnit4.class
+        ZipFile zipFile = new ZipFile( file );
+        ZipEntry zipEntry = zipFile.getEntry( "org/junit/runners/JUnit4.class" );
+        assertNotNull( zipEntry );
+        zipFile.close();
+        file.deleteOnExit();
+    }
+
+    public static class RedirectServlet
+        extends HttpServlet
+    {
+        @Override
+        protected void doGet( HttpServletRequest req, HttpServletResponse resp )
+            throws ServletException, IOException
+        {
+
+            log.info( "redirect servlet receive: {}", req.getRequestURI() );
+            resp.setStatus( 302 );
+            resp.getWriter().write( "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n" + "<html><head>\n"
+                                        + "<title>302 Found</title>\n" + "</head><body>\n" + "<h1>Found</h1>\n"
+                                        + "<p>The document has moved <a href=\"http://repo1.maven.apache.org/maven2/junit/junit/4.9/junit-4.9.jar\">here</a>.</p>\n"
+                                        + "</body></html>\n" + "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\n"
+                                        + "<html><head>\n" );
+            resp.sendRedirect( "http://repo1.maven.apache.org/maven2/" + req.getRequestURI() );
+        }
+    }
+
+    protected ProxyConnectorService getProxyConnectorService()
+    {
+        ProxyConnectorService service =
+            JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
+                                       ProxyConnectorService.class );
+
+        WebClient.client( service ).header( "Authorization", authorizationHeader );
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L );
+        return service;
+    }
+
+    protected RemoteRepositoriesService getRemoteRepositoriesService()
+    {
+        RemoteRepositoriesService service =
+            JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/",
+                                       RemoteRepositoriesService.class );
+
+        WebClient.client( service ).header( "Authorization", authorizationHeader );
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L );
+        return service;
+    }
+
+    protected String getBaseUrl()
+    {
+        String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
+        return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + port : baseUrlSysProps;
+    }
+
+
+    protected RoleManagementService getRoleManagementService( String authzHeader )
+    {
+        RoleManagementService service =
+            JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/redbackServices/",
+                                       RoleManagementService.class );
+
+        // for debuging purpose
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 3000000L );
+
+        if ( authzHeader != null )
+        {
+            WebClient.client( service ).header( "Authorization", authzHeader );
+        }
+        return service;
+    }
+
+    protected UserService getUserService( String authzHeader )
+    {
+        UserService service =
+            JAXRSClientFactory.create( "http://localhost:" + port + "/" + getRestServicesPath() + "/redbackServices/",
+                                       UserService.class );
+
+        // for debuging purpose
+        WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 3000000L );
+
+        if ( authzHeader != null )
+        {
+            WebClient.client( service ).header( "Authorization", authzHeader );
+        }
+        return service;
+    }
+
+    protected FakeCreateAdminService getFakeCreateAdminService()
+    {
+        return JAXRSClientFactory.create(
+            "http://localhost:" + port + "/" + getRestServicesPath() + "/fakeCreateAdminService/",
+            FakeCreateAdminService.class );
+    }
+
+
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataRepository.java
deleted file mode 100644 (file)
index f1ae981..0000000
+++ /dev/null
@@ -1,224 +0,0 @@
-package org.apache.archiva.metadata.repository.memory;
-
-/*
- * 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.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.model.MetadataFacet;
-import org.apache.archiva.metadata.model.ProjectMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionReference;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-public class TestMetadataRepository
-    implements MetadataRepository
-{
-    private static final String TEST_REPO = "test-repo";
-
-    private static final String TEST_NAMESPACE = "org.apache.archiva";
-
-    private List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
-
-    private List<String> versions = new ArrayList<String>();
-
-    public TestMetadataRepository()
-    {
-        Date whenGathered = new Date( 123456789 );
-
-        addArtifact( "artifact-one", "1.0", whenGathered );
-        addArtifact( "artifact-one", "1.1", whenGathered );
-        addArtifact( "artifact-one", "2.0", whenGathered );
-        addArtifact( "artifact-two", "1.0.1", whenGathered );
-        addArtifact( "artifact-two", "1.0.2", whenGathered );
-        addArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered );
-        addArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered );
-        addArtifact( "artifact-four", "1.1-beta-2", whenGathered );
-    }
-
-    private void addArtifact( String projectId, String projectVersion, Date whenGathered )
-    {
-        ArtifactMetadata artifact = new ArtifactMetadata();
-        artifact.setFileLastModified( System.currentTimeMillis() );
-        artifact.setNamespace( TEST_NAMESPACE );
-        artifact.setProjectVersion( projectVersion );
-        artifact.setVersion( projectVersion );
-        artifact.setId( projectId + "-" + projectVersion + ".jar" );
-        artifact.setProject( projectId );
-        artifact.setRepositoryId( TEST_REPO );
-        artifact.setWhenGathered( whenGathered );
-        artifacts.add( artifact );
-
-        versions.add( projectVersion );
-    }
-
-    public ProjectMetadata getProject( String repoId, String namespace, String projectId )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
-                                                     String projectVersion )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
-                                                   String projectVersion )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
-                                                                     String projectVersion )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Collection<String> getRootNamespaces( String repoId )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Collection<String> getNamespaces( String repoId, String namespace )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Collection<String> getProjects( String repoId, String namespace )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
-    {
-        return versions;
-    }
-
-    public void updateProject( String repoId, ProjectMetadata project )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion,
-                                ArtifactMetadata artifactMeta )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public void updateProjectVersion( String repoId, String namespace, String projectId,
-                                      ProjectVersionMetadata versionMetadata )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public void updateNamespace( String repoId, String namespace )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public List<String> getMetadataFacets( String repodId, String facetId )
-    {
-        return Collections.emptyList();
-    }
-
-    public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public void removeMetadataFacets( String repositoryId, String facetId )
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public void removeMetadataFacet( String repoId, String facetId, String name )
-    {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
-    {
-        return artifacts;
-    }
-
-    public Collection<String> getRepositories()
-    {
-        return Collections.singletonList( TEST_REPO );
-    }
-
-    public List<ArtifactMetadata> getArtifactsByChecksum( String repoId, String checksum )
-    {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
-    {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public void removeRepository( String repoId )
-    {
-        //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
-                                                      String projectVersion )
-    {
-        return artifacts;
-    }
-
-    public void save()
-    {
-    }
-
-    public void close()
-    {
-    }
-
-    public void revert()
-    {
-        throw new UnsupportedOperationException();
-    }
-
-    public boolean canObtainAccess( Class<?> aClass )
-    {
-        return false;  //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public Object obtainAccess( Class<?> aClass )
-    {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
-    }
-
-    public List<ArtifactMetadata> getArtifacts( String repositoryId )
-    {
-        return artifacts;
-    }
-}
\ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestMetadataResolver.java
deleted file mode 100644 (file)
index 0e2033b..0000000
+++ /dev/null
@@ -1,160 +0,0 @@
-package org.apache.archiva.metadata.repository.memory;
-
-/*
- * 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.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionReference;
-import org.apache.archiva.metadata.repository.MetadataResolver;
-import org.apache.archiva.metadata.repository.RepositorySession;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class TestMetadataResolver
-    implements MetadataResolver
-{
-    private Map<String, ProjectVersionMetadata> projectVersions = new HashMap<String, ProjectVersionMetadata>();
-
-    private Map<String, List<ArtifactMetadata>> artifacts = new HashMap<String, List<ArtifactMetadata>>();
-
-    private Map<String, List<ProjectVersionReference>> references =
-        new HashMap<String, List<ProjectVersionReference>>();
-
-    private Map<String, List<String>> namespaces = new HashMap<String, List<String>>();
-
-    private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>();
-
-    private Map<String, Collection<String>> versionsInProject = new HashMap<String, Collection<String>>();
-
-    public ProjectVersionMetadata resolveProjectVersion( RepositorySession repositorySession, String repoId,
-                                                         String namespace, String projectId, String projectVersion )
-    {
-        return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
-    }
-
-    public Collection<ProjectVersionReference> resolveProjectReferences( RepositorySession repositorySession,
-                                                                         String repoId, String namespace,
-                                                                         String projectId, String projectVersion )
-    {
-        Collection<ProjectVersionReference> projectVersionReferences =
-            references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
-        return projectVersionReferences;
-    }
-
-    public Collection<String> resolveRootNamespaces( RepositorySession repositorySession, String repoId )
-    {
-        return resolveNamespaces( repositorySession, repoId, null );
-    }
-
-    public Collection<String> resolveNamespaces( RepositorySession repositorySession, String repoId,
-                                                 String baseNamespace )
-    {
-        Set<String> namespaces = new LinkedHashSet<String>();
-        int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
-        for ( String namespace : this.namespaces.get( repoId ) )
-        {
-            if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) )
-            {
-                int i = namespace.indexOf( '.', fromIndex );
-                if ( i >= 0 )
-                {
-                    namespaces.add( namespace.substring( fromIndex, i ) );
-                }
-                else
-                {
-                    namespaces.add( namespace.substring( fromIndex ) );
-                }
-            }
-        }
-        return namespaces;
-    }
-
-    public Collection<String> resolveProjects( RepositorySession repositorySession, String repoId, String namespace )
-    {
-        Collection<String> list = projectsInNamespace.get( namespace );
-        return list != null ? list : Collections.<String>emptyList();
-    }
-
-    public Collection<String> resolveProjectVersions( RepositorySession repositorySession, String repoId,
-                                                      String namespace, String projectId )
-    {
-        Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
-        return list != null ? list : Collections.<String>emptyList();
-    }
-
-    public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession repositorySession, String repoId,
-                                                          String namespace, String projectId, String projectVersion )
-    {
-        List<ArtifactMetadata> artifacts =
-            this.artifacts.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
-        return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() );
-    }
-
-    public void setProjectVersion( String repoId, String namespace, String projectId,
-                                   ProjectVersionMetadata versionMetadata )
-    {
-        projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
-
-        Collection<String> projects = projectsInNamespace.get( namespace );
-        if ( projects == null )
-        {
-            projects = new LinkedHashSet<String>();
-            projectsInNamespace.put( namespace, projects );
-        }
-        projects.add( projectId );
-
-        String key = namespace + ":" + projectId;
-        Collection<String> versions = versionsInProject.get( key );
-        if ( versions == null )
-        {
-            versions = new LinkedHashSet<String>();
-            versionsInProject.put( key, versions );
-        }
-        versions.add( versionMetadata.getId() );
-    }
-
-    public void setArtifacts( String repoId, String namespace, String projectId, String projectVersion,
-                              List<ArtifactMetadata> artifacts )
-    {
-        this.artifacts.put( createMapKey( repoId, namespace, projectId, projectVersion ), artifacts );
-    }
-
-    private String createMapKey( String repoId, String namespace, String projectId, String projectVersion )
-    {
-        return repoId + ":" + namespace + ":" + projectId + ":" + projectVersion;
-    }
-
-    public void setProjectReferences( String repoId, String namespace, String projectId, String projectVersion,
-                                      List<ProjectVersionReference> references )
-    {
-        this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
-    }
-
-    public void setNamespaces( String repoId, List<String> namespaces )
-    {
-        this.namespaces.put( repoId, namespaces );
-    }
-}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestRepositorySessionFactory.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/metadata/repository/memory/TestRepositorySessionFactory.java
deleted file mode 100644 (file)
index bbe5ce5..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-package org.apache.archiva.metadata.repository.memory;
-
-/*
- * 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.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.RepositorySessionFactory;
-import org.springframework.stereotype.Service;
-
-@Service("repositorySessionFactory#test")
-public class TestRepositorySessionFactory
-    implements RepositorySessionFactory
-{
-    private RepositorySession repositorySession;
-
-    public void setRepositorySession( RepositorySession repositorySession )
-    {
-        this.repositorySession = repositorySession;
-    }
-
-    public RepositorySession createSession()
-    {
-        return repositorySession != null ? repositorySession : new RepositorySession( new TestMetadataRepository(),
-                                                                                      new TestMetadataResolver() );
-    }
-}
index 3c5193d463793b88b84e7b5e4ebb5de305be54db..ce330cb266244f9533dc88caeb58347cb399168a 100644 (file)
@@ -33,7 +33,7 @@ import org.apache.archiva.metadata.model.License;
 import org.apache.archiva.metadata.model.Organization;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.Scm;
-import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
+import org.apache.archiva.webtest.memory.TestMetadataResolver;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectFacet;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenProjectParent;
 import org.apache.archiva.security.UserRepositoriesStub;
index 7d9f45e30ca7c81c02d8b86c606637d590add211..9503ccbd47fb9f228dda7343e839fd380f6f2649 100644 (file)
@@ -23,10 +23,9 @@ import com.google.common.collect.Lists;
 import com.opensymphony.xwork2.Action;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestMetadataResolver;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.scheduler.indexing.DefaultDownloadRemoteIndexScheduler;
-import org.springframework.context.support.GenericApplicationContext;
 
 import java.util.Arrays;
 import java.util.Collections;
index 1dc6ae899088fda0be5cd6fdf6a5763b4b2a2164..e5f468d5e72fd6df472d2eaa76a587008b86933f 100644 (file)
@@ -25,7 +25,7 @@ import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.commons.lang.StringUtils;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.Configuration;
index 3065f52864e7aecb1791f8f753ffea8a83152fff..d46e880f1345e929bf62d1ac034feafcd1cb3ab6 100644 (file)
@@ -30,7 +30,7 @@ import org.apache.archiva.indexer.util.SearchUtil;
 import org.apache.archiva.metadata.model.ArtifactMetadata;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.security.UserRepositories;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.easymock.MockControl;
index 32aafde0cc0c3ad42527a05e791066f967bcb141..51b9975953dc8915b08490d9bafcf408387d208f 100644 (file)
@@ -29,8 +29,8 @@ import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.model.ProjectVersionReference;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestMetadataResolver;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.metadata.repository.storage.maven2.MavenArtifactFacet;
 import org.apache.archiva.reports.RepositoryProblemFacet;
 import org.apache.archiva.common.utils.VersionUtil;
index 3d09c40957816bae0963dfe0d4ef1a10d4aeee8a..f1e7e84565cbd5776920401009741ecc9d4d3b14 100644 (file)
@@ -29,7 +29,7 @@ import org.apache.archiva.audit.AuditEvent;
 import org.apache.archiva.audit.AuditListener;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
 import org.apache.archiva.security.ArchivaRoleConstants;
 import org.apache.archiva.configuration.ArchivaConfiguration;
index 7c5feded2bb409aacdac09b187ac3f1b79f39011..7c75b9b8739731fd8ceccd788b511d303cce8490 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin
 import org.apache.archiva.audit.AuditListener;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
 import org.apache.archiva.scheduler.repository.RepositoryArchivaTaskScheduler;
 import org.apache.archiva.scheduler.repository.RepositoryTask;
index 601a55488e1cbb84311d33bc67251d45047febcf..4b767add695297c81cc9bb792da2fda2ce86f81a 100644 (file)
@@ -27,7 +27,7 @@ import org.apache.archiva.admin.repository.managed.DefaultManagedRepositoryAdmin
 import org.apache.archiva.admin.repository.remote.DefaultRemoteRepositoryAdmin;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.struts2.StrutsSpringTestCase;
index d74aad4a67b2556424e5d3b72bd2d02bbd586830..354032e5b0fc69681c1b992a4c9512243c589688 100644 (file)
@@ -26,7 +26,7 @@ import org.apache.archiva.admin.model.managed.ManagedRepositoryAdmin;
 import org.apache.archiva.metadata.model.MetadataFacet;
 import org.apache.archiva.metadata.repository.MetadataRepository;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatistics;
 import org.apache.archiva.metadata.repository.stats.RepositoryStatisticsManager;
 import org.apache.archiva.reports.RepositoryProblemFacet;
index 851e1cf56d160bd19d9e75b1b4e5933edb769f0a..5c7421c9bbad6a91bb9ee9f19eb5333d78a32331 100644 (file)
@@ -29,8 +29,8 @@ import junit.framework.TestCase;
 import org.apache.archiva.common.plexusbridge.PlexusSisuBridge;
 import org.apache.archiva.metadata.model.ProjectVersionMetadata;
 import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.memory.TestMetadataResolver;
-import org.apache.archiva.metadata.repository.memory.TestRepositorySessionFactory;
+import org.apache.archiva.webtest.memory.TestMetadataResolver;
+import org.apache.archiva.webtest.memory.TestRepositorySessionFactory;
 import org.apache.archiva.common.ArchivaException;
 import org.apache.archiva.configuration.ArchivaConfiguration;
 import org.apache.archiva.configuration.Configuration;
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java
new file mode 100644 (file)
index 0000000..482637f
--- /dev/null
@@ -0,0 +1,224 @@
+package org.apache.archiva.webtest.memory;
+
+/*
+ * 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.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.MetadataFacet;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+public class TestMetadataRepository
+    implements MetadataRepository
+{
+    private static final String TEST_REPO = "test-repo";
+
+    private static final String TEST_NAMESPACE = "org.apache.archiva";
+
+    private List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
+
+    private List<String> versions = new ArrayList<String>();
+
+    public TestMetadataRepository()
+    {
+        Date whenGathered = new Date( 123456789 );
+
+        addArtifact( "artifact-one", "1.0", whenGathered );
+        addArtifact( "artifact-one", "1.1", whenGathered );
+        addArtifact( "artifact-one", "2.0", whenGathered );
+        addArtifact( "artifact-two", "1.0.1", whenGathered );
+        addArtifact( "artifact-two", "1.0.2", whenGathered );
+        addArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered );
+        addArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered );
+        addArtifact( "artifact-four", "1.1-beta-2", whenGathered );
+    }
+
+    private void addArtifact( String projectId, String projectVersion, Date whenGathered )
+    {
+        ArtifactMetadata artifact = new ArtifactMetadata();
+        artifact.setFileLastModified( System.currentTimeMillis() );
+        artifact.setNamespace( TEST_NAMESPACE );
+        artifact.setProjectVersion( projectVersion );
+        artifact.setVersion( projectVersion );
+        artifact.setId( projectId + "-" + projectVersion + ".jar" );
+        artifact.setProject( projectId );
+        artifact.setRepositoryId( TEST_REPO );
+        artifact.setWhenGathered( whenGathered );
+        artifacts.add( artifact );
+
+        versions.add( projectVersion );
+    }
+
+    public ProjectMetadata getProject( String repoId, String namespace, String projectId )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
+                                                     String projectVersion )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
+                                                   String projectVersion )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+                                                                     String projectVersion )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Collection<String> getRootNamespaces( String repoId )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Collection<String> getNamespaces( String repoId, String namespace )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Collection<String> getProjects( String repoId, String namespace )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+    {
+        return versions;
+    }
+
+    public void updateProject( String repoId, ProjectMetadata project )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion,
+                                ArtifactMetadata artifactMeta )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void updateProjectVersion( String repoId, String namespace, String projectId,
+                                      ProjectVersionMetadata versionMetadata )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void updateNamespace( String repoId, String namespace )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public List<String> getMetadataFacets( String repodId, String facetId )
+    {
+        return Collections.emptyList();
+    }
+
+    public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void removeMetadataFacets( String repositoryId, String facetId )
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public void removeMetadataFacet( String repoId, String facetId, String name )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
+    {
+        return artifacts;
+    }
+
+    public Collection<String> getRepositories()
+    {
+        return Collections.singletonList( TEST_REPO );
+    }
+
+    public List<ArtifactMetadata> getArtifactsByChecksum( String repoId, String checksum )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public void removeRepository( String repoId )
+    {
+        //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
+                                                      String projectVersion )
+    {
+        return artifacts;
+    }
+
+    public void save()
+    {
+    }
+
+    public void close()
+    {
+    }
+
+    public void revert()
+    {
+        throw new UnsupportedOperationException();
+    }
+
+    public boolean canObtainAccess( Class<?> aClass )
+    {
+        return false;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public Object obtainAccess( Class<?> aClass )
+    {
+        return null;  //To change body of implemented methods use File | Settings | File Templates.
+    }
+
+    public List<ArtifactMetadata> getArtifacts( String repositoryId )
+    {
+        return artifacts;
+    }
+}
\ No newline at end of file
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestMetadataResolver.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestMetadataResolver.java
new file mode 100644 (file)
index 0000000..2a5ba06
--- /dev/null
@@ -0,0 +1,160 @@
+package org.apache.archiva.webtest.memory;
+
+/*
+ * 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.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.RepositorySession;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class TestMetadataResolver
+    implements MetadataResolver
+{
+    private Map<String, ProjectVersionMetadata> projectVersions = new HashMap<String, ProjectVersionMetadata>();
+
+    private Map<String, List<ArtifactMetadata>> artifacts = new HashMap<String, List<ArtifactMetadata>>();
+
+    private Map<String, List<ProjectVersionReference>> references =
+        new HashMap<String, List<ProjectVersionReference>>();
+
+    private Map<String, List<String>> namespaces = new HashMap<String, List<String>>();
+
+    private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>();
+
+    private Map<String, Collection<String>> versionsInProject = new HashMap<String, Collection<String>>();
+
+    public ProjectVersionMetadata resolveProjectVersion( RepositorySession repositorySession, String repoId,
+                                                         String namespace, String projectId, String projectVersion )
+    {
+        return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
+    }
+
+    public Collection<ProjectVersionReference> resolveProjectReferences( RepositorySession repositorySession,
+                                                                         String repoId, String namespace,
+                                                                         String projectId, String projectVersion )
+    {
+        Collection<ProjectVersionReference> projectVersionReferences =
+            references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
+        return projectVersionReferences;
+    }
+
+    public Collection<String> resolveRootNamespaces( RepositorySession repositorySession, String repoId )
+    {
+        return resolveNamespaces( repositorySession, repoId, null );
+    }
+
+    public Collection<String> resolveNamespaces( RepositorySession repositorySession, String repoId,
+                                                 String baseNamespace )
+    {
+        Set<String> namespaces = new LinkedHashSet<String>();
+        int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
+        for ( String namespace : this.namespaces.get( repoId ) )
+        {
+            if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) )
+            {
+                int i = namespace.indexOf( '.', fromIndex );
+                if ( i >= 0 )
+                {
+                    namespaces.add( namespace.substring( fromIndex, i ) );
+                }
+                else
+                {
+                    namespaces.add( namespace.substring( fromIndex ) );
+                }
+            }
+        }
+        return namespaces;
+    }
+
+    public Collection<String> resolveProjects( RepositorySession repositorySession, String repoId, String namespace )
+    {
+        Collection<String> list = projectsInNamespace.get( namespace );
+        return list != null ? list : Collections.<String>emptyList();
+    }
+
+    public Collection<String> resolveProjectVersions( RepositorySession repositorySession, String repoId,
+                                                      String namespace, String projectId )
+    {
+        Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
+        return list != null ? list : Collections.<String>emptyList();
+    }
+
+    public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession repositorySession, String repoId,
+                                                          String namespace, String projectId, String projectVersion )
+    {
+        List<ArtifactMetadata> artifacts =
+            this.artifacts.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
+        return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() );
+    }
+
+    public void setProjectVersion( String repoId, String namespace, String projectId,
+                                   ProjectVersionMetadata versionMetadata )
+    {
+        projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
+
+        Collection<String> projects = projectsInNamespace.get( namespace );
+        if ( projects == null )
+        {
+            projects = new LinkedHashSet<String>();
+            projectsInNamespace.put( namespace, projects );
+        }
+        projects.add( projectId );
+
+        String key = namespace + ":" + projectId;
+        Collection<String> versions = versionsInProject.get( key );
+        if ( versions == null )
+        {
+            versions = new LinkedHashSet<String>();
+            versionsInProject.put( key, versions );
+        }
+        versions.add( versionMetadata.getId() );
+    }
+
+    public void setArtifacts( String repoId, String namespace, String projectId, String projectVersion,
+                              List<ArtifactMetadata> artifacts )
+    {
+        this.artifacts.put( createMapKey( repoId, namespace, projectId, projectVersion ), artifacts );
+    }
+
+    private String createMapKey( String repoId, String namespace, String projectId, String projectVersion )
+    {
+        return repoId + ":" + namespace + ":" + projectId + ":" + projectVersion;
+    }
+
+    public void setProjectReferences( String repoId, String namespace, String projectId, String projectVersion,
+                                      List<ProjectVersionReference> references )
+    {
+        this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
+    }
+
+    public void setNamespaces( String repoId, List<String> namespaces )
+    {
+        this.namespaces.put( repoId, namespaces );
+    }
+}
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/archiva/webtest/memory/TestRepositorySessionFactory.java
new file mode 100644 (file)
index 0000000..f311d97
--- /dev/null
@@ -0,0 +1,42 @@
+package org.apache.archiva.webtest.memory;
+
+/*
+ * 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.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.springframework.stereotype.Service;
+
+@Service("repositorySessionFactory#test")
+public class TestRepositorySessionFactory
+    implements RepositorySessionFactory
+{
+    private RepositorySession repositorySession;
+
+    public void setRepositorySession( RepositorySession repositorySession )
+    {
+        this.repositorySession = repositorySession;
+    }
+
+    public RepositorySession createSession()
+    {
+        return repositorySession != null ? repositorySession : new RepositorySession( new TestMetadataRepository(),
+                                                                                      new TestMetadataResolver() );
+    }
+}
index 79e981ec1f6142c74e73ba6d92fb5be5d178cbc4..9144b0745b98d8a2146061624ccdd063b048bcc5 100644 (file)
@@ -30,7 +30,7 @@
   <context:property-placeholder system-properties-mode="OVERRIDE"/>
 
   <context:annotation-config/>
-  <context:component-scan base-package="org.apache.archiva.metadata.repository.memory"/>
+  <context:component-scan base-package="org.apache.archiva.webtest.memory"/>
 
   <bean name="archivaConfiguration#test" class="org.apache.archiva.configuration.TestConfiguration" />
   <alias name="archivaConfiguration#test" alias="archivaConfiguration#default" />
diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context-artifacts-download.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/spring-context-artifacts-download.xml
new file mode 100644 (file)
index 0000000..03ea7e7
--- /dev/null
@@ -0,0 +1,54 @@
+<?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-3.0.xsd
+           http://www.springframework.org/schema/context 
+           http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+       default-lazy-init="true">
+
+  <context:property-placeholder system-properties-mode="OVERRIDE"/>
+
+
+  <bean name="commons-configuration" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+    <property name="properties">
+      <value>
+        <![CDATA[
+        <configuration>
+          <system/>
+
+          <xml fileName="${appserver.base}/conf/archiva-test-download-artifacts.xml" config-optional="true"
+               config-name="org.apache.maven.archiva.base"
+               config-at="org.apache.maven.archiva"/>
+
+          <properties fileName="${appserver.base}/conf/security.properties" config-optional="true"
+                      config-at="org.codehaus.plexus.redback"/>
+          <properties fileName="org/apache/archiva/security.properties" config-at="org.codehaus.plexus.redback"/>
+        </configuration>
+        ]]>
+      </value>
+    </property>
+  </bean>
+
+
+</beans>
index 37834e2178656f213b0ad9abcfab4d43bb94e508..7860e21a103cc84a2527b2fbe1cb6fd6afd56d1a 100644 (file)
@@ -30,7 +30,7 @@
   <context:property-placeholder system-properties-mode="OVERRIDE"/>
 
   <context:annotation-config/>
-  <context:component-scan base-package="org.apache.archiva.metadata.repository.memory"/>
+  <context:component-scan base-package="org.apache.archiva.webtest.memory"/>
 
   <alias name="repositorySessionFactory#test" alias="repositorySessionFactory"/>
 
index 8c2633875294817aca86c182f5e90ba96191e77d..fe6cbae7632ca02988a5c618ebbaebea53303864 100644 (file)
@@ -30,7 +30,7 @@
   <context:property-placeholder system-properties-mode="OVERRIDE"/>
 
   <context:annotation-config/>
-  <context:component-scan base-package="org.apache.archiva.metadata.repository.memory"/>
+  <context:component-scan base-package="org.apache.archiva.webtest.memory"/>
 
   <alias name="repositorySessionFactory#test" alias="repositorySessionFactory"/>
 
@@ -38,6 +38,6 @@
 
   <alias name="userRepositories#test" alias="userRepositories"/>
 
-  <bean name="metadataResolver#test" class="org.apache.archiva.metadata.repository.memory.TestMetadataResolver"/>
+  <bean name="metadataResolver#test" class="org.apache.archiva.webtest.memory.TestMetadataResolver"/>
   <alias name="metadataResolver#test" alias="metadataResolver#default"/>
 </beans>