Skip to content

Commit b7a2f06

Browse files
committed
Add Testcontainers module, setup testing with Nginx container
- Enable `testcontainers` module in root `pom.xml` - Add `bnd.bnd` configuration for Testcontainers core - Create `pom.xml` for Testcontainers core module - Add Nginx container test in `NginxRundAndConnectTest.java` - Add `test.bndrun` for OSGi testing setup - Create parent `pom.xml` for Testcontainers module
1 parent d17c8f6 commit b7a2f06

File tree

6 files changed

+233
-1
lines changed

6 files changed

+233
-1
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@
3333
<description></description>
3434

3535
<modules>
36-
<!-- <module>testcontainers</module>-->
36+
<module>testcontainers</module>
3737
</modules>
3838
</project>

testcontainers/core/bnd.bnd

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#*******************************************************************************
2+
# Copyright (c) 2004 Contributors to the Eclipse Foundation
3+
#
4+
# This program and the accompanying materials are made
5+
# available under the terms of the Eclipse Public License 2.0
6+
# which is available at https://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
# Contributors:
11+
# SmartCity Jena - initial
12+
# Stefan Bischof (bipolis.org) - initial
13+
#*******************************************************************************
14+
15+
Export-Package: \
16+
!org.testcontainers.shaded*,\
17+
com.github.dockerjava.api*,\
18+
org.testcontainers*
19+
20+
-includeresource: \
21+
@testcontainers-1.20.2.jar,\
22+
@duct-tape-1.0.8.jar,\
23+
@docker-java-transport-3.4.0.jar,\
24+
@docker-java-transport-zerodep-3.4.0.jar
25+
26+
27+
-privatepackage: \
28+
org.rnorth.ducttape*,\
29+
com.fasterxml.jackson.annotation*,\
30+
org.junit.rules*,\
31+
org.junit.runners*,\
32+
org.hamcrest*,\
33+
org.apache.commons.compress,\
34+
com.github.dockerjava.zerodep*
35+
36+
Import-Package: \
37+
!android.os.*,\
38+
!com.github.dockerjava*,\
39+
!com.google.appengine.*,\
40+
!com.google.apphosting.*,\
41+
!com.google.cloud.*,\
42+
!io.r2dbc.*,\
43+
!javax.annotation.*, \
44+
!org.conscrypt, \
45+
!org.testcontainers.r2dbc.*, \
46+
!org.junit*,\
47+
!sun.nio.ch*,\
48+
*

testcontainers/core/pom.xml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*********************************************************************
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
5+
*
6+
* This program and the accompanying materials are made
7+
* available under the terms of the Eclipse Public License 2.0
8+
* which is available at https://www.eclipse.org/legal/epl-2.0/
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
**********************************************************************/
12+
-->
13+
<project xmlns="http://maven.apache.org/POM/4.0.0"
14+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
<parent>
18+
<groupId>org.eclipse.daanse</groupId>
19+
<artifactId>org.eclipse.daanse.tooling.testcontainers</artifactId>
20+
<version>0.0.1-SNAPSHOT</version>
21+
</parent>
22+
<artifactId>org.eclipse.daanse.tooling.testcontainers.core</artifactId>
23+
24+
25+
<dependencies>
26+
<dependency>
27+
<groupId>org.testcontainers</groupId>
28+
<artifactId>testcontainers</artifactId>
29+
<version>1.20.2</version>
30+
<scope>compile</scope>
31+
</dependency>
32+
</dependencies>
33+
</project>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
3+
*
4+
* This program and the accompanying materials are made
5+
* available under the terms of the Eclipse Public License 2.0
6+
* which is available at https://www.eclipse.org/legal/epl-2.0/
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* SmartCity Jena - initial
12+
* Stefan Bischof (bipolis.org) - initial
13+
*/
14+
package org.eclipse.daanse.tooling.testcontainers.core;
15+
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
18+
import java.net.URI;
19+
import java.net.http.HttpClient;
20+
import java.net.http.HttpRequest;
21+
import java.net.http.HttpResponse;
22+
23+
import org.testcontainers.DockerClientFactory;
24+
import org.testcontainers.containers.GenericContainer;
25+
26+
public class NginxRundAndConnectTest {
27+
28+
@org.junit.jupiter.api.Test
29+
void startandConnectPortNginX() throws Exception {
30+
31+
DockerClientFactory.lazyClient().pingCmd();
32+
33+
try (GenericContainer<?> nginx = new GenericContainer("nginx:alpine-slim").withExposedPorts(80)
34+
35+
) {
36+
// Starte den Container
37+
nginx.start();
38+
39+
// get external port mapped
40+
Integer mappedPort = nginx.getMappedPort(80);
41+
String url = "http://localhost:" + mappedPort;
42+
System.out.println("Container Port: " + mappedPort);
43+
44+
// Create a HTTP-Client
45+
HttpClient client = HttpClient.newHttpClient();
46+
47+
// BuildHTTP GET-Request
48+
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).build();
49+
50+
// Send Request
51+
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
52+
53+
// Check Statuscode is 200 OK
54+
assertTrue(response.statusCode() == 200, "Expected 200 OK, but got: " + response.statusCode());
55+
56+
// Answer
57+
System.out.println("Response body: " + response.body());
58+
59+
nginx.stop();
60+
61+
System.out.println(1113);
62+
} finally {
63+
}
64+
}
65+
}

