Skip to content

Commit c7c08ba

Browse files
committed
Refactor the jaxrs tests to make it easier to add more later.
Signed-off-by: Hiram Chirino <hiram@hiramchirino.com>
1 parent f3df694 commit c7c08ba

File tree

6 files changed

+61
-82
lines changed

6 files changed

+61
-82
lines changed

proxy-wasm-jaxrs/src/test/java/io/roastedroot/proxywasm/jaxrs/App.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

proxy-wasm-jaxrs/src/test/java/io/roastedroot/proxywasm/jaxrs/ExampleResource.java

Lines changed: 0 additions & 22 deletions
This file was deleted.

proxy-wasm-jaxrs/src/test/java/io/roastedroot/proxywasm/jaxrs/ExampleResourceTest.java

Lines changed: 0 additions & 26 deletions
This file was deleted.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.roastedroot.proxywasm.jaxrs;
2+
3+
import jakarta.ws.rs.GET;
4+
import jakarta.ws.rs.Path;
5+
6+
@Path("/http_headers")
7+
public class HttpHeadersResource {
8+
9+
@GET
10+
@NamedWasmPlugin("http_headers")
11+
public String get() {
12+
return "hello world";
13+
}
14+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.roastedroot.proxywasm.jaxrs;
2+
3+
import static io.restassured.RestAssured.given;
4+
import static io.roastedroot.proxywasm.jaxrs.TestHelpers.EXAMPLES_DIR;
5+
import static org.hamcrest.Matchers.equalTo;
6+
7+
import com.dylibso.chicory.wasm.Parser;
8+
import io.quarkus.test.junit.QuarkusTest;
9+
import io.roastedroot.proxywasm.StartException;
10+
import jakarta.enterprise.inject.Produces;
11+
import java.nio.file.Path;
12+
import org.junit.jupiter.api.Test;
13+
14+
@QuarkusTest
15+
public class HttpHeadersTest {
16+
17+
@Produces
18+
public WasmPluginFactory create() throws StartException {
19+
return () ->
20+
WasmPlugin.builder()
21+
.withName("http_headers")
22+
.withPluginConfig("{\"header\": \"x-wasm-header\", \"value\": \"foo\"}")
23+
.build(
24+
Parser.parse(
25+
Path.of(
26+
EXAMPLES_DIR
27+
+ "/go-examples/http_headers/main.wasm")));
28+
}
29+
30+
@Test
31+
public void testRequest() {
32+
given().when()
33+
.get("/http_headers")
34+
.then()
35+
.statusCode(200)
36+
.header("x-proxy-wasm-go-sdk-example", "http_headers")
37+
.header("x-wasm-header", "foo")
38+
.body(equalTo("hello world"));
39+
}
40+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.roastedroot.proxywasm.jaxrs;
2+
3+
public final class TestHelpers {
4+
private TestHelpers() {}
5+
6+
public static final String EXAMPLES_DIR = "../proxy-wasm-java-host/src/test";
7+
}

0 commit comments

Comments
 (0)