diff options
author | Martin Stockhammer <martin_s@apache.org> | 2019-08-03 20:34:28 +0200 |
---|---|---|
committer | Martin Stockhammer <martin_s@apache.org> | 2019-08-03 20:34:28 +0200 |
commit | 34806cdf355267100c8a59c2be245e53805e0225 (patch) | |
tree | f83038906d660871b3a7c02e6d902c212a43cf32 /archiva-modules | |
parent | 9ebf8c88809bbe9c689a0a4ac5628f92f49f152e (diff) | |
download | archiva-34806cdf355267100c8a59c2be245e53805e0225.tar.gz archiva-34806cdf355267100c8a59c2be245e53805e0225.zip |
Using repository copies in unit tests
Diffstat (limited to 'archiva-modules')
11 files changed, 302 insertions, 77 deletions
diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/resources/archiva-test.xml b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/resources/archiva-test.xml index 04a67f124..7e451cce2 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/resources/archiva-test.xml +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-repository/src/test/resources/archiva-test.xml @@ -24,7 +24,7 @@ <managedRepository> <id>testRepo</id> <name>Archiva Test Repository</name> - <location>${basedir}/src/test/repositories/default-repository</location> + <location>${basedir}/target/default-repository</location> <layout>default</layout> <releases>true</releases> <snapshots>false</snapshots> diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/RuntimeInfoServiceTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/RuntimeInfoServiceTest.java index 2c0874346..1ffae7e58 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/RuntimeInfoServiceTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/RuntimeInfoServiceTest.java @@ -20,16 +20,21 @@ package org.apache.archiva; import com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider; import org.apache.archiva.redback.rest.services.AbstractRestServicesTest; +import org.apache.archiva.remotedownload.DownloadArtifactsTest; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.apache.archiva.web.api.RuntimeInfoService; import org.apache.archiva.web.model.ApplicationRuntimeInfo; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; +import org.junit.AfterClass; import org.junit.Before; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -42,13 +47,33 @@ import java.util.Collections; public class RuntimeInfoServiceTest extends AbstractRestServicesTest { + + private static Path appServerBase; + private static String previousAppServerBase; + + @BeforeClass + public static void setAppServerBase() + throws IOException + { + previousAppServerBase = System.getProperty( "appserver.base" ); + appServerBase = Files.createTempDirectory( "archiva-common-web_appsrvrt_" ); + System.setProperty( "appserver.base", appServerBase.toString( ) ); + } + + @AfterClass + public static void resetAppServerBase() + { + if (Files.exists(appServerBase)) { + FileUtils.deleteQuietly( appServerBase.toFile() ); + } + System.setProperty( "appserver.base", previousAppServerBase ); + } + @Override @Before public void startServer() throws Exception { - Path appServerBase = Paths.get( System.getProperty( "appserver.base" ) ); - Path jcrDirectory = appServerBase.resolve( "jcr" ); if ( Files.exists(jcrDirectory) ) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/AbstractDownloadTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/AbstractDownloadTest.java index cf69545b1..78a9723ec 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/AbstractDownloadTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/AbstractDownloadTest.java @@ -33,6 +33,7 @@ import org.apache.archiva.rest.api.services.RepositoryGroupService; import org.apache.archiva.rest.api.services.SearchService; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.apache.archiva.webdav.RepositoryServlet; +import org.apache.commons.io.FileUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.SystemUtils; import org.apache.cxf.common.util.Base64Utility; @@ -52,10 +53,14 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.context.ContextLoaderListener; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -67,6 +72,11 @@ public abstract class AbstractDownloadTest extends TestCase { + AtomicReference<Path> projectDir = new AtomicReference<>( ); + AtomicReference<Path> basePath = new AtomicReference<>( ); + + protected List<Path> createdPaths = new ArrayList<>( ); + protected final Logger log = LoggerFactory.getLogger( getClass() ); protected static String previousAppServerBase; @@ -79,6 +89,37 @@ public abstract class AbstractDownloadTest public int port; + protected Path getProjectDirectory() { + if ( projectDir.get()==null) { + String propVal = System.getProperty("mvn.project.base.dir"); + Path newVal; + if (StringUtils.isEmpty(propVal)) { + newVal = Paths.get("").toAbsolutePath(); + } else { + newVal = Paths.get(propVal).toAbsolutePath(); + } + projectDir.compareAndSet(null, newVal); + } + return projectDir.get(); + } + + public Path getBasedir() + { + if (basePath.get()==null) { + String baseDir = System.getProperty( "basedir" ); + final Path baseDirPath; + if (StringUtils.isNotEmpty( baseDir )) { + baseDirPath = Paths.get( baseDir ); + } else { + baseDirPath = getProjectDirectory( ); + } + basePath.compareAndSet( null, baseDirPath ); + } + return basePath.get( ); + } + + + public static String encode( String uid, String password ) { return "Basic " + Base64Utility.encode( ( uid + ":" + password ).getBytes() ); @@ -148,6 +189,14 @@ public abstract class AbstractDownloadTest public void tearDown() throws Exception { + + for(Path dir : createdPaths) { + if ( Files.exists( dir)) { + FileUtils.deleteQuietly( dir.toFile( ) ); + } + } + createdPaths.clear(); + System.clearProperty( "redback.admin.creation.file" ); super.tearDown(); if ( this.server != null ) diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java index b377f6169..b13e24722 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactFromQueryTest.java @@ -27,6 +27,7 @@ import org.assertj.core.api.Assertions; import org.junit.After; import org.junit.AfterClass; import org.junit.Assert; +import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -48,37 +49,49 @@ public class DownloadArtifactFromQueryTest extends AbstractDownloadTest { + private static Path appServerBase; + + private Path indexDir; + @BeforeClass public static void setAppServerBase() throws IOException { previousAppServerBase = System.getProperty( "appserver.base" ); - System.setProperty( "appserver.base", - Paths.get( System.getProperty( "java.io.tmpdir" ) ).toAbsolutePath().resolve("target") - .resolve(DownloadArtifactFromQueryTest.class.getName() ).toString()); + appServerBase = Files.createTempDirectory( "archiva-common-web_appsrv1_" ).toAbsolutePath(); + System.setProperty( "appserver.base", appServerBase.toString( ) ); } @AfterClass public static void resetAppServerBase() { + if (Files.exists(appServerBase)) { + FileUtils.deleteQuietly( appServerBase.toFile() ); + } System.setProperty( "appserver.base", previousAppServerBase ); } @Override protected String getSpringConfigLocation() { + System.out.println( "Appserver base: " + System.getProperty( "appserver.base" ) ); return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-merge-index-download.xml"; } + @Before + public void init() throws IOException + { + indexDir = Files.createTempDirectory( "archiva-web-common-index" ); + } + @After public void cleanup() throws Exception { super.tearDown(); - Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ), "tmpIndex" ); - if ( Files.exists( tmpIndexDir ) ) + if ( Files.exists( indexDir ) ) { - FileUtils.deleteDirectory( tmpIndexDir.toFile() ); + FileUtils.deleteDirectory( indexDir.toFile() ); } } @@ -87,17 +100,19 @@ public class DownloadArtifactFromQueryTest throws Exception { - Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ), "tmpIndex" ); - if ( Files.exists( tmpIndexDir ) ) - { - FileUtils.deleteDirectory( tmpIndexDir.toFile() ); - } String id = Long.toString( System.currentTimeMillis() ); + Path srcRep = getProjectDirectory( ).resolve( "src/test/repositories/test-repo" ); + Path testRep = getBasedir( ).resolve( "target" ).resolve( "test-repo-" + id ).toAbsolutePath(); + FileUtils.copyDirectory( srcRep.toFile( ), testRep.toFile( ) ); + createdPaths.add( testRep ); + + ManagedRepository managedRepository = new ManagedRepository( Locale.getDefault()); managedRepository.setId( id ); managedRepository.setName( "name of " + id ); - managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ); - managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id ); + managedRepository.setLocation( testRep.toString() ); + managedRepository.setIndexDirectory( indexDir.resolve( "index-"+id ).toString()); + managedRepository.setPackedIndexDirectory( indexDir.resolve( "indexpacked-"+id ).toString()); ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java index db2a713a2..fad595a45 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadArtifactsTest.java @@ -23,6 +23,7 @@ import org.apache.archiva.redback.rest.api.services.RoleManagementService; import org.apache.archiva.security.common.ArchivaRoleConstants; import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.apache.commons.io.FileUtils; +import org.apache.commons.lang.StringUtils; import org.apache.maven.wagon.providers.http.HttpWagon; import org.apache.maven.wagon.repository.Repository; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -49,6 +50,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import java.util.concurrent.atomic.AtomicReference; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -70,23 +72,31 @@ public class DownloadArtifactsTest public int repoServerPort; + private static Path appServerBase; + @BeforeClass public static void setAppServerBase() + throws IOException { + System.out.println( "Setting appserver base" ); previousAppServerBase = System.getProperty( "appserver.base" ); - System.setProperty( "appserver.base", "target/" + DownloadArtifactsTest.class.getName() ); + appServerBase = Files.createTempDirectory( "archiva-common-web_appsrv2_" ).toAbsolutePath( ); + System.setProperty( "appserver.base", appServerBase.toString( ) ); } - @AfterClass public static void resetAppServerBase() { + if (Files.exists(appServerBase)) { + FileUtils.deleteQuietly( appServerBase.toFile() ); + } System.setProperty( "appserver.base", previousAppServerBase ); } @Override protected String getSpringConfigLocation() { + System.out.println( "AppserverBase: " + System.getProperty( "appserver.base" ) ); return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml"; } @@ -212,11 +222,28 @@ public class DownloadArtifactsTest public static class RepoServlet extends HttpServlet { + + private AtomicReference<Path> projectDir = new AtomicReference<>( ); + + protected Path getProjectDirectory() { + if ( projectDir.get()==null) { + String propVal = System.getProperty("mvn.project.base.dir"); + Path newVal; + if ( StringUtils.isEmpty(propVal)) { + newVal = Paths.get("").toAbsolutePath(); + } else { + newVal = Paths.get(propVal).toAbsolutePath(); + } + projectDir.compareAndSet(null, newVal); + } + return projectDir.get(); + } + @Override protected void doGet( HttpServletRequest req, HttpServletResponse resp ) throws ServletException, IOException { - Path jar = Paths.get( System.getProperty( "basedir" ), "src/test/junit-4.9.jar" ); + Path jar = getProjectDirectory().resolve( "src/test/junit-4.9.jar" ); Files.copy( jar, resp.getOutputStream() ); } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexNonDefaultPathTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexNonDefaultPathTest.java index b64f128ef..ebe5f9f49 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexNonDefaultPathTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexNonDefaultPathTest.java @@ -22,7 +22,6 @@ 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.common.utils.FileUtils; import org.apache.archiva.maven2.model.Artifact; import org.apache.archiva.redback.integration.security.role.RedbackRoleConstants; import org.apache.archiva.redback.rest.services.FakeCreateAdminService; @@ -33,15 +32,21 @@ 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.test.utils.ArchivaBlockJUnit4ClassRunner; +import org.apache.commons.io.FileUtils; 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 java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import java.time.LocalDateTime; +import java.time.LocalTime; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Locale; @@ -56,56 +61,74 @@ public class DownloadMergedIndexNonDefaultPathTest extends AbstractDownloadTest { + private static Path appServerBase; + private Path indexDir; + + @BeforeClass public static void setAppServerBase() + throws IOException { previousAppServerBase = System.getProperty( "appserver.base" ); - System.setProperty( "appserver.base", System.getProperty( "basedir" ) + "/target/" + DownloadMergedIndexNonDefaultPathTest.class.getName() ); + appServerBase = Files.createTempDirectory( "archiva-common-web_appsrv3_" ).toAbsolutePath(); + System.setProperty( "appserver.base", appServerBase.toString( ) ); } @AfterClass public static void resetAppServerBase() { + if (Files.exists(appServerBase)) { + org.apache.commons.io.FileUtils.deleteQuietly( appServerBase.toFile() ); + } System.setProperty( "appserver.base", previousAppServerBase ); } @Override protected String getSpringConfigLocation() { + System.out.println( "AppserverBase: " + System.getProperty( "appserver.base" ) ); return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-merge-index-download.xml"; } + @Before + public void init() throws IOException + { + indexDir = Files.createTempDirectory( "archiva-web-common-index" ); + } + @After public void cleanup() throws Exception { super.tearDown(); - Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ), "tmpIndex" ); - if ( Files.exists(tmpIndexDir) ) + if ( Files.exists( indexDir ) ) { - org.apache.archiva.common.utils.FileUtils.deleteDirectory( tmpIndexDir ); + org.apache.commons.io.FileUtils.deleteDirectory( indexDir.toFile() ); } } - @Test public void downloadMergedIndexWithNonDefaultPath() throws Exception { - Path indexBaseDir = Paths.get(System.getProperty( "java.io.tmpdir" )).resolve("archiva").resolve("remotedownloadtest"); - String indexBase = indexBaseDir.toString(); - FileUtils.deleteQuietly( indexBaseDir); + Path indexBaseDir = indexDir.resolve("remotedownloadtest"); if (!Files.exists(indexBaseDir)) { Files.createDirectories( indexBaseDir ); } String id = Long.toString( System.currentTimeMillis() ); + Path srcRep = getProjectDirectory( ).resolve( "src/test/repositories/test-repo" ); + Path testRep = getBasedir( ).resolve( "target" ).resolve( "test-repo-" + id ).toAbsolutePath(); + FileUtils.copyDirectory( srcRep.toFile( ), testRep.toFile( ) ); + createdPaths.add( testRep ); + ManagedRepository managedRepository = new ManagedRepository( Locale.getDefault()); managedRepository.setId( id ); managedRepository.setName( "name of " + id ); - managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ); - managedRepository.setIndexDirectory( indexBase + "/index-" + id ); - managedRepository.setPackedIndexDirectory( indexBase + "/indexPacked-" + id ); + managedRepository.setLocation( testRep.toString() ); + managedRepository.setIndexDirectory( indexBaseDir.resolve( "index-" + id ).toString() ); + managedRepository.setPackedIndexDirectory( indexBaseDir.resolve( "indexPacked-" + id ).toString() ); + ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(); @@ -145,14 +168,21 @@ public class DownloadMergedIndexNonDefaultPathTest repositoryGroupService.addRepositoryGroup( repositoryGroup ); + + // create a repo with a remote on the one with index id = Long.toString( System.currentTimeMillis() ); + Path srcRep2 = getProjectDirectory( ).resolve( "src/test/repositories/test-repo" ); + Path testRep2 = getBasedir( ).resolve( "target" ).resolve( "test-repo-" + id ).toAbsolutePath(); + FileUtils.copyDirectory( srcRep2.toFile( ), testRep2.toFile( ) ); + createdPaths.add( testRep2 ); + managedRepository = new ManagedRepository(Locale.getDefault()); managedRepository.setId( id ); managedRepository.setName( "name of " + id ); - managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ); - managedRepository.setIndexDirectory( indexBaseDir + "/index-"+ id ); - managedRepository.setPackedIndexDirectory( indexBase + "/tmpIndexPacked-" + id ); + managedRepository.setLocation( testRep2.toString() ); + managedRepository.setIndexDirectory( indexBaseDir.resolve( "index-" + id ).toString() ); + managedRepository.setPackedIndexDirectory( indexBaseDir.resolve( "indexpacked-" + id ).toString() ); if ( managedRepositoriesService.getManagedRepository( id ) != null ) { diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexTest.java index 7bb4bb173..5e27eeb14 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadMergedIndexTest.java @@ -35,6 +35,7 @@ import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.apache.commons.io.FileUtils; 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; @@ -57,38 +58,48 @@ public class DownloadMergedIndexTest extends AbstractDownloadTest { + private static Path appServerBase; + private Path indexDir; + @BeforeClass public static void setAppServerBase() throws IOException { previousAppServerBase = System.getProperty( "appserver.base" ); - System.setProperty( "appserver.base", - Paths.get(System.getProperty( "java.io.tmpdir" ) ).toAbsolutePath().resolve( "target").resolve( - DownloadMergedIndexTest.class.getName()).toString() - ); + appServerBase = Files.createTempDirectory( "archiva-common-web_appsrv4_" ).toAbsolutePath(); + System.setProperty( "appserver.base", appServerBase.toString( ) ); } @AfterClass public static void resetAppServerBase() { + if (Files.exists(appServerBase)) { + FileUtils.deleteQuietly( appServerBase.toFile() ); + } System.setProperty( "appserver.base", previousAppServerBase ); } @Override protected String getSpringConfigLocation() { + System.out.println( "AppserverBase: " + System.getProperty( "appserver.base" ) ); return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-merge-index-download.xml"; } + @Before + public void init() throws IOException + { + indexDir = Files.createTempDirectory( "archiva-web-common-index" ); + } + @After public void cleanup() throws Exception { super.tearDown(); - Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" ); - if ( Files.exists(tmpIndexDir) ) + if ( Files.exists( indexDir ) ) { - org.apache.archiva.common.utils.FileUtils.deleteDirectory( tmpIndexDir ); + FileUtils.deleteDirectory( indexDir.toFile() ); } } @@ -97,17 +108,18 @@ public class DownloadMergedIndexTest public void downloadMergedIndex() throws Exception { - Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ), "tmpIndex" ); - if ( Files.exists( tmpIndexDir ) ) - { - FileUtils.deleteDirectory( tmpIndexDir.toFile() ); - } String id = Long.toString( System.currentTimeMillis() ); + Path srcRep = getProjectDirectory( ).resolve( "src/test/repositories/test-repo" ); + Path testRep = getBasedir( ).resolve( "target" ).resolve( "test-repo-" + id ).toAbsolutePath(); + FileUtils.copyDirectory( srcRep.toFile( ), testRep.toFile( ) ); + createdPaths.add( testRep ); + + ManagedRepository managedRepository = new ManagedRepository( Locale.getDefault()); managedRepository.setId( id ); managedRepository.setName( "name of " + id ); - managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ); - managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id ); + managedRepository.setLocation( testRep.toString() ); + managedRepository.setIndexDirectory( indexDir.resolve( "index-" + id ).toString() ); ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(); @@ -147,11 +159,17 @@ public class DownloadMergedIndexTest // create a repo with a remote on the one with index id = Long.toString( System.currentTimeMillis() ); + + Path srcRep2 = getProjectDirectory( ).resolve( "src/test/repositories/test-repo" ); + Path testRep2 = getBasedir( ).resolve( "target" ).resolve( "test-repo-" + id ).toAbsolutePath(); + FileUtils.copyDirectory( srcRep2.toFile( ), testRep2.toFile( ) ); + createdPaths.add( testRep2 ); + managedRepository = new ManagedRepository(Locale.getDefault()); managedRepository.setId( id ); managedRepository.setName( "name of " + id ); - managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/test-repo" ); - managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id ); + managedRepository.setLocation( testRep2.toString() ); + managedRepository.setIndexDirectory( indexDir.resolve( "index-" + id ).toString() ); if ( managedRepositoriesService.getManagedRepository( id ) != null ) { diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadSnapshotTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadSnapshotTest.java index eeacbf989..05a29966c 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadSnapshotTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/DownloadSnapshotTest.java @@ -27,13 +27,16 @@ import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner; import org.apache.commons.io.FileUtils; import org.apache.maven.wagon.providers.http.HttpWagon; import org.apache.maven.wagon.repository.Repository; +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 java.io.IOException; import java.nio.charset.Charset; import java.nio.file.Files; import java.nio.file.Path; @@ -52,43 +55,69 @@ public class DownloadSnapshotTest { protected Logger log = LoggerFactory.getLogger( getClass() ); + private static Path appServerBase; + private Path indexDir; + @BeforeClass public static void setAppServerBase() + throws IOException { previousAppServerBase = System.getProperty( "appserver.base" ); - System.setProperty( "appserver.base", "target/" + DownloadSnapshotTest.class.getName() ); + appServerBase = Files.createTempDirectory( "archiva-common-web_appsrv5_" ).toAbsolutePath(); + System.setProperty( "appserver.base", appServerBase.toString( ) ); } - @AfterClass public static void resetAppServerBase() { + if (Files.exists(appServerBase)) { + FileUtils.deleteQuietly( appServerBase.toFile() ); + } System.setProperty( "appserver.base", previousAppServerBase ); } @Override protected String getSpringConfigLocation() { + System.out.println( "AppserverBase: " + System.getProperty( "appserver.base" ) ); return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml"; } + @Before + public void init() throws IOException + { + indexDir = Files.createTempDirectory( "archiva-web-common-index" ); + } + + @After + public void cleanup() + throws Exception + { + super.tearDown(); + if ( Files.exists( indexDir ) ) + { + FileUtils.deleteDirectory( indexDir.toFile() ); + } + } + @Test public void downloadSNAPSHOT() throws Exception { - Path tmpIndexDir = Paths.get( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex" ); - if ( Files.exists(tmpIndexDir) ) - { - org.apache.archiva.common.utils.FileUtils.deleteDirectory( tmpIndexDir ); - } String id = Long.toString( System.currentTimeMillis() ); + Path srcRep = getProjectDirectory( ).resolve( "src/test/repositories/snapshot-repo" ); + Path testRep = getBasedir( ).resolve( "target" ).resolve( "snapshot-repo-" + id ).toAbsolutePath(); + FileUtils.copyDirectory( srcRep.toFile( ), testRep.toFile( ) ); + createdPaths.add( testRep ); + ManagedRepository managedRepository = new ManagedRepository( Locale.getDefault()); managedRepository.setId( id ); managedRepository.setName( "name of " + id ); - managedRepository.setLocation( System.getProperty( "basedir" ) + "/src/test/repositories/snapshot-repo" ); - managedRepository.setIndexDirectory( System.getProperty( "java.io.tmpdir" ) + "/tmpIndex/" + id ); + managedRepository.setLocation( testRep.toString() ); + managedRepository.setIndexDirectory( indexDir.resolve( "index-" + id ).toString() ); + managedRepository.setPackedIndexDirectory( indexDir.resolve( "indexpacked-" + id ).toString() ); ManagedRepositoriesService managedRepositoriesService = getManagedRepositoriesService(); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/RemoteRepositoryConnectivityCheckTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/RemoteRepositoryConnectivityCheckTest.java index e9d156c2e..435f51de5 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/RemoteRepositoryConnectivityCheckTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/remotedownload/RemoteRepositoryConnectivityCheckTest.java @@ -21,6 +21,7 @@ package org.apache.archiva.remotedownload; import org.apache.archiva.admin.model.beans.RemoteRepository; import org.apache.archiva.rest.api.services.RemoteRepositoriesService; +import org.apache.commons.io.FileUtils; import org.apache.cxf.jaxrs.client.WebClient; import org.eclipse.jetty.server.Handler; import org.eclipse.jetty.server.HttpConnectionFactory; @@ -33,6 +34,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; +import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; @@ -47,23 +49,30 @@ public class RemoteRepositoryConnectivityCheckTest extends AbstractDownloadTest { + private static Path appServerBase; + @BeforeClass public static void setAppServerBase() + throws IOException { previousAppServerBase = System.getProperty( "appserver.base" ); - System.setProperty( "appserver.base", "target/" + RemoteRepositoryConnectivityCheckTest.class.getName() ); + appServerBase = Files.createTempDirectory( "archiva-common-web_appsrv6_" ).toAbsolutePath( ); + System.setProperty( "appserver.base", appServerBase.toString( ) ); } - @AfterClass public static void resetAppServerBase() { + if (Files.exists(appServerBase)) { + FileUtils.deleteQuietly( appServerBase.toFile() ); + } System.setProperty( "appserver.base", previousAppServerBase ); } @Override protected String getSpringConfigLocation() { + System.out.println( "AppserverBase: " + System.getProperty( "appserver.base" ) ); return "classpath*:META-INF/spring-context.xml classpath*:spring-context-test-common.xml classpath*:spring-context-artifacts-download.xml"; } @@ -71,9 +80,16 @@ public class RemoteRepositoryConnectivityCheckTest public void checkRemoteConnectivity() throws Exception { + String id = Long.toString( System.currentTimeMillis() ); + + Path srcRep = getProjectDirectory( ).resolve( "src/test/repositories/test-repo" ); + Path testRep = getBasedir( ).resolve( "target" ).resolve( "test-repo-" + id ).toAbsolutePath(); + FileUtils.copyDirectory( srcRep.toFile( ), testRep.toFile( ) ); + createdPaths.add( testRep ); + Server repoServer = - buildStaticServer( Paths.get( System.getProperty( "basedir" ), "src/test/repositories/test-repo" ) ); + buildStaticServer( testRep ); ServerConnector serverConnector = new ServerConnector( repoServer, new HttpConnectionFactory()); repoServer.addConnector( serverConnector ); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java index e501d1cdf..ca147bbf9 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/upload/UploadArtifactsTest.java @@ -47,6 +47,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.Collections; +import java.util.concurrent.atomic.AtomicReference; /** * @author Olivier Lamy @@ -56,6 +57,7 @@ public class UploadArtifactsTest extends AbstractRestServicesTest { private static String PREVIOUS_ARCHIVA_PATH; + private AtomicReference<Path> projectDir = new AtomicReference<>( ); @BeforeClass public static void initConfigurationPath() @@ -63,7 +65,7 @@ public class UploadArtifactsTest { PREVIOUS_ARCHIVA_PATH = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY); System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, - System.getProperty( "test.resources.path/" ) + "archiva.xml" ); + System.getProperty( "test.resources.path" ) + "/archiva.xml" ); } @@ -78,6 +80,20 @@ public class UploadArtifactsTest return "classpath*:META-INF/spring-context.xml,classpath:/spring-context-test-upload.xml"; } + protected Path getProjectDirectory() { + if ( projectDir.get()==null) { + String propVal = System.getProperty("mvn.project.base.dir"); + Path newVal; + if (StringUtils.isEmpty(propVal)) { + newVal = Paths.get("").toAbsolutePath(); + } else { + newVal = Paths.get(propVal).toAbsolutePath(); + } + projectDir.compareAndSet(null, newVal); + } + return projectDir.get(); + } + @Override protected String getRestServicesPath() { return "restServices"; @@ -119,7 +135,7 @@ public class UploadArtifactsTest public void uploadFile() throws IOException, ArchivaRestServiceException { FileUploadService service = getUploadService(); try { - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); final Attachment fileAttachment = new AttachmentBuilder().object(Files.newInputStream(file)).contentDisposition(new ContentDisposition("form-data; filename=\"" + file.getFileName().toString() + "\"; name=\"files[]\"")).build(); MultipartBody body = new MultipartBody(fileAttachment); service.post(body); @@ -132,7 +148,7 @@ public class UploadArtifactsTest public void failUploadFileWithBadFileName() throws IOException, ArchivaRestServiceException { FileUploadService service = getUploadService(); try { - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); final Attachment fileAttachment = new AttachmentBuilder().object(Files.newInputStream(file)).contentDisposition(new ContentDisposition("form-data; filename=\"/../TestFile.testext\"; name=\"files[]\"")).build(); MultipartBody body = new MultipartBody(fileAttachment); try { @@ -150,7 +166,7 @@ public class UploadArtifactsTest public void uploadAndDeleteFile() throws IOException, ArchivaRestServiceException { FileUploadService service = getUploadService(); try { - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); final Attachment fileAttachment = new AttachmentBuilder().object(Files.newInputStream(file)).contentDisposition(new ContentDisposition("form-data; filename=\"" + file.getFileName().toString() + "\"; name=\"files[]\"")).build(); MultipartBody body = new MultipartBody(fileAttachment); service.post(body); @@ -164,7 +180,7 @@ public class UploadArtifactsTest public void failUploadAndDeleteWrongFile() throws IOException, ArchivaRestServiceException { FileUploadService service = getUploadService(); try { - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); final Attachment fileAttachment = new AttachmentBuilder().object(Files.newInputStream(file)).contentDisposition(new ContentDisposition("form-data; filename=\"" + file.getFileName().toString() + "\"; name=\"files[]\"")).build(); MultipartBody body = new MultipartBody(fileAttachment); service.post(body); @@ -179,7 +195,7 @@ public class UploadArtifactsTest Path testFile = null; try { FileUploadService service = getUploadService(); - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); Path targetDir = Paths.get("target/testDelete").toAbsolutePath(); if (!Files.exists(targetDir)) Files.createDirectories(targetDir); Path tempDir = SystemUtils.getJavaIoTmpDir().toPath(); @@ -208,10 +224,10 @@ public class UploadArtifactsTest @Test public void failSaveFileWithBadParams() throws IOException, ArchivaRestServiceException { - Path path = Paths.get("target/appserver-base/repositories/internal/data/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.jar"); + Path path = Paths.get("target/appserver-base/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.jar"); Files.deleteIfExists(path); FileUploadService service = getUploadService(); - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); Attachment fileAttachment = new AttachmentBuilder().object(Files.newInputStream(file)).contentDisposition(new ContentDisposition("form-data; filename=\"archiva-model.jar\"; name=\"files[]\"")).build(); MultipartBody body = new MultipartBody(fileAttachment); @@ -235,14 +251,14 @@ public class UploadArtifactsTest public void saveFile() throws IOException, ArchivaRestServiceException { log.debug("Starting saveFile()"); - Path path = Paths.get("target/appserver-base/repositories/internal/data/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.jar"); + Path path = Paths.get("target/appserver-base/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.jar"); log.debug("Jar exists: {}",Files.exists(path)); Files.deleteIfExists(path); - path = Paths.get("target/appserver-base/repositories/internal/data/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.pom"); + path = Paths.get("target/appserver-base/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.pom"); Files.deleteIfExists(path); FileUploadService service = getUploadService(); service.clearUploadedFiles(); - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); log.debug("Upload file exists: {}", Files.exists(file)); final Attachment fileAttachment = new AttachmentBuilder().object(Files.newInputStream(file)).contentDisposition(new ContentDisposition("form-data; filename=\"archiva-model.jar\"; name=\"files[]\"")).build(); MultipartBody body = new MultipartBody(fileAttachment); @@ -254,14 +270,14 @@ public class UploadArtifactsTest public void saveFileWithOtherExtension() throws IOException, ArchivaRestServiceException { log.debug("Starting saveFileWithOtherExtension()"); - Path path = Paths.get("target/appserver-base/repositories/internal/data/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.bin"); + Path path = Paths.get("target/appserver-base/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.bin"); log.debug("Jar exists: {}",Files.exists(path)); Files.deleteIfExists(path); - Path pomPath = Paths.get("target/appserver-base/repositories/internal/data/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.pom"); + Path pomPath = Paths.get("target/appserver-base/repositories/internal/org/apache/archiva/archiva-model/1.2/archiva-model-1.2.pom"); Files.deleteIfExists(pomPath); FileUploadService service = getUploadService(); service.clearUploadedFiles(); - Path file = Paths.get("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); + Path file = getProjectDirectory().resolve("src/test/repositories/snapshot-repo/org/apache/archiva/archiva-model/1.4-M4-SNAPSHOT/archiva-model-1.4-M4-20130425.081822-1.jar"); log.debug("Upload file exists: {}", Files.exists(file)); final Attachment fileAttachment = new AttachmentBuilder().object(Files.newInputStream(file)).contentDisposition(new ContentDisposition("form-data; filename=\"archiva-model.bin\"; name=\"files[]\"")).build(); MultipartBody body = new MultipartBody(fileAttachment); diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java index 850b0a81d..e20632bb6 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/web/rss/RssFeedServletTest.java @@ -77,7 +77,7 @@ public class RssFeedServletTest { PREVIOUS_ARCHIVA_PATH = System.getProperty(ArchivaConfiguration.USER_CONFIG_PROPERTY); System.setProperty( ArchivaConfiguration.USER_CONFIG_PROPERTY, - System.getProperty( "test.resources.path/" ) + "empty-archiva.xml" ); + System.getProperty( "test.resources.path" ) + "/empty-archiva.xml" ); } |