1 package org.apache.archiva;
3 import com.google.common.io.Files;
4 import org.apache.archiva.admin.model.beans.RemoteRepository;
5 import org.apache.archiva.remotedownload.AbstractDownloadTest;
6 import org.apache.archiva.rest.api.services.RemoteRepositoriesService;
7 import org.apache.catalina.startup.Tomcat;
8 import org.apache.commons.io.FileUtils;
9 import org.apache.cxf.jaxrs.client.WebClient;
10 import org.eclipse.jetty.server.Handler;
11 import org.eclipse.jetty.server.Server;
12 import org.eclipse.jetty.server.handler.ContextHandler;
13 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
14 import org.eclipse.jetty.server.handler.DefaultHandler;
15 import org.eclipse.jetty.server.handler.HandlerList;
16 import org.eclipse.jetty.server.handler.ResourceHandler;
17 import org.eclipse.jetty.servlet.DefaultServlet;
18 import org.eclipse.jetty.servlet.ServletContextHandler;
19 import org.eclipse.jetty.servlet.ServletHolder;
20 import org.junit.AfterClass;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
27 * @author Olivier Lamy
29 public class RemoteRepositoryConnectivityCheckTest
30 extends AbstractDownloadTest
34 public static void setAppServerBase()
36 previousAppServerBase = System.getProperty( "appserver.base" );
37 System.setProperty( "appserver.base", "target/" + RemoteRepositoryConnectivityCheckTest.class.getName() );
42 public static void resetAppServerBase()
44 System.setProperty( "appserver.base", previousAppServerBase );
47 protected String getSpringConfigLocation()
49 return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml";
53 public void checkRemoteConnectivity()
58 buildStaticServer( new File( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ) );
61 RemoteRepositoriesService service = getRemoteRepositoriesService();
63 WebClient.client( service ).header( "Authorization", authorizationHeader );
68 int repoServerPort = repoServer.getConnectors()[0].getLocalPort();
70 RemoteRepository repo = getRemoteRepository();
72 repo.setUrl( "http://localhost:" + repoServerPort );
74 service.addRemoteRepository( repo );
76 service.checkRemoteConnectivity( repo.getId() );
80 service.deleteRemoteRepository( "id-new" );
86 public void checkRemoteConnectivityEmptyRemote()
90 File tmpDir = Files.createTempDir();
91 Server repoServer = buildStaticServer( tmpDir );
94 RemoteRepositoriesService service = getRemoteRepositoriesService();
96 WebClient.client( service ).header( "Authorization", authorizationHeader );
101 int repoServerPort = repoServer.getConnectors()[0].getLocalPort();
103 RemoteRepository repo = getRemoteRepository();
105 repo.setUrl( "http://localhost:" + repoServerPort );
107 service.addRemoteRepository( repo );
109 service.checkRemoteConnectivity( repo.getId() );
113 service.deleteRemoteRepository( "id-new" );
114 FileUtils.deleteQuietly( tmpDir );
119 protected Server buildStaticServer( File path )
121 Server repoServer = new Server( 0 );
123 ResourceHandler resourceHandler = new ResourceHandler();
124 resourceHandler.setDirectoriesListed( true );
125 resourceHandler.setWelcomeFiles( new String[]{ "index.html" } );
126 resourceHandler.setResourceBase( path.getAbsolutePath() );
128 HandlerList handlers = new HandlerList();
129 handlers.setHandlers( new Handler[]{ resourceHandler, new DefaultHandler() } );
130 repoServer.setHandler( handlers );
136 RemoteRepository getRemoteRepository()
138 return new RemoteRepository( "id-new", "new one", "http://foo.com", "default", "foo", "foopassword", 120,