mirror of https://github.com/knative/func.git
src: Quarkus events template uses CloudEvent<> (#303)
Signed-off-by: Matej Vasek <mvasek@redhat.com>
This commit is contained in:
parent
c86fdbc5e7
commit
4f60504708
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,4 +16,11 @@ public class Input {
|
|||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Input{" +
|
||||
"message='" + message + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,4 +16,11 @@ public class Output {
|
|||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Output{" +
|
||||
"message='" + message + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue