diff --git a/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/HTTPProcessor.java b/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/HTTPProcessor.java index c534484703..e81f4ddf3a 100644 --- a/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/HTTPProcessor.java +++ b/jvm-runtime/ftl-runtime/common/deployment/src/main/java/xyz/block/ftl/deployment/HTTPProcessor.java @@ -39,7 +39,7 @@ public class HTTPProcessor { @BuildStep - @Record(ExecutionTime.RUNTIME_INIT) + @Record(ExecutionTime.STATIC_INIT) public MethodScannerBuildItem methodScanners(TopicsBuildItem topics, VerbClientBuildItem verbClients, FTLRecorder recorder) { return new MethodScannerBuildItem(new MethodScanner() { diff --git a/jvm-runtime/ftl-runtime/java/integration-tests/src/main/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResource.java b/jvm-runtime/ftl-runtime/java/integration-tests/src/main/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResource.java index b76cc737ad..e746c1d442 100644 --- a/jvm-runtime/ftl-runtime/java/integration-tests/src/main/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResource.java +++ b/jvm-runtime/ftl-runtime/java/integration-tests/src/main/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResource.java @@ -35,12 +35,11 @@ public class FtlJavaRuntimeResource { @POST @Consumes(MediaType.APPLICATION_JSON) @Path("/post") - public String post(Person person) { - return "Hello " + person.first() + " " + person.last(); + public String post(Person person, HelloClient helloClient) { + return helloClient.call(person.first() + " " + person.last()); } @POST - @Consumes(MediaType.APPLICATION_JSON) @Path("/bytes") public String bytesHttp(byte[] data) { return "Hello " + new String(data, StandardCharsets.UTF_8); diff --git a/jvm-runtime/ftl-runtime/java/integration-tests/src/main/java/xyz/block/ftl/java/runtime/it/HelloClient.java b/jvm-runtime/ftl-runtime/java/integration-tests/src/main/java/xyz/block/ftl/java/runtime/it/HelloClient.java new file mode 100644 index 0000000000..830dcf00a7 --- /dev/null +++ b/jvm-runtime/ftl-runtime/java/integration-tests/src/main/java/xyz/block/ftl/java/runtime/it/HelloClient.java @@ -0,0 +1,8 @@ +package xyz.block.ftl.java.runtime.it; + +import xyz.block.ftl.VerbClient; +import xyz.block.ftl.VerbClientDefinition; + +@VerbClientDefinition(name = "hello") +public interface HelloClient extends VerbClient { +} \ No newline at end of file diff --git a/jvm-runtime/ftl-runtime/java/integration-tests/src/test/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResourceTest.java b/jvm-runtime/ftl-runtime/java/integration-tests/src/test/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResourceTest.java index a440670c37..036273e1c0 100644 --- a/jvm-runtime/ftl-runtime/java/integration-tests/src/test/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResourceTest.java +++ b/jvm-runtime/ftl-runtime/java/integration-tests/src/test/java/xyz/block/ftl/java/runtime/it/FtlJavaRuntimeResourceTest.java @@ -1,12 +1,11 @@ package xyz.block.ftl.java.runtime.it; import java.nio.charset.StandardCharsets; -import java.util.Base64; -import java.util.HashMap; import java.util.function.Function; import jakarta.inject.Inject; +import org.hamcrest.Matchers; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; @@ -19,6 +18,8 @@ import ftl.echo.EchoResponse; import io.quarkus.test.common.WithTestResource; import io.quarkus.test.junit.QuarkusTest; +import io.restassured.RestAssured; +import io.restassured.http.ContentType; import xyz.block.ftl.VerbClient; import xyz.block.ftl.VerbClientDefinition; import xyz.block.ftl.VerbClientSink; @@ -42,14 +43,6 @@ public class FtlJavaRuntimeResourceTest { @Inject BytesClient bytesClient; - @FTLManaged - @Inject - PostClient postClient; - - @FTLManaged - @Inject - BytesHTTPClient bytesHttpClient; - @Test public void testHelloEndpoint() { TestVerbServer.registerFakeVerb("echo", "echo", new Function() { @@ -76,47 +69,33 @@ public void testBytesSerialization() { @Test public void testHttpPost() { - HttpRequest request = new HttpRequest() - .setMethod("POST") - .setPath("/test/post") - .setQuery(new HashMap<>()) - .setPathParameters(new HashMap<>()) - .setHeaders(new HashMap<>()) - .setBody(new Person("Stuart", "Douglas")); - HttpResponse response = postClient.call(request); - Assertions.assertEquals("Hello Stuart Douglas", response.getBody()); + RestAssured.with().body(new Person("Stuart", "Douglas")) + .contentType(ContentType.JSON) + .post("/test/post") + .then() + .statusCode(200) + .body(Matchers.equalTo("Hello Stuart Douglas")); } @Test public void testHttpBytes() { - HttpRequest request = new HttpRequest() - .setMethod("POST") - .setPath("/test/bytes") - .setQuery(new HashMap<>()) - .setPathParameters(new HashMap<>()) - .setHeaders(new HashMap<>()) - .setBody("Stuart Douglas".getBytes(java.nio.charset.StandardCharsets.UTF_8)); - HttpResponse response = bytesHttpClient.call(request); - Assertions.assertArrayEquals("Hello Stuart Douglas".getBytes(StandardCharsets.UTF_8), - Base64.getDecoder().decode(response.getBody())); + + RestAssured.with().body("Stuart Douglas".getBytes(java.nio.charset.StandardCharsets.UTF_8)) + .contentType(ContentType.JSON) + .post("/test/bytes") + .then() + .statusCode(200) + .body(Matchers.equalTo("Hello Stuart Douglas")); } @VerbClientDefinition(name = "publish") interface PublishVerbClient extends VerbClientSink { } - @VerbClientDefinition(name = "hello") - interface HelloClient extends VerbClient { - } - @VerbClientDefinition(name = "bytes") interface BytesClient extends VerbClient { } - @VerbClientDefinition(name = "post") - interface PostClient extends VerbClient, HttpResponse> { - } - @VerbClientDefinition(name = "bytesHttp") interface BytesHTTPClient extends VerbClient, HttpResponse> { }