Skip to content

feat: add TomEE integration test module #87

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ build/

### Rust ###
target/

### TomEE ###
.distribution
8 changes: 8 additions & 0 deletions integration-tests/tomee/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Running

If you would like to run this web app in tomee, run:

```
mvn clean install tomee:exec
java -jar target/*-exec.jar
```
128 changes: 128 additions & 0 deletions integration-tests/tomee/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<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">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.roastedroot</groupId>
<artifactId>proxy-wasm-java-host-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

<artifactId>proxy-wasm-integration-tests-tomee</artifactId>
<packaging>war</packaging>
<name>${project.artifactId}</name>

<properties>
<tomee.version>10.0.0</tomee.version>
<failOnMissingWebXml>false</failOnMissingWebXml>
<maven.compiler.target>17</maven.compiler.target>
<maven.compiler.source>17</maven.compiler.source>
</properties>

<dependencies>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.13.1</version>
</dependency>
<dependency>
<groupId>io.roastedroot</groupId>
<artifactId>proxy-wasm-jaxrs</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomee.bom</groupId>
<artifactId>tomee-webprofile</artifactId>
<version>${tomee.version}</version>
<scope>provided</scope>
<exclusions>
<exclusion>
<groupId>org.apache.tomee</groupId>
<artifactId>tomee-webapp</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.apache.tomee.bom</groupId>
<artifactId>tomee-webprofile-api</artifactId>
<version>${tomee.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.tomee</groupId>
<artifactId>arquillian-tomee-embedded</artifactId>
<version>${tomee.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.resolver</groupId>
<artifactId>shrinkwrap-resolver-impl-maven</artifactId>
<version>3.3.1</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>com.dylibso.chicory</groupId>
<artifactId>chicory-compiler-maven-plugin</artifactId>
<version>${chicory.version}</version>
<executions>
<execution>
<id>wasm-shim</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<name>io.roastedroot.proxywasm.jaxrs.it.internal.MainWasm</name>
<wasmFile>../../proxy-wasm-java-host/src/test/go-examples/unit_tester/main.wasm</wasmFile>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.2.5</version>
<configuration>
<systemPropertyVariables>
<proxy.wasm.version>${project.version}</proxy.wasm.version>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.tomee.maven</groupId>
<artifactId>tomee-maven-plugin</artifactId>
<version>${tomee.version}</version>
<configuration>
<tomeeVersion>${tomee.version}</tomeeVersion>
<tomeeClassifier>webprofile</tomeeClassifier>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.roastedroot.proxywasm.jaxrs.it;

import com.google.gson.Gson;
import io.roastedroot.proxywasm.PluginFactory;
import io.roastedroot.proxywasm.jaxrs.it.internal.MainWasm;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Produces;
import java.util.Map;

/**
* CDI producers for PluginFactory instances used in integration tests.
*/
@ApplicationScoped
public class App {

private static final Gson gson = new Gson();

/**
* Configures the headerTests PluginFactory.
*/
@Produces
public PluginFactory headerTests() {

return PluginFactory.builder(MainWasm.load())
.withMachineFactory(MainWasm::create)
.withName("headerTests")
.withShared(true)
.withPluginConfig(gson.toJson(Map.of("type", "headerTests")))
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.roastedroot.proxywasm.jaxrs.it;

import io.roastedroot.proxywasm.jaxrs.ProxyWasm;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.HeaderParam;
import jakarta.ws.rs.Path;

/**
* JAX-RS resource class providing endpoints for integration tests.
*/
@Path("/")
public class Resources {

/**
* Endpoint for testing header manipulation with a shared Wasm plugin instance.
*
* @param counter The value of the "x-request-counter" header.
* @return A string indicating the counter value.
*/
@Path("/headerTests")
@GET
@ProxyWasm("headerTests")
public String headerTests(@HeaderParam("x-request-counter") String counter) {
return String.format("counter: %s", counter);
}
}
6 changes: 6 additions & 0 deletions integration-tests/tomee/src/main/webapp/WEB-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
version="4.0" bean-discovery-mode="all"/>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.roastedroot.proxywasm.jaxrs.it;

import jakarta.ws.rs.client.ClientBuilder;
import java.io.File;
import java.net.URL;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.FileAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(Arquillian.class)
public class ResourceTest extends Assert {

@ArquillianResource private URL webappUrl;

@Deployment(testable = false)
public static WebArchive createDeployment() {

// Get GAV coordinates from system properties set by Maven
String version = System.getProperty("proxy.wasm.version", "999-SNAPSHOT");
String gav = "io.roastedroot:proxy-wasm-jaxrs:" + version;

return ShrinkWrap.create(WebArchive.class)
.addClasses(Resources.class, App.class)
.addAsLibraries(Maven.resolver().resolve(gav).withTransitivity().asFile())
.addAsWebInfResource(
new FileAsset(new File("src/main/webapp/WEB-INF/beans.xml")), "beans.xml");
}

@Test
public void test() throws Exception {
final var webTarget = ClientBuilder.newClient().target(webappUrl.toURI());

var response = webTarget.path("/headerTests").request().get();
assertEquals(200, response.getStatus());
assertEquals("1", response.getHeaderString("x-response-counter"));
assertEquals("counter: 1", response.readEntity(String.class));

response = webTarget.path("/headerTests").request().get();
assertEquals(200, response.getStatus());
assertEquals("2", response.getHeaderString("x-response-counter"));
assertEquals("counter: 2", response.readEntity(String.class));
}
}
26 changes: 26 additions & 0 deletions integration-tests/tomee/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!--
Optional file. Allows us to use random ports when running tests.
The ports are communicated to the test via the @ArquillianResource annotation


@RunWith(Arquillian.class)
public class ColorBeanTest {

@ArquillianResource
private URL webappUrl;

// ....
}

If this file is deleted the default Tomcat 8080 port is used
-->
<arquillian>
<container qualifier="tomee" default="true">
<configuration>
<property name="httpPort">-1</property>
<property name="stopPort">-1</property>
<property name="ajpPort">-1</property>
</configuration>
</container>
</arquillian>
26 changes: 26 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,21 @@

</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.roastedroot</groupId>
<artifactId>proxy-wasm-java-host</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.roastedroot</groupId>
<artifactId>proxy-wasm-jaxrs</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<pluginManagement>
<plugins>
Expand Down Expand Up @@ -369,6 +384,17 @@
</plugins>
</build>
</profile>

<profile>
<id>jdk17-modules</id>
<activation>
<jdk>[17,)</jdk>
</activation>
<modules>
<module>integration-tests/tomee</module>
</modules>
</profile>

</profiles>

</project>
9 changes: 9 additions & 0 deletions proxy-wasm-jaxrs/src/main/resources/META-INF/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/beans_4_0.xsd"
version="4.0" bean-discovery-mode="all">
<alternatives>
<class>io.roastedroot.proxywasm.jaxrs.cdi.ServerAdaptor</class>
</alternatives>
</beans>