Skip to content

Commit

Permalink
#10699 use non-static setup and teardown
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <lorban@bitronix.be>
  • Loading branch information
lorban committed Oct 13, 2023
1 parent 4ae40d6 commit 68797d9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand All @@ -38,17 +38,17 @@

public class JaxWsEndpointTest
{
private static StacklessLogging STACKLESS_LOGGING;
private static String URL_PREFIX;
private static Server SERVER;
private static HttpClient CLIENT;
private StacklessLogging stacklessLogging;
private String urlPrefix;
private Server server;
private HttpClient client;

@Test
public void testPostToURLWithoutTrailingSlash() throws Exception
{
Endpoint.publish(URL_PREFIX + "/add", new AddService());
Endpoint.publish(urlPrefix + "/add", new AddService());

ContentResponse response = CLIENT.newRequest(URL_PREFIX)
ContentResponse response = client.newRequest(urlPrefix)
.method(HttpMethod.POST)
.path("/add")
.send();
Expand All @@ -67,42 +67,43 @@ public int add(int a, int b)
}
}

@BeforeAll
public static void setUp() throws Exception
@BeforeEach
public void setUp() throws Exception
{
LoggingUtil.init();
STACKLESS_LOGGING = new StacklessLogging("com.sun.xml.ws.transport.http.HttpAdapter");
stacklessLogging = new StacklessLogging(com.sun.xml.ws.transport.http.HttpAdapter.class);

int port;
try (ServerSocket serverSocket = new ServerSocket())
{
serverSocket.setReuseAddress(true);
serverSocket.bind(new InetSocketAddress("localhost", 0));
port = serverSocket.getLocalPort();
URL_PREFIX = "http://localhost:" + port;
urlPrefix = "http://localhost:" + port;
}

SERVER = new Server(new DelegatingThreadPool(new QueuedThreadPool()));
ServerConnector connector = new ServerConnector(SERVER);
server = new Server(new DelegatingThreadPool(new QueuedThreadPool()));
ServerConnector connector = new ServerConnector(server);
connector.setPort(port);
SERVER.addConnector(connector);
SERVER.setHandler(new ContextHandlerCollection());
SERVER.start();
server.addConnector(connector);
server.setHandler(new ContextHandlerCollection());
server.start();

JettyHttpServerProvider.setServer(SERVER);
JettyHttpServerProvider.setServer(server);
System.setProperty("com.sun.net.httpserver.HttpServerProvider", JettyHttpServerProvider.class.getName());

CLIENT = new HttpClient();
CLIENT.start();
client = new HttpClient();
client.start();
}

@AfterAll
public static void tearDown()
@AfterEach
public void tearDown()
{
LifeCycle.stop(CLIENT);
LifeCycle.stop(SERVER);
LifeCycle.stop(client);
LifeCycle.stop(server);
JettyHttpServerProvider.setServer(null);
System.clearProperty("com.sun.net.httpserver.HttpServerProvider");
STACKLESS_LOGGING.close();
stacklessLogging.close();
LoggingUtil.end();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,9 @@ public static void init()
org.slf4j.bridge.SLF4JBridgeHandler.removeHandlersForRootLogger();
org.slf4j.bridge.SLF4JBridgeHandler.install();
}

public static void end()
{
org.slf4j.bridge.SLF4JBridgeHandler.uninstall();
}
}

0 comments on commit 68797d9

Please sign in to comment.