<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
+ <forkCount>2</forkCount>
<reuseForks>false</reuseForks>
<includes>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
</includes>
+ <workingDirectory>${project.build.directory}/WDIR-${surefire.forkNumber}</workingDirectory>
+ <trimStackTrace>false</trimStackTrace>
<!--
- <argLine>-Xms1024m -Xmx3072m -server -XX:MaxPermSize=256m @{jacocoproperty}</argLine>
+ The property jdk.net.URLClassPath.disableClassPathURLCheck is a workaround for a regression
+ with surefire and OpenJDK 8 181b13 on Debian/Ubuntu,
+ @see https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=911925
-->
- <argLine>-Xms1024m -Xmx3072m -server -XX:MaxPermSize=256m</argLine>
+ <argLine>-Xms256m -Xmx512m -server -Djdk.net.URLClassPath.disableClassPathURLCheck=true</argLine>
<systemPropertyVariables>
- <appserver.base>${project.build.directory}/appserver-base</appserver.base>
- <plexus.home>${project.build.directory}/appserver-base</plexus.home>
- <derby.system.home>${project.build.directory}/appserver-base</derby.system.home>
+ <mvn.project.base.dir>${project.basedir}</mvn.project.base.dir>
+ <appserver.base>${project.build.directory}/appserver-base-${surefire.forkNumber}</appserver.base>
+ <plexus.home>${project.build.directory}/appserver-base-${surefire.forkNumber}</plexus.home>
+ <derby.system.home>${project.build.directory}/appserver-base-${surefire.forkNumber}</derby.system.home>
<archiva.baseRestUrl>${archiva.baseRestUrl}</archiva.baseRestUrl>
<rest.admin.pwd>${rest.admin.pwd}</rest.admin.pwd>
<redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>
import org.apache.commons.lang.StringUtils;
import org.apache.cxf.jaxrs.client.JAXRSClientFactory;
import org.apache.cxf.jaxrs.client.WebClient;
+import org.junit.After;
import org.junit.Assume;
import org.junit.Before;
import org.junit.BeforeClass;
import java.util.Collections;
import java.util.Date;
import java.util.Locale;
+import java.util.concurrent.atomic.AtomicReference;
/**
* @author Olivier Lamy
public abstract class AbstractArchivaRestTest
extends AbstractRestServicesTest
{
+ private AtomicReference<Path> buildDir = new AtomicReference<>();
+ private boolean reuseServer = true;
+
+
+ protected void setReuseServer(boolean value) {
+ this.reuseServer = value;
+ }
+
+ protected boolean isReuseServer() {
+ return this.reuseServer;
+ }
+
+
// START SNIPPET: authz-header
// guest with an empty password
@BeforeClass
- public static void chekRepo()
+ public static void checkRepo()
{
Assume.assumeTrue( !System.getProperty( "appserver.base" ).contains( " " ) );
LoggerFactory.getLogger( AbstractArchivaRestTest.class.getName() ).
public void startServer()
throws Exception
{
- Path appServerBase = Paths.get( System.getProperty( "appserver.base" ) );
+ if ( (!isReuseServer()) || (isReuseServer() && !isServerRunning())) {
+ log.info("Starting new server reuse={}, running={}, instance={}, server={}", isReuseServer(), isServerRunning(), this.hashCode(), getServer()==null ? "" : getServer().hashCode());
+ Path appServerBase = Paths.get(System.getProperty("appserver.base"));
- removeAppsubFolder( appServerBase, "jcr" );
- removeAppsubFolder( appServerBase, "conf" );
- removeAppsubFolder( appServerBase, "data" );
+ removeAppsubFolder(appServerBase, "jcr");
+ removeAppsubFolder(appServerBase, "conf");
+ removeAppsubFolder(appServerBase, "data");
+ super.startServer();
+ } else {
+ log.info("Reusing running server instance reuse={}, running={}", isReuseServer(), isServerRunning());
+ }
+ }
- super.startServer();
+ @Override
+ @After
+ public void stopServer()
+ throws Exception
+ {
+ if ( !isReuseServer() )
+ {
+ log.info("Stopping server reuse={}, running={}, instance={}, server={}", isReuseServer(), isServerRunning(), this.hashCode(), getServer()==null ? "" : getServer().hashCode());
+ super.stopServer();
+ } else {
+ log.info("Server not stopping reuse={}, running={}", isReuseServer(), isServerRunning());
+ }
}
{
WebClient.client( service ).header( "Authorization", authzHeader );
}
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
WebClient.client( service ).header( "Authorization", authorizationHeader );
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
Collections.singletonList( new JacksonJaxbJsonProvider() ) );
WebClient.client( service ).header( "Authorization", authorizationHeader );
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).header( "Authorization", authorizationHeader );
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
return service;
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).header( "Authorization", authorizationHeader );
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 300000 );
return service;
}
WebClient.client( service ).header( "Authorization", authzHeader );
}
// Set the Referer header to your archiva server url
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
if ( useXml )
WebClient.client( service ).header( "Authorization", authzHeader );
}
// Set the Referer header to your archiva server url
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
// to configure read timeout
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
// if you want to use json as exchange format xml is supported too
{
WebClient.client( service ).header( "Authorization", authzHeader );
}
- WebClient.client(service).header("Referer","http://localhost:"+port);
+ WebClient.client(service).header("Referer","http://localhost:"+getServerPort());
WebClient.getConfig( service ).getHttpConduit().getClient().setReceiveTimeout( 100000000 );
WebClient.client( service ).accept( MediaType.APPLICATION_JSON_TYPE );
WebClient.client( service ).type( MediaType.APPLICATION_JSON_TYPE );
protected String getBaseUrl()
{
String baseUrlSysProps = System.getProperty( "archiva.baseRestUrl" );
- return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + port : baseUrlSysProps;
+ return StringUtils.isBlank( baseUrlSysProps ) ? "http://localhost:" + getServerPort() : baseUrlSysProps;
+ }
+
+ protected Path getBuildDirectory() {
+ if (buildDir.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();
+ }
+ buildDir.compareAndSet(null, newVal);
+ }
+ return buildDir.get();
}
//-----------------------------------------------------
org.apache.archiva.common.utils.FileUtils.deleteDirectory( originRepo );
}
assertFalse( Files.exists(originRepo) );
- FileUtils.copyDirectory( Paths.get( "src/test/repo-with-osgi" ).toAbsolutePath().toFile(), originRepo.toAbsolutePath().toFile() );
+ FileUtils.copyDirectory( getBuildDirectory().resolve("src/test/repo-with-osgi" ).toAbsolutePath().toFile(), originRepo.toAbsolutePath().toFile() );
if ( getManagedRepositoriesService( authorizationHeader ).getManagedRepository( SOURCE_REPO_ID ) != null )
{
{
+ private void removeRemoteRepositories(String... repos) {
+ try {
+ RemoteRepositoriesService service = getRemoteRepositoriesService();
+ WebClient.client( service ).header( "Authorization", authorizationHeader );
+ for (String repo : repos ) {
+ try {
+ service.deleteRemoteRepository(repo);
+ } catch (Throwable ex) {
+ log.warn("Could not remove repo {}", repo);
+ // ignore
+ }
+ }
+ } catch (Throwable ex) {
+ // ignore
+ }
+ }
+
@Test( expected = ForbiddenException.class )
public void listRemoteRepositoriesKarmaFailed()
throws Exception
@Test
public void checkRemoteConnectivity()
throws Exception {
- RemoteRepositoriesService service = getRemoteRepositoriesService();
+ try {
+ RemoteRepositoriesService service = getRemoteRepositoriesService();
- WebClient.client(service).header("Authorization", authorizationHeader);
+ WebClient.client(service).header("Authorization", authorizationHeader);
- int initialSize = service.getRemoteRepositories().size();
+ int initialSize = service.getRemoteRepositories().size();
- service.addRemoteRepository(getRemoteRepository());
+ service.addRemoteRepository(getRemoteRepository());
- assertTrue(service.checkRemoteConnectivity("id-new"));
+ assertTrue(service.checkRemoteConnectivity("id-new"));
+ } finally {
+ removeRemoteRepositories("id-new");
+ }
}
@Test
public void checkRemoteConnectivity2()
throws Exception {
- RemoteRepositoriesService service = getRemoteRepositoriesService();
+ try {
+ RemoteRepositoriesService service = getRemoteRepositoriesService();
- WebClient.client(service).header("Authorization", authorizationHeader);
+ WebClient.client(service).header("Authorization", authorizationHeader);
- int initialSize = service.getRemoteRepositories().size();
+ int initialSize = service.getRemoteRepositories().size();
- service.addRemoteRepository(getRemoteMavenRepository());
+ service.addRemoteRepository(getRemoteMavenRepository());
- assertTrue(service.checkRemoteConnectivity("id-maven1"));
+ assertTrue(service.checkRemoteConnectivity("id-maven1"));
+ } finally {
+ removeRemoteRepositories("id-maven1");
+ }
}
@Test
public void checkRemoteConnectivity3()
throws Exception {
- RemoteRepositoriesService service = getRemoteRepositoriesService();
+ try {
+ RemoteRepositoriesService service = getRemoteRepositoriesService();
- WebClient.client(service).header("Authorization", authorizationHeader);
- WebClient.client(service).accept("application/json");
+ WebClient.client(service).header("Authorization", authorizationHeader);
+ WebClient.client(service).accept("application/json");
- int initialSize = service.getRemoteRepositories().size();
+ int initialSize = service.getRemoteRepositories().size();
- service.addRemoteRepository(getRemoteOracleRepository());
+ service.addRemoteRepository(getRemoteOracleRepository());
- assertTrue(service.checkRemoteConnectivity("id-oracle"));
+ assertTrue(service.checkRemoteConnectivity("id-oracle"));
+ } finally {
+ removeRemoteRepositories("id-oracle");
+ }
}