Skip to content

Commit 0fc4ea4

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 0fc4ea4

File tree

6 files changed

+237
-2
lines changed

6 files changed

+237
-2
lines changed

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<parent>
2020
<groupId>org.eclipse.daanse</groupId>
2121
<artifactId>org.eclipse.daanse.pom.parent</artifactId>
22-
<version>0.0.3</version>
22+
<version>0.0.4</version>
2323
</parent>
2424

2525
<artifactId>org.eclipse.daanse.tooling</artifactId>
@@ -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: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
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+
-metainf-services: auto
16+
17+
Export-Package: \
18+
!org.testcontainers.shaded*,\
19+
com.github.dockerjava.api*,\
20+
org.testcontainers*
21+
22+
-includeresource: \
23+
@testcontainers-1.21.3.jar,\
24+
@duct-tape-1.0.8.jar,\
25+
@docker-java-api-3.4.2.jar,\
26+
@docker-java-transport-3.4.2.jar,\
27+
@docker-java-transport-zerodep-3.4.2.jar
28+
29+
DynamicImport-Package: *
30+
31+
-privatepackage: \
32+
org.rnorth.ducttape*,\
33+
com.fasterxml.jackson.annotation*,\
34+
org.junit.rules*,\
35+
org.junit.runners*,\
36+
org.hamcrest*,\
37+
org.apache.commons.compress,\
38+
com.github.dockerjava.zerodep*
39+
40+
Import-Package: \
41+
!android.os.*,\
42+
!com.github.dockerjava*,\
43+
!com.google.appengine.*,\
44+
!com.google.apphosting.*,\
45+
!com.google.cloud.*,\
46+
!io.r2dbc.*,\
47+
!javax.annotation.*, \
48+
!org.conscrypt, \
49+
!org.testcontainers.r2dbc.*, \
50+
!org.junit*,\
51+
!sun.nio.ch*,\
52+
*

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.21.3</version>
30+
<scope>compile</scope>
31+
</dependency>
32+
</dependencies>
33+
</project>
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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.junit.jupiter.api.Disabled;
24+
import org.testcontainers.DockerClientFactory;
25+
import org.testcontainers.containers.GenericContainer;
26+
27+
public class NginxRundAndConnectTest {
28+
29+
@Disabled
30+
@org.junit.jupiter.api.Test
31+
void startandConnectPortNginX() throws Exception {
32+
33+
DockerClientFactory.lazyClient().pingCmd();
34+
35+
try (GenericContainer<?> nginx = new GenericContainer("nginx:alpine-slim").withExposedPorts(80)
36+
37+
) {
38+
// Starte den Container
39+
nginx.start();
40+
41+
// get external port mapped
42+
Integer mappedPort = nginx.getMappedPort(80);
43+
String url = "http://localhost:" + mappedPort;
44+
System.out.println("Container Port: " + mappedPort);
45+
46+
// Create a HTTP-Client
47+
HttpClient client = HttpClient.newHttpClient();
48+
49+
// BuildHTTP GET-Request
50+
HttpRequest request = HttpRequest.newBuilder().uri(URI.create(url)).build();
51+
52+
// Send Request
53+
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
54+
55+
// Check Statuscode is 200 OK
56+
assertTrue(response.statusCode() == 200, "Expected 200 OK, but got: " + response.statusCode());
57+
58+
// Answer
59+
System.out.println("Response body: " + response.body());
60+
61+
nginx.stop();
62+
63+
System.out.println(1113);
64+
} finally {
65+
}
66+
}
67+
}

testcontainers/core/test.bndrun

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
com.sun.jna;version='[5.13.0,5.13.1)',\
47+
junit-jupiter-api;version='[5.10.2,5.10.3)',\
48+
junit-jupiter-engine;version='[5.10.2,5.10.3)',\
49+
junit-platform-commons;version='[1.10.2,1.10.3)',\
50+
junit-platform-engine;version='[1.10.2,1.10.3)',\
51+
junit-platform-launcher;version='[1.10.2,1.10.3)',\
52+
org.apache.aries.spifly.dynamic.framework.extension;version='[1.3.7,1.3.8)',\
53+
org.apache.commons.commons-compress;version='[1.24.0,1.24.1)',\
54+
org.eclipse.daanse.tooling.testcontainers.core;version='[0.0.1,0.0.2)',\
55+
org.eclipse.daanse.tooling.testcontainers.core-tests;version='[0.0.1,0.0.2)',\
56+
org.opentest4j;version='[1.3.0,1.3.1)'

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)