diff --git a/pom.xml b/pom.xml index 381146e8..38c85461 100644 --- a/pom.xml +++ b/pom.xml @@ -94,6 +94,7 @@ 0.11.2 + true @@ -428,6 +429,14 @@ test + + org.eclipse.jetty + jetty-bom + ${jetty.version} + pom + import + + org.mockito mockito-core @@ -966,7 +975,7 @@ -Xmx256m -Xms256m alphabetical - true + ${surefire.redirectTestOutputToFile} diff --git a/redback-integrations/redback-rest/redback-rest-services/pom.xml b/redback-integrations/redback-rest/redback-rest-services/pom.xml index 0bd1ace6..099fda7d 100644 --- a/redback-integrations/redback-rest/redback-rest-services/pom.xml +++ b/redback-integrations/redback-rest/redback-rest-services/pom.xml @@ -284,18 +284,16 @@ org.eclipse.jetty jetty-server - ${jetty.version} jakarta.servlet - jakarta.servlet-api + jakarta.servlet-api org.eclipse.jetty jetty-servlet - ${jetty.version} diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java index 839f8e79..828052c7 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/AbstractRestServicesTest.java @@ -30,13 +30,11 @@ import org.apache.archiva.redback.rest.api.services.LoginService; import org.apache.archiva.redback.rest.api.services.RoleManagementService; import org.apache.archiva.redback.rest.api.services.UserService; import org.apache.archiva.redback.rest.api.services.v2.AuthenticationService; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; import org.apache.cxf.common.util.Base64Utility; import org.apache.cxf.jaxrs.client.JAXRSClientFactory; import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.transport.servlet.CXFServlet; -import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.ServerConnector; import org.eclipse.jetty.server.session.SessionHandler; @@ -44,27 +42,22 @@ import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.junit.After; import org.junit.Before; -import org.junit.runner.RunWith; -import org.junit.runners.JUnit4; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.web.context.ContextLoaderListener; import javax.ws.rs.core.MediaType; import java.util.Collections; -import java.util.concurrent.atomic.AtomicReference; /** * @author Olivier Lamy */ -@RunWith(JUnit4.class) public abstract class AbstractRestServicesTest extends TestCase { protected Logger log = LoggerFactory.getLogger( getClass() ); - private static AtomicReference server = new AtomicReference<>(); - private static AtomicReference serverConnector = new AtomicReference<>(); + protected Server server; public String authorizationHeader = getAdminAuthzHeader(); @@ -73,16 +66,14 @@ public abstract class AbstractRestServicesTest * @return */ public Server getServer() { - return this.server.get(); + return server; } public int getServerPort() { - ServerConnector connector = serverConnector.get(); - if (connector!=null) { - return connector.getLocalPort(); - } else { - return 0; + if (this.server == null || !this.server.isRunning()) { + throw new IllegalStateException("Server has not been started"); } + return ((ServerConnector) server.getConnectors()[0]).getLocalPort(); } JacksonJaxbJsonProvider getJsonProvider() { @@ -93,14 +84,6 @@ public abstract class AbstractRestServicesTest return provider; } - /** - * Returns true, if the server does exist and is running. - * @return true, if server does exist and is running. - */ - public boolean isServerRunning() { - return this.server.get() != null && this.server.get().isRunning(); - } - /** * Returns the timeout in ms for rest requests. The timeout can be set by * the system property rest.test.timeout. @@ -137,21 +120,18 @@ public abstract class AbstractRestServicesTest throws Exception { log.info("Starting server"); - Server myServer = new Server(); - this.server.set(myServer); - this.serverConnector.set(new ServerConnector( myServer, new HttpConnectionFactory())); - myServer.addConnector(serverConnector.get()); + this.server = new Server(0); ServletHolder servletHolder = new ServletHolder( new CXFServlet() ); ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setResourceBase( SystemUtils.JAVA_IO_TMPDIR ); - context.setSessionHandler( new SessionHandler( ) ); + context.setSessionHandler( new SessionHandler() ); context.addServlet( servletHolder, "/" + getRestServicesPath() + "/*" ); context.setInitParameter( "contextConfigLocation", getSpringConfigLocation() ); context.addEventListener(new ContextLoaderListener()); - getServer().setHandler( context ); - getServer().start(); + this.server.setHandler( context ); + this.server.start(); if (log.isDebugEnabled()) { @@ -187,11 +167,7 @@ public abstract class AbstractRestServicesTest public void stopServer() throws Exception { - if ( getServer() != null ) - { - log.info("Stopping server"); - getServer().stop(); - } + this.server.stop(); } protected UserService getUserService() diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LoginServiceTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LoginServiceTest.java index e13ead5b..dc87584e 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LoginServiceTest.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/LoginServiceTest.java @@ -30,9 +30,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; /** * @author Olivier Lamy */ -@RunWith( SpringJUnit4ClassRunner.class ) -@ContextConfiguration( - locations = { "classpath:/spring-context.xml" } ) +@RunWith(SpringJUnit4ClassRunner.class ) +@ContextConfiguration(locations = { "classpath:/spring-context.xml" } ) public class LoginServiceTest extends AbstractRestServicesTest { diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java index 2e262ea2..3d95a7e5 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java +++ b/redback-integrations/redback-rest/redback-rest-services/src/test/java/org/apache/archiva/redback/rest/services/UserServiceTest.java @@ -45,7 +45,7 @@ import java.util.List; /** * @author Olivier Lamy */ -@RunWith( SpringJUnit4ClassRunner.class ) +@RunWith(SpringJUnit4ClassRunner.class ) @ContextConfiguration( locations = { "classpath:/spring-context.xml" } ) public class UserServiceTest diff --git a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml index e058bdb7..9e512c6c 100644 --- a/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml +++ b/redback-integrations/redback-rest/redback-rest-services/src/test/resources/log4j2-test.xml @@ -32,8 +32,6 @@ - - diff --git a/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java b/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java index ca061189..25a62c1f 100644 --- a/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java +++ b/redback-users/redback-users-providers/redback-users-ldap/src/test/java/org/apache/archiva/redback/users/ldap/LdapUserManagerTest.java @@ -147,44 +147,28 @@ public class LdapUserManagerTest { assertNotNull( connectionFactory ); - LdapConnection connection = null; - - try + try (LdapConnection connection = connectionFactory.getConnection()) { - connection = connectionFactory.getConnection(); - assertNotNull( connection ); DirContext context = connection.getDirContext(); assertNotNull( context ); } - finally - { - connection.close(); - } } @Test public void testDirectUsersExistence() throws Exception { - LdapConnection connection = null; - - try + try (LdapConnection connection = connectionFactory.getConnection()) { - connection = connectionFactory.getConnection(); DirContext context = connection.getDirContext(); assertExist( context, createDn( "jesse" ), "cn", "jesse" ); assertExist( context, createDn( "joakim" ), "cn", "joakim" ); } - finally - { - connection.close(); - } - } @Test