diff options
author | Olivier Lamy <olamy@apache.org> | 2012-09-13 08:39:06 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2012-09-13 08:39:06 +0000 |
commit | 3cf32bb9ad6d23f4539b6af48de118b0d327dcad (patch) | |
tree | ec95572fd7fa6037bbe8a5b5cb705863da0465ea | |
parent | 46b69ff5f0a671307b3f902d7fd3481ee61c4dc4 (diff) | |
download | archiva-3cf32bb9ad6d23f4539b6af48de118b0d327dcad.tar.gz archiva-3cf32bb9ad6d23f4539b6af48de118b0d327dcad.zip |
ensure file are cleaned before test for folks who do not use clean and break the build (folks like me I mean :-))
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1384231 13f79535-47bb-0310-9956-ffa450edef68
5 files changed, 812 insertions, 0 deletions
diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/AbstractDownloadTest.java b/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/AbstractDownloadTest.java new file mode 100644 index 000000000..fdf51e81b --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/AbstractDownloadTest.java @@ -0,0 +1,278 @@ +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.rest.api.services.ManagedRepositoriesService; +import org.apache.archiva.rest.api.services.ProxyConnectorService; +import org.apache.archiva.rest.api.services.RemoteRepositoriesService; +import org.apache.archiva.rest.api.services.RepositoriesService; +import org.apache.archiva.rest.api.services.RepositoryGroupService; +import org.apache.archiva.rest.api.services.SearchService; +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.jackson.jaxrs.JacksonJaxbJsonProvider; +import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants; +import org.apache.archiva.redback.rest.api.model.User; +import org.apache.archiva.redback.rest.api.services.RoleManagementService; +import org.apache.archiva.redback.rest.api.services.UserService; +import org.apache.archiva.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.Before; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.web.context.ContextLoaderListener; + +import java.util.Collections; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.junit.runner.RunWith; + +/** + * @author Olivier Lamy + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public abstract class AbstractDownloadTest + extends TestCase +{ + + protected Logger log = LoggerFactory.getLogger( getClass() ); + + static String previousAppServerBase; + + public String authorizationHeader = getAdminAuthzHeader(); + + public Server server = null; + + public int port; + + 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 abstract String getSpringConfigLocation(); + + + protected String getRestServicesPath() + { + return "restServices"; + } + + + @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 ); + + User user = new User(); + user.setEmail( "toto@toto.fr" ); + user.setFullName( "the root user" ); + user.setUsername( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME ); + user.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD ); + + getUserService( null ).createAdminUser( user ); + + + } + + + @After + public void tearDown() + throws Exception + { + System.clearProperty( "redback.admin.creation.file" ); + super.tearDown(); + if ( this.server != null ) + { + this.server.stop(); + } + } + + + protected ProxyConnectorService getProxyConnectorService() + { + ProxyConnectorService service = + JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", + ProxyConnectorService.class, + Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + 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, + Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + WebClient.client( service ).header( "Authorization", authorizationHeader ); + WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); + return service; + } + + protected ManagedRepositoriesService getManagedRepositoriesService() + { + ManagedRepositoriesService service = + JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", + ManagedRepositoriesService.class, + Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + WebClient.client( service ).header( "Authorization", authorizationHeader ); + WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); + return service; + } + + + protected RepositoryGroupService getRepositoryGroupService() + { + RepositoryGroupService service = + JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", + RepositoryGroupService.class, + Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + WebClient.client( service ).header( "Authorization", authorizationHeader ); + WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); + return service; + } + + protected RepositoriesService getRepositoriesService() + { + RepositoriesService service = + JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", + RepositoriesService.class, + Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + WebClient.client( service ).header( "Authorization", authorizationHeader ); + WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000L ); + return service; + } + + protected SearchService getSearchService() + { + SearchService service = + JAXRSClientFactory.create( getBaseUrl() + "/" + getRestServicesPath() + "/archivaServices/", + SearchService.class, + Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + 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, + Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + // 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, Collections.singletonList( new JacksonJaxbJsonProvider() ) ); + + // 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-js/src/test/java/org/apache/archiva/DownloadArtifactsTest.java b/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/DownloadArtifactsTest.java new file mode 100644 index 000000000..ff1c7322e --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/DownloadArtifactsTest.java @@ -0,0 +1,240 @@ +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 org.apache.archiva.admin.model.beans.RemoteRepository; +import org.apache.archiva.redback.rest.api.services.RoleManagementService; +import org.apache.archiva.security.common.ArchivaRoleConstants; +import org.apache.commons.compress.utils.IOUtils; +import org.apache.commons.io.FileUtils; +import org.apache.maven.wagon.providers.http.HttpWagon; +import org.apache.maven.wagon.repository.Repository; +import org.eclipse.jetty.server.Server; +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.slf4j.Logger; +import org.slf4j.LoggerFactory; + +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.FileInputStream; +import java.io.IOException; +import java.util.ArrayList; +import java.util.Collections; +import java.util.Enumeration; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; + +/** + * @author Olivier Lamy + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class DownloadArtifactsTest + extends AbstractDownloadTest +{ + + protected Logger log = LoggerFactory.getLogger( DownloadArtifactsTest.class ); + + public Server redirectServer = null; + + public int redirectPort; + + public Server repoServer = null; + + public int repoServerPort; + + @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 ); + } + + protected String getSpringConfigLocation() + { + return "classpath*:META-INF/spring-context.xml classpath*:spring-context-artifacts-download.xml"; + } + + @Before + public void startServer() + throws Exception + { + super.startServer(); + + // repo handler + + this.repoServer = new Server( 0 ); + + ServletHolder shRepo = new ServletHolder( RepoServlet.class ); + ServletContextHandler contextRepo = new ServletContextHandler(); + + contextRepo.setContextPath( "/" ); + contextRepo.addServlet( shRepo, "/*" ); + + repoServer.setHandler( contextRepo ); + repoServer.start(); + this.repoServerPort = repoServer.getConnectors()[0].getLocalPort(); + + //redirect handler + + this.redirectServer = new Server( 0 ); + ServletHolder shRedirect = new ServletHolder( RedirectServlet.class ); + ServletContextHandler contextRedirect = new ServletContextHandler(); + contextRedirect.setAttribute( "redirectToPort", Integer.toString( this.repoServerPort ) ); + + contextRedirect.setContextPath( "/" ); + contextRedirect.addServlet( shRedirect, "/*" ); + + redirectServer.setHandler( contextRedirect ); + redirectServer.start(); + this.redirectPort = redirectServer.getConnectors()[0].getLocalPort(); + log.info( "redirect server port {}", redirectPort ); + + + + } + + @After + public void tearDown() + throws Exception + { + super.tearDown(); + if ( this.redirectServer != null ) + { + this.redirectServer.stop(); + } + } + + @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" ); + + File file = new File( "target/junit-4.9.jar" ); + if ( file.exists() ) + { + file.delete(); + } + + HttpWagon httpWagon = new HttpWagon(); + httpWagon.connect( new Repository( "foo", "http://localhost:" + port ) ); + + httpWagon.get( "/repository/internal/junit/junit/4.9/junit-4.9.jar", file ); + + ZipFile zipFile = new ZipFile( file ); + List<String> entries = getZipEntriesNames( zipFile ); + ZipEntry zipEntry = zipFile.getEntry( "org/junit/runners/JUnit4.class" ); + assertNotNull( "cannot find zipEntry org/junit/runners/JUnit4.class, entries: " + entries + ", content is: " + + FileUtils.readFileToString( file ), zipEntry ); + zipFile.close(); + file.deleteOnExit(); + } + + private List<String> getZipEntriesNames( ZipFile zipFile ) + { + try + { + List<String> entriesNames = new ArrayList<String>(); + Enumeration<? extends ZipEntry> entries = zipFile.entries(); + while ( entries.hasMoreElements() ) + { + entriesNames.add( entries.nextElement().getName() ); + } + return entriesNames; + } + catch ( Throwable e ) + { + log.info( "fail to get zipEntries " + e.getMessage(), e ); + } + return Collections.emptyList(); + } + + + public static class RedirectServlet + extends HttpServlet + { + @Override + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) + throws ServletException, IOException + { + + LoggerFactory.getLogger( getClass() ).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://repo.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://localhost:" + getServletContext().getAttribute( "redirectToPort" ) + "/maven2/" + + req.getRequestURI() ); + } + } + + public static class RepoServlet + extends HttpServlet + { + @Override + protected void doGet( HttpServletRequest req, HttpServletResponse resp ) + throws ServletException, IOException + { + File jar = new File( System.getProperty( "basedir" ), "src/test/junit-4.9.jar" ); + IOUtils.copy( new FileInputStream( jar ), resp.getOutputStream() ); + + } + } + + +} diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/DownloadMergedIndexTest.java b/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/DownloadMergedIndexTest.java new file mode 100644 index 000000000..118ff0dc8 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/test/java/org/apache/archiva/DownloadMergedIndexTest.java @@ -0,0 +1,183 @@ +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 org.apache.archiva.admin.model.beans.ManagedRepository; +import org.apache.archiva.admin.model.beans.ProxyConnector; +import org.apache.archiva.admin.model.beans.RemoteRepository; +import org.apache.archiva.admin.model.beans.RepositoryGroup; +import org.apache.archiva.maven2.model.Artifact; +import org.apache.archiva.rest.api.model.SearchRequest; +import org.apache.archiva.rest.api.services.ManagedRepositoriesService; +import org.apache.archiva.rest.api.services.ProxyConnectorService; +import org.apache.archiva.rest.api.services.RepositoriesService; +import org.apache.archiva.rest.api.services.RepositoryGroupService; +import org.apache.archiva.rest.api.services.SearchService; +import org.apache.commons.io.FileUtils; +import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants; +import org.apache.archiva.redback.rest.services.FakeCreateAdminService; +import org.junit.After; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.io.File; +import java.util.Arrays; +import java.util.List; +import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; + +/** + * @author Olivier Lamy + */ +@RunWith( ArchivaBlockJUnit4ClassRunner.class ) +public class DownloadMergedIndexTest + extends AbstractDownloadTest +{ + + @BeforeClass + public static void setAppServerBase() + { + previousAppServerBase = System.getProperty( "appserver.base" ); + System.setProperty( "appserver.base", "target/" + DownloadMergedIndexTest.class.getName() ); + } + + @AfterClass + public static void resetAppServerBase() + { + System.setProperty( "appserver.base", previousAppServerBase ); + } + + protected String getSpringConfigLocation() + { + return "classpath*:META-INF/spring-context.xml classpath*:spring-context-merge-index-download.xml"; + } + + @After + public void cleanup() + throws Exception + { + super.tearDown(); + File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" ); + if ( tmpIndexDir.exists() ) + { + FileUtils.deleteDirectory( tmpIndexDir ); + } + } + + + @Test + public void downloadMergedIndex() + throws Exception + { + File tmpIndexDir = new File( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" ); + if ( tmpIndexDir.exists() ) + { + FileUtils.deleteDirectory( tmpIndexDir ); + } + String id = Long.toString( System.currentTimeMillis() ); + ManagedRepository managedRepository = new ManagedRepository(); + managedRepository.setId( id ); + managedRepository.setName( "name of " + id ); + managedRepository.setLocation( "src/test/repositories/test-repo" ); + managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id ); + + ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(); + + if ( managedRepositoriesService.getManagedRepository( id ) != null ) + { + managedRepositoriesService.deleteManagedRepository( id, false ); + } + + getManagedRepositoriesService().addManagedRepository( managedRepository ); + + RepositoriesService repositoriesService = getRepositoriesService(); + + repositoriesService.scanRepositoryNow( id, true ); + + // wait a bit to ensure index is finished + int timeout = 20000; + while ( timeout > 0 && repositoriesService.alreadyScanning( id ) ) + { + Thread.sleep( 500 ); + timeout -= 500; + } + + RepositoryGroupService repositoryGroupService = getRepositoryGroupService(); + + RepositoryGroup repositoryGroup = new RepositoryGroup(); + repositoryGroup.setId( "test-group" ); + repositoryGroup.setRepositories( Arrays.asList( id ) ); + + repositoryGroupService.addRepositoryGroup( repositoryGroup ); + + // create a repo with a remote on the one with index + id = Long.toString( System.currentTimeMillis() ); + managedRepository = new ManagedRepository(); + managedRepository.setId( id ); + managedRepository.setName( "name of " + id ); + managedRepository.setLocation( "src/test/repositories/test-repo" ); + managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id ); + + if ( managedRepositoriesService.getManagedRepository( id ) != null ) + { + managedRepositoriesService.deleteManagedRepository( id, false ); + } + + getManagedRepositoriesService().addManagedRepository( managedRepository ); + + RemoteRepository remoteRepository = new RemoteRepository(); + remoteRepository.setId( "all-merged" ); + remoteRepository.setName( "all-merged" ); + remoteRepository.setDownloadRemoteIndex( true ); + remoteRepository.setUrl( "http://localhost:" + port + "/repository/test-group" ); + remoteRepository.setRemoteIndexUrl( "http://localhost:" + port + "/repository/test-group/.indexer" ); + remoteRepository.setUserName( RedbackRoleConstants.ADMINISTRATOR_ACCOUNT_NAME ); + remoteRepository.setPassword( FakeCreateAdminService.ADMIN_TEST_PWD ); + + getRemoteRepositoriesService().addRemoteRepository( remoteRepository ); + + ProxyConnectorService proxyConnectorService = getProxyConnectorService(); + ProxyConnector proxyConnector = new ProxyConnector(); + proxyConnector.setProxyId( "foo-bar" ); + proxyConnector.setSourceRepoId( id ); + proxyConnector.setTargetRepoId( "all-merged" ); + proxyConnectorService.addProxyConnector( proxyConnector ); + + repositoriesService.scheduleDownloadRemoteIndex( "all-merged", true, true ); + + // wait a bit + timeout = 20000; + while ( timeout > 0 ) + { + Thread.sleep( 500 ); + timeout -= 500; + } + + SearchService searchService = getSearchService(); + + SearchRequest request = new SearchRequest(); + request.setRepositories( Arrays.asList( id ) ); + request.setGroupId( "org.apache.felix" ); + + List<Artifact> artifacts = searchService.searchArtifacts( request ); + assertFalse( artifacts.isEmpty() ); + assertEquals( 1, artifacts.size() ); + } +} diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/test/resources/spring-context-artifacts-download.xml b/archiva-modules/archiva-web/archiva-webapp-js/src/test/resources/spring-context-artifacts-download.xml new file mode 100644 index 000000000..2ade48455 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/test/resources/spring-context-artifacts-download.xml @@ -0,0 +1,55 @@ +<?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.apache.archiva.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.archiva.base" + config-at="org.apache.archiva"/> + + <properties fileName="${appserver.base}/conf/security.properties" config-optional="true" + config-at="org.apache.archiva.redback"/> + <properties fileName="org/apache/archiva/security.properties" config-at="org.apache.archiva.redback"/> + </configuration> + ]]> + </value> + </property> + </bean> + <bean name="repositorySessionFactory" class="org.apache.archiva.webtest.memory.TestRepositorySessionFactory"/> + +</beans> diff --git a/archiva-modules/archiva-web/archiva-webapp-js/src/test/resources/spring-context-merge-index-download.xml b/archiva-modules/archiva-web/archiva-webapp-js/src/test/resources/spring-context-merge-index-download.xml new file mode 100644 index 000000000..16b37542d --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp-js/src/test/resources/spring-context-merge-index-download.xml @@ -0,0 +1,56 @@ +<?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.apache.archiva.redback.components.registry.commons.CommonsConfigurationRegistry"> + <property name="properties"> + <value> + <![CDATA[ + <configuration> + <system/> + + <xml fileName="${appserver.base}/conf/archiva-test-merge-index-download.xml" config-optional="true" + config-name="org.apache.archiva.base" + config-at="org.apache.archiva"/> + + <properties fileName="${appserver.base}/conf/security.properties" config-optional="true" + config-at="org.apache.archiva.redback"/> + <properties fileName="org/apache/archiva/security.properties" config-at="org.apache.archiva.redback"/> + </configuration> + ]]> + </value> + </property> + </bean> + + <bean name="repositorySessionFactory" class="org.apache.archiva.webtest.memory.TestRepositorySessionFactory"/> + +</beans> |