mirror of
https://github.com/apache/archiva.git
synced 2025-02-21 01:15:08 +00:00
Using repository copies in unit tests
This commit is contained in:
parent
9ebf8c8880
commit
34806cdf35
@ -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>
|
||||
|
@ -20,16 +20,21 @@
|
||||
|
||||
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 @@
|
||||
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) )
|
||||
|
@ -33,6 +33,7 @@
|
||||
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.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 void startServer()
|
||||
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 )
|
||||
|
@ -27,6 +27,7 @@
|
||||
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 @@ protected String createAndScanRepo()
|
||||
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();
|
||||
|
||||
|
@ -23,6 +23,7 @@
|
||||
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.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 @@ protected void doGet( HttpServletRequest req, HttpServletResponse resp )
|
||||
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() );
|
||||
|
||||
}
|
||||
|
@ -22,7 +22,6 @@
|
||||
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.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 void downloadMergedIndexWithNonDefaultPath()
|
||||
|
||||
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 )
|
||||
{
|
||||
|
@ -35,6 +35,7 @@
|
||||
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 void cleanup()
|
||||
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 void downloadMergedIndex()
|
||||
|
||||
// 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 )
|
||||
{
|
||||
|
@ -27,13 +27,16 @@
|
||||
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();
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
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.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 @@ protected String getSpringConfigLocation()
|
||||
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 );
|
||||
|
@ -47,6 +47,7 @@
|
||||
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 static void initConfigurationPath()
|
||||
{
|
||||
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 @@ protected String getSpringConfigLocation() {
|
||||
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 void clearUploadedFiles()
|
||||
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 void uploadFile() throws IOException, ArchivaRestServiceException {
|
||||
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 void failUploadFileWithBadFileName() throws IOException, ArchivaRestServi
|
||||
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 void uploadAndDeleteFile() throws IOException, ArchivaRestServiceExceptio
|
||||
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 void failUploadAndDeleteFileInOtherDir() throws IOException, ArchivaRestS
|
||||
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 void failUploadAndDeleteFileInOtherDir() throws IOException, ArchivaRestS
|
||||
|
||||
@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 void failSaveFileWithBadParams() throws IOException, ArchivaRestServiceEx
|
||||
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 void saveFile() throws IOException, ArchivaRestServiceException {
|
||||
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);
|
||||
|
@ -77,7 +77,7 @@ public static void initConfigurationPath()
|
||||
{
|
||||
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" );
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user