Skip to content

Commit 1f05850

Browse files
committed
feat: add TomEE integration test module
• Add new integration-tests/tomee module with complete TomEE webprofile setup • Set up CDI beans.xml configuration for proper dependency injection Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
1 parent a8fdf7e commit 1f05850

File tree

10 files changed

+329
-0
lines changed

10 files changed

+329
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,6 @@ build/
3636

3737
### Rust ###
3838
target/
39+
40+
### TomEE ###
41+
.distribution

integration-tests/tomee/README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Running
2+
3+
If you would like to run this web app in tomee, run:
4+
5+
```
6+
mvn clean install tomee:exec
7+
java -jar target/*-exec.jar
8+
```

integration-tests/tomee/pom.xml

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one or more
4+
contributor license agreements. See the NOTICE file distributed with
5+
this work for additional information regarding copyright ownership.
6+
The ASF licenses this file to You under the Apache License, Version 2.0
7+
(the "License"); you may not use this file except in compliance with
8+
the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
19+
<modelVersion>4.0.0</modelVersion>
20+
21+
<parent>
22+
<groupId>io.roastedroot</groupId>
23+
<artifactId>proxy-wasm-java-host-parent</artifactId>
24+
<version>999-SNAPSHOT</version>
25+
<relativePath>../../pom.xml</relativePath>
26+
</parent>
27+
28+
<artifactId>proxy-wasm-integration-tests-tomee</artifactId>
29+
<packaging>war</packaging>
30+
<name>${project.artifactId}</name>
31+
32+
<properties>
33+
<tomee.version>10.0.0</tomee.version>
34+
<failOnMissingWebXml>false</failOnMissingWebXml>
35+
<maven.compiler.target>17</maven.compiler.target>
36+
<maven.compiler.source>17</maven.compiler.source>
37+
</properties>
38+
39+
<dependencies>
40+
<dependency>
41+
<groupId>com.google.code.gson</groupId>
42+
<artifactId>gson</artifactId>
43+
<version>2.13.1</version>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.roastedroot</groupId>
47+
<artifactId>proxy-wasm-jaxrs</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.apache.tomee.bom</groupId>
51+
<artifactId>tomee-webprofile</artifactId>
52+
<version>${tomee.version}</version>
53+
<scope>provided</scope>
54+
<exclusions>
55+
<exclusion>
56+
<groupId>org.apache.tomee</groupId>
57+
<artifactId>tomee-webapp</artifactId>
58+
</exclusion>
59+
</exclusions>
60+
</dependency>
61+
62+
<dependency>
63+
<groupId>org.apache.tomee.bom</groupId>
64+
<artifactId>tomee-webprofile-api</artifactId>
65+
<version>${tomee.version}</version>
66+
<scope>provided</scope>
67+
</dependency>
68+
<dependency>
69+
<groupId>junit</groupId>
70+
<artifactId>junit</artifactId>
71+
<version>4.13.2</version>
72+
<scope>test</scope>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.apache.tomee</groupId>
76+
<artifactId>arquillian-tomee-embedded</artifactId>
77+
<version>${tomee.version}</version>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.jboss.shrinkwrap.resolver</groupId>
82+
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
83+
<version>3.3.1</version>
84+
<scope>test</scope>
85+
</dependency>
86+
</dependencies>
87+
88+
<build>
89+
<plugins>
90+
<plugin>
91+
<groupId>com.dylibso.chicory</groupId>
92+
<artifactId>chicory-compiler-maven-plugin</artifactId>
93+
<version>${chicory.version}</version>
94+
<executions>
95+
<execution>
96+
<id>wasm-shim</id>
97+
<goals>
98+
<goal>compile</goal>
99+
</goals>
100+
<configuration>
101+
<name>io.roastedroot.proxywasm.jaxrs.it.internal.MainWasm</name>
102+
<wasmFile>../../proxy-wasm-java-host/src/test/go-examples/unit_tester/main.wasm</wasmFile>
103+
</configuration>
104+
</execution>
105+
</executions>
106+
</plugin>
107+
<plugin>
108+
<groupId>org.apache.maven.plugins</groupId>
109+
<artifactId>maven-surefire-plugin</artifactId>
110+
<version>3.2.5</version>
111+
<configuration>
112+
<systemPropertyVariables>
113+
<proxy.wasm.version>${project.version}</proxy.wasm.version>
114+
</systemPropertyVariables>
115+
</configuration>
116+
</plugin>
117+
<plugin>
118+
<groupId>org.apache.tomee.maven</groupId>
119+
<artifactId>tomee-maven-plugin</artifactId>
120+
<version>${tomee.version}</version>
121+
<configuration>
122+
<tomeeVersion>${tomee.version}</tomeeVersion>
123+
<tomeeClassifier>webprofile</tomeeClassifier>
124+
</configuration>
125+
</plugin>
126+
</plugins>
127+
</build>
128+
</project>
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.roastedroot.proxywasm.jaxrs.it;
2+
3+
import com.google.gson.Gson;
4+
import io.roastedroot.proxywasm.PluginFactory;
5+
import io.roastedroot.proxywasm.jaxrs.it.internal.MainWasm;
6+
import jakarta.enterprise.context.ApplicationScoped;
7+
import jakarta.enterprise.inject.Produces;
8+
import java.util.Map;
9+
10+
/**
11+
* CDI producers for PluginFactory instances used in integration tests.
12+
*/
13+
@ApplicationScoped
14+
public class App {
15+
16+
private static final Gson gson = new Gson();
17+
18+
/**
19+
* Configures the headerTests PluginFactory.
20+
*/
21+
@Produces
22+
public PluginFactory headerTests() {
23+
24+
return PluginFactory.builder(MainWasm.load())
25+
.withMachineFactory(MainWasm::create)
26+
.withName("headerTests")
27+
.withShared(true)
28+
.withPluginConfig(gson.toJson(Map.of("type", "headerTests")))
29+
.build();
30+
}
31+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package io.roastedroot.proxywasm.jaxrs.it;
2+
3+
import io.roastedroot.proxywasm.jaxrs.ProxyWasm;
4+
import jakarta.ws.rs.GET;
5+
import jakarta.ws.rs.HeaderParam;
6+
import jakarta.ws.rs.Path;
7+
8+
/**
9+
* JAX-RS resource class providing endpoints for integration tests.
10+
*/
11+
@Path("/")
12+
public class Resources {
13+
14+
/**
15+
* Endpoint for testing header manipulation with a shared Wasm plugin instance.
16+
*
17+
* @param counter The value of the "x-request-counter" header.
18+
* @return A string indicating the counter value.
19+
*/
20+
@Path("/headerTests")
21+
@GET
22+
@ProxyWasm("headerTests")
23+
public String headerTests(@HeaderParam("x-request-counter") String counter) {
24+
return String.format("counter: %s", counter);
25+
}
26+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
5+
https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
6+
version="4.0" bean-discovery-mode="all"/>
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package io.roastedroot.proxywasm.jaxrs.it;
18+
19+
import jakarta.ws.rs.client.ClientBuilder;
20+
import java.io.File;
21+
import java.net.URL;
22+
import org.jboss.arquillian.container.test.api.Deployment;
23+
import org.jboss.arquillian.junit.Arquillian;
24+
import org.jboss.arquillian.test.api.ArquillianResource;
25+
import org.jboss.shrinkwrap.api.ShrinkWrap;
26+
import org.jboss.shrinkwrap.api.asset.FileAsset;
27+
import org.jboss.shrinkwrap.api.spec.WebArchive;
28+
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
29+
import org.junit.Assert;
30+
import org.junit.Test;
31+
import org.junit.runner.RunWith;
32+
33+
@RunWith(Arquillian.class)
34+
public class ResourceTest extends Assert {
35+
36+
@ArquillianResource private URL webappUrl;
37+
38+
@Deployment(testable = false)
39+
public static WebArchive createDeployment() {
40+
41+
// Get GAV coordinates from system properties set by Maven
42+
String version = System.getProperty("proxy.wasm.version", "999-SNAPSHOT");
43+
String gav = "io.roastedroot:proxy-wasm-jaxrs:" + version;
44+
45+
return ShrinkWrap.create(WebArchive.class)
46+
.addClasses(Resources.class, App.class)
47+
.addAsLibraries(Maven.resolver().resolve(gav).withTransitivity().asFile())
48+
.addAsWebInfResource(
49+
new FileAsset(new File("src/main/webapp/WEB-INF/beans.xml")), "beans.xml");
50+
}
51+
52+
@Test
53+
public void test() throws Exception {
54+
final var webTarget = ClientBuilder.newClient().target(webappUrl.toURI());
55+
56+
var response = webTarget.path("/headerTests").request().get();
57+
assertEquals(200, response.getStatus());
58+
assertEquals("1", response.getHeaderString("x-response-counter"));
59+
assertEquals("counter: 1", response.readEntity(String.class));
60+
61+
response = webTarget.path("/headerTests").request().get();
62+
assertEquals(200, response.getStatus());
63+
assertEquals("2", response.getHeaderString("x-response-counter"));
64+
assertEquals("counter: 2", response.readEntity(String.class));
65+
}
66+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2+
<!--
3+
Optional file. Allows us to use random ports when running tests.
4+
The ports are communicated to the test via the @ArquillianResource annotation
5+
6+
7+
@RunWith(Arquillian.class)
8+
public class ColorBeanTest {
9+
10+
@ArquillianResource
11+
private URL webappUrl;
12+
13+
// ....
14+
}
15+
16+
If this file is deleted the default Tomcat 8080 port is used
17+
-->
18+
<arquillian>
19+
<container qualifier="tomee" default="true">
20+
<configuration>
21+
<property name="httpPort">-1</property>
22+
<property name="stopPort">-1</property>
23+
<property name="ajpPort">-1</property>
24+
</configuration>
25+
</container>
26+
</arquillian>

pom.xml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,21 @@
7878

7979
</properties>
8080

81+
<dependencyManagement>
82+
<dependencies>
83+
<dependency>
84+
<groupId>io.roastedroot</groupId>
85+
<artifactId>proxy-wasm-java-host</artifactId>
86+
<version>${project.version}</version>
87+
</dependency>
88+
<dependency>
89+
<groupId>io.roastedroot</groupId>
90+
<artifactId>proxy-wasm-jaxrs</artifactId>
91+
<version>${project.version}</version>
92+
</dependency>
93+
</dependencies>
94+
</dependencyManagement>
95+
8196
<build>
8297
<pluginManagement>
8398
<plugins>
@@ -369,6 +384,17 @@
369384
</plugins>
370385
</build>
371386
</profile>
387+
388+
<profile>
389+
<id>jdk17-modules</id>
390+
<activation>
391+
<jdk>[17,)</jdk>
392+
</activation>
393+
<modules>
394+
<module>integration-tests/tomee</module>
395+
</modules>
396+
</profile>
397+
372398
</profiles>
373399

374400
</project>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
5+
version="4.0" bean-discovery-mode="all">
6+
<alternatives>
7+
<class>io.roastedroot.proxywasm.jaxrs.cdi.ServerAdaptor</class>
8+
</alternatives>
9+
</beans>

0 commit comments

Comments
 (0)