From 2751e6ff4b993837e0f2171094b019118ce4130e Mon Sep 17 00:00:00 2001 From: Thierry Boileau Date: Tue, 28 Jan 2025 19:14:10 +0100 Subject: [PATCH] Fix TUs --- .../ext/crypto/HttpDigestTestCase.java | 7 +++-- .../restlet/ext/spring/SpringTestCase.java | 26 ++++++++++++++----- .../org/restlet/ext/spring/SpringTestCase.xml | 2 +- .../org/restlet/data/FileClientTestCase.java | 2 ++ .../restlet/data/RiapConnectorsTestCase.java | 3 +++ 5 files changed, 30 insertions(+), 10 deletions(-) diff --git a/org.restlet.java/org.restlet.ext.crypto/src/test/java/org/restlet/ext/crypto/HttpDigestTestCase.java b/org.restlet.java/org.restlet.ext.crypto/src/test/java/org/restlet/ext/crypto/HttpDigestTestCase.java index 5df115f1ec..cd08f80897 100644 --- a/org.restlet.java/org.restlet.ext.crypto/src/test/java/org/restlet/ext/crypto/HttpDigestTestCase.java +++ b/org.restlet.java/org.restlet.ext.crypto/src/test/java/org/restlet/ext/crypto/HttpDigestTestCase.java @@ -14,6 +14,7 @@ import org.junit.jupiter.api.Test; import org.restlet.*; import org.restlet.data.*; +import org.restlet.engine.Engine; import org.restlet.resource.ClientResource; import org.restlet.resource.ResourceException; import org.restlet.routing.Router; @@ -58,8 +59,9 @@ public void handle(Request request, Response response) { @BeforeEach protected void setUpEach() throws Exception { + Engine.clearThreadLocalVariables(); component = new Component(); - Server server = component.getServers().add(Protocol.HTTP, 0); + final Server server = component.getServers().add(Protocol.HTTP, 0); Application application = new MyApplication(); component.getDefaultHost().attach(application); component.start(); @@ -68,12 +70,13 @@ protected void setUpEach() throws Exception { @AfterEach protected void tearDownEach() throws Exception { + Engine.clearThreadLocalVariables(); component.stop(); component = null; } @Test - public void testDigest() throws Exception { + public void testDigest() { ClientResource cr = new ClientResource("http://localhost:" + port + "/"); // Try unauthenticated request diff --git a/org.restlet.java/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringTestCase.java b/org.restlet.java/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringTestCase.java index bad5683d6d..b9d0e1194f 100644 --- a/org.restlet.java/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringTestCase.java +++ b/org.restlet.java/org.restlet.ext.spring/src/test/java/org/restlet/ext/spring/SpringTestCase.java @@ -9,9 +9,12 @@ package org.restlet.ext.spring; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.restlet.Component; import org.restlet.Server; +import org.restlet.engine.Engine; import org.springframework.context.support.ClassPathXmlApplicationContext; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -23,30 +26,39 @@ */ public class SpringTestCase { + public static int TEST_PORT = 1337; // referenced in SpringTestCase.xml + @Test public void testSpring() throws Exception { - // Load the Spring container - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "org/restlet/ext/spring/SpringTestCase.xml"); - // Start the Restlet component Component component = (Component) ctx.getBean("component"); component.start(); Thread.sleep(500); component.stop(); - ctx.close(); } @Test public void testSpringServerProperties() { - ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext( - "org/restlet/test/ext/spring/SpringTestCase.xml"); Server server = (Server) ctx.getBean("server"); assertEquals("value1", server.getContext().getParameters() .getFirstValue("key1")); assertEquals("value2", server.getContext().getParameters() .getFirstValue("key2")); + } + + private ClassPathXmlApplicationContext ctx; + + @BeforeEach + void setUp() { + Engine.clearThreadLocalVariables(); + ctx = new ClassPathXmlApplicationContext("org/restlet/ext/spring/SpringTestCase.xml"); + System.out.println(ctx); + } + + @AfterEach + void cleanUp() { + Engine.clearThreadLocalVariables(); ctx.close(); } diff --git a/org.restlet.java/org.restlet.ext.spring/src/test/resources/org/restlet/ext/spring/SpringTestCase.xml b/org.restlet.java/org.restlet.ext.spring/src/test/resources/org/restlet/ext/spring/SpringTestCase.xml index 2fee914559..05e9739ef5 100644 --- a/org.restlet.java/org.restlet.ext.spring/src/test/resources/org/restlet/ext/spring/SpringTestCase.xml +++ b/org.restlet.java/org.restlet.ext.spring/src/test/resources/org/restlet/ext/spring/SpringTestCase.xml @@ -23,7 +23,7 @@ - diff --git a/org.restlet.java/org.restlet/src/test/java/org/restlet/data/FileClientTestCase.java b/org.restlet.java/org.restlet/src/test/java/org/restlet/data/FileClientTestCase.java index 4dfd2543fc..275d81a463 100644 --- a/org.restlet.java/org.restlet/src/test/java/org/restlet/data/FileClientTestCase.java +++ b/org.restlet.java/org.restlet/src/test/java/org/restlet/data/FileClientTestCase.java @@ -32,6 +32,7 @@ public class FileClientTestCase { @Test public void testFileClient() throws IOException { Engine.register(); + Engine.clearThreadLocalVariables(); String fileContent = "Test content\r\nLine 2\r\nLine2"; File temporaryfile = File.createTempFile("Restlet", ".txt." + Language.DEFAULT.getName()); @@ -51,5 +52,6 @@ public void testFileClient() throws IOException { // Delete the file resource.delete(); assertEquals(Status.SUCCESS_NO_CONTENT, resource.getStatus()); + Engine.clearThreadLocalVariables(); } } diff --git a/org.restlet.java/org.restlet/src/test/java/org/restlet/data/RiapConnectorsTestCase.java b/org.restlet.java/org.restlet/src/test/java/org/restlet/data/RiapConnectorsTestCase.java index 225c4ac4da..f29848cfef 100644 --- a/org.restlet.java/org.restlet/src/test/java/org/restlet/data/RiapConnectorsTestCase.java +++ b/org.restlet.java/org.restlet/src/test/java/org/restlet/data/RiapConnectorsTestCase.java @@ -47,6 +47,7 @@ public void testRiapConnectors(final String url) throws IOException { @BeforeAll static void setUp() throws Exception { + Engine.clearThreadLocalVariables(); Engine.register(); component = new Component(); @@ -83,7 +84,9 @@ public void handle(Request request, Response response) { @AfterAll static void tearDown() throws Exception { + Engine.clearThreadLocalVariables(); component.stop(); + component = null; } }