Skip to content

Commit

Permalink
progress
Browse files Browse the repository at this point in the history
  • Loading branch information
paultuckey committed Jun 8, 2023
1 parent 47d2f1e commit 9a1d92f
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
11 changes: 6 additions & 5 deletions container-test2/example-webapp/pom.xml
Expand Up @@ -28,7 +28,7 @@
</developers>

<build>
<finalName>webapp</finalName>
<finalName>example-webapp</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
Expand All @@ -55,14 +55,15 @@

<dependencies>
<dependency>
<!-- run `mvn install` locally root of project -->
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
<version>5.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
<version>6.0.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
Expand Down
8 changes: 7 additions & 1 deletion container-test2/test-with-testcontainters/pom.xml
Expand Up @@ -33,9 +33,15 @@

<dependencies>
<dependency>
<!-- run `mvn install` locally root of project -->
<groupId>org.tuckey</groupId>
<artifactId>urlrewritefilter</artifactId>
<version>4.0.4</version>
<version>5.0.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents.client5</groupId>
<artifactId>httpclient5</artifactId>
<version>5.2.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down
@@ -1,48 +1,56 @@
package org.tuckey.web.filters.urlrewriteviacontainer;

import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.HttpClients;
import org.apache.hc.core5.http.ClassicHttpRequest;
import org.apache.hc.core5.http.io.support.ClassicRequestBuilder;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;
import org.testcontainers.utility.MountableFile;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.testcontainers.shaded.org.apache.commons.lang3.BooleanUtils.isTrue;

import java.io.IOException;
import java.nio.file.Paths;


@Testcontainers
public class ExampleTest {

private final MountableFile warFile = MountableFile.forHostPath("/Users/paul/co/urlrewritefilter/container-test2/example-webapp/target/webapp.war");
String webappPath = Paths.get("..", "example-webapp", "target", "example-webapp.war")
.toAbsolutePath().toString();

@Container
public GenericContainer<?> container = new GenericContainer(DockerImageName.parse("payara/micro"))
.withExposedPorts(8087)
.withCopyFileToContainer(warFile, "/opt/payara/deployments/webapp.war")
.withCommand("--noCluster --deploy /opt/payara/deployments/webapp.war --contextRoot /")
.waitingFor(Wait.forHttp("/get").forStatusCode(200));
public GenericContainer<?> container = new GenericContainer<>("tomcat:10.1.9")
.withReuse(true)
.withExposedPorts(8080)
.withFileSystemBind(webappPath, "/usr/local/tomcat/webapps/example-webapp.war")
.waitingFor(Wait.forHttp("/example-webapp/test/test.jsp").forStatusCode(200));

@BeforeEach
public void setUp() {
// Assume that we have Redis running locally?
//underTest = new RedisBackedCache("localhost", 6379);
System.out.println("War: " + webappPath);
}

@Test
public void checkContainerIsRunning(){
assert(isTrue(container.isRunning()));
public void checkContainerIsRunning() {
System.out.println(container.getContainerId());
assert (container.isRunning());
}

@Test
public void testSimplePutAndGet() {
//System.out.println(webContainer.getContainerId());
//underTest.put("test", "example");

//String retrieved = underTest.get("test");
//assertThat("123").isEqualTo("example");


public void testSimplePutAndGet() throws IOException {
System.out.println("Container ID" + container.getContainerId());

try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
ClassicHttpRequest httpGet = ClassicRequestBuilder.get("http://localhost:8080/example-webapp/test/test.jsp")
.build();
httpClient.execute(httpGet, response -> {
System.out.println(response.getCode() + " " + response.getReasonPhrase());
return null;
});
}
}
}

0 comments on commit 9a1d92f

Please sign in to comment.