src: Quarkus events template uses CloudEvent<> (#303)

Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
Matej Vasek 2021-04-14 20:28:08 +02:00 committed by GitHub
parent c86fdbc5e7
commit 4f60504708
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 22 additions and 13 deletions

File diff suppressed because one or more lines are too long

View File

@ -3,21 +3,15 @@ package functions;
import io.quarkus.funqy.Context;
import io.quarkus.funqy.Funq;
import io.quarkus.funqy.knative.events.CloudEvent;
import io.quarkus.funqy.knative.events.CloudEventBuilder;
public class Function {
@Funq
public Output function(Input input, @Context CloudEvent cloudEvent) {
if (cloudEvent != null) {
System.out.println(
"CloudEvent{" +
"id='" + cloudEvent.id() + '\'' +
", specVersion='" + cloudEvent.specVersion() + '\'' +
", source='" + cloudEvent.source() + '\'' +
", subject='" + cloudEvent.subject() + '\'' +
'}');
}
return new Output(input.getMessage());
public CloudEvent<Output> function(CloudEvent<Input> input) {
System.out.println(input);
Output output = new Output(input.data().getMessage());
return CloudEventBuilder.create().build(output);
}
}

View File

@ -16,4 +16,11 @@ public class Input {
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "Input{" +
"message='" + message + '\'' +
'}';
}
}

View File

@ -16,4 +16,11 @@ public class Output {
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
return "Output{" +
"message='" + message + '\'' +
'}';
}
}

View File

@ -1,5 +1,6 @@
package functions;
import io.quarkus.funqy.knative.events.CloudEventBuilder;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.hamcrest.CoreMatchers;
@ -14,7 +15,7 @@ public class FunctionTest {
@Test
void testFunction() {
Output output = (new Function()).function(new Input("Hello!"), null);
Output output = (new Function()).function(CloudEventBuilder.create().build(new Input("Hello!"))).data();
Assertions.assertEquals("Hello!", output.getMessage());
}