Skip to content

Commit

Permalink
Fix TUs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thierry Boileau committed Jan 28, 2025
1 parent 286481c commit 2751e6f
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<bean id="server" class="org.restlet.ext.spring.SpringServer">
<constructor-arg value="http" />
<constructor-arg>
<bean id="org.restlet.test.RestletTestCase.TEST_PORT"
<bean id="org.restlet.ext.spring.SpringTestCase.TEST_PORT"
class="org.springframework.beans.factory.config.FieldRetrievingFactoryBean" />
</constructor-arg>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -51,5 +52,6 @@ public void testFileClient() throws IOException {
// Delete the file
resource.delete();
assertEquals(Status.SUCCESS_NO_CONTENT, resource.getStatus());
Engine.clearThreadLocalVariables();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -83,7 +84,9 @@ public void handle(Request request, Response response) {

@AfterAll
static void tearDown() throws Exception {
Engine.clearThreadLocalVariables();
component.stop();
component = null;
}

}

0 comments on commit 2751e6f

Please sign in to comment.