testcontainers/core/test.bndrun

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#*******************************************************************************
2+
# Copyright (c) 2004 Contributors to the Eclipse Foundation
3+
#
4+
# This program and the accompanying materials are made
5+
# available under the terms of the Eclipse Public License 2.0
6+
# which is available at https://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
# Contributors:
11+
# SmartCity Jena - initial
12+
# Stefan Bischof (bipolis.org) - initial
13+
#*******************************************************************************
14+
15+
-runpath: \
16+
ch.qos.logback.classic,\
17+
ch.qos.logback.core,\
18+
slf4j.api
19+
20+
-runstartlevel: \
21+
order=sortbynameversion,\
22+
begin=-1
23+
24+
-runtrace: true
25+
26+
-tester: biz.aQute.tester.junit-platform
27+
28+
-runsystemcapabilities: ${native_capability}
29+
30+
-runproperties: \
31+
org.slf4j.simpleLogger.defaultLogLevel=debug
32+
33+
-runfw: org.apache.felix.framework
34+
35+
-runee: JavaSE-21
36+
37+
-runrequires: \
38+
bnd.identity;id='${project.artifactId}-tests',\
39+
bnd.identity;id=junit-jupiter-engine,\
40+
bnd.identity;id=junit-platform-launcher,\
41+
bnd.identity;id='org.apache.aries.spifly.dynamic.framework.extension'
42+
43+
# -runbundles is calculated by the bnd-resolver-maven-plugin
44+
45+
-runbundles: \
46+
ch.qos.logback.classic;version='[1.5.6,1.5.7)',\
47+
ch.qos.logback.core;version='[1.5.6,1.5.7)',\
48+
com.sun.jna;version='[5.13.0,5.13.1)',\
49+
junit-jupiter-api;version='[5.10.2,5.10.3)',\
50+
junit-jupiter-engine;version='[5.10.2,5.10.3)',\
51+
junit-platform-commons;version='[1.10.2,1.10.3)',\
52+
junit-platform-engine;version='[1.10.2,1.10.3)',\
53+
junit-platform-launcher;version='[1.10.2,1.10.3)',\
54+
org.apache.aries.spifly.dynamic.framework.extension;version='[1.3.7,1.3.8)',\
55+
org.apache.commons.commons-compress;version='[1.24.0,1.24.1)',\
56+
org.eclipse.daanse.tooling.testcontainers.core;version='[0.0.1,0.0.2)',\
57+
org.eclipse.daanse.tooling.testcontainers.core-tests;version='[0.0.1,0.0.2)',\
58+
org.opentest4j;version='[1.3.0,1.3.1)',\
59+
slf4j.api;version='[2.0.12,2.0.13)'

testcontainers/pom.xml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/*********************************************************************
4+
* Copyright (c) 2025 Contributors to the Eclipse Foundation.
5+
*
6+
* This program and the accompanying materials are made
7+
* available under the terms of the Eclipse Public License 2.0
8+
* which is available at https://www.eclipse.org/legal/epl-2.0/
9+
*
10+
* SPDX-License-Identifier: EPL-2.0
11+
**********************************************************************/
12+
-->
13+
<project xmlns="http://maven.apache.org/POM/4.0.0"
14+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
16+
<modelVersion>4.0.0</modelVersion>
17+
<parent>
18+
<groupId>org.eclipse.daanse</groupId>
19+
<artifactId>org.eclipse.daanse.tooling</artifactId>
20+
<version>0.0.1-SNAPSHOT</version>
21+
</parent>
22+
<artifactId>org.eclipse.daanse.tooling.testcontainers</artifactId>
23+
<packaging>pom</packaging>
24+
<modules>
25+
<module>core</module>
26+
</modules>
27+
</project>

0 commit comments

Comments
 (0)