Skip to content

Commit b595500

Browse files
authored
src: updated Quarkus template
Function in template now accepts beans instead of java.lang.Object Signed-off-by: Matej Vasek <[email protected]>
1 parent d562498 commit b595500

File tree

16 files changed

+116
-34
lines changed

16 files changed

+116
-34
lines changed

Diff for: pkged.go

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: templates/quarkus/events/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Welcome to your new Quarkus function project!
44

5-
This sample project contains single function: `functions.Function.echo()`,
5+
This sample project contains a single function: `functions.Function.function()`,
66
the function just returns its argument.
77

88
## Local execution
@@ -69,7 +69,7 @@ curl -v ${URL} \
6969
-H "Ce-Source:cloud-event-example" \
7070
-H "Ce-Type:dev.knative.example" \
7171
-H "Ce-Specversion:1.0" \
72-
-d "{\"name\": \"$(whoami)\"}\""
72+
-d "{\"message\": \"$(whoami)\"}\""
7373
```
7474

7575
### HTTPie
@@ -82,5 +82,5 @@ http -v ${URL} \
8282
Ce-Source:cloud-event-example \
8383
Ce-Type:dev.knative.example \
8484
Ce-Specversion:1.0 \
85-
name=$(whoami)
85+
message=$(whoami)
8686
```

Diff for: templates/quarkus/events/src/main/java/functions/Function.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
public class Function {
88

99
@Funq
10-
public Object echo(Object input, @Context CloudEvent cloudEvent) {
10+
public Output function(Input input, @Context CloudEvent cloudEvent) {
1111
if (cloudEvent != null) {
1212
System.out.println(
1313
"CloudEvent{" +
@@ -17,7 +17,7 @@ public Object echo(Object input, @Context CloudEvent cloudEvent) {
1717
", subject='" + cloudEvent.subject() + '\'' +
1818
'}');
1919
}
20-
return input;
20+
return new Output(input.getMessage());
2121
}
2222

23-
}
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package functions;
2+
3+
public class Input {
4+
private String message;
5+
6+
public Input() {}
7+
8+
public Input(String message) {
9+
this.message = message;
10+
}
11+
12+
public String getMessage() {
13+
return message;
14+
}
15+
16+
public void setMessage(String message) {
17+
this.message = message;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package functions;
2+
3+
public class Output {
4+
private String message;
5+
6+
public Output() {}
7+
8+
public Output(String message) {
9+
this.message = message;
10+
}
11+
12+
public String getMessage() {
13+
return message;
14+
}
15+
16+
public void setMessage(String message) {
17+
this.message = message;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Configuration file
22
# key = value
3-
quarkus.funqy.export=echo
3+
quarkus.funqy.export=function

Diff for: templates/quarkus/events/src/test/java/functions/FunctionTest.java

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,24 @@
1313
public class FunctionTest {
1414

1515
@Test
16-
void testEcho() {
17-
Object obj = (new Function()).echo(42, null);
18-
Assertions.assertEquals(42, obj);
16+
void testFunction() {
17+
Output output = (new Function()).function(new Input("Hello!"), null);
18+
Assertions.assertEquals("Hello!", output.getMessage());
1919
}
2020

2121
@Test
22-
public void testEchoIntegration() {
22+
public void testFunctionIntegration() {
2323
RestAssured.given().contentType("application/json")
24-
.body("{\"message\": \"Hello\"}")
24+
.body("{\"message\": \"Hello!\"}")
2525
.header("ce-id", "42")
2626
.header("ce-specversion", "1.0")
2727
.post("/")
2828
.then().statusCode(200)
2929
.header("ce-id", notNullValue())
3030
.header("ce-specversion", equalTo("1.0"))
31-
.header("ce-source", equalTo("echo"))
32-
.header("ce-type", equalTo("echo.output"))
33-
.body("message", equalTo("Hello"));
31+
.header("ce-source", equalTo("function"))
32+
.header("ce-type", equalTo("function.output"))
33+
.body("message", equalTo("Hello!"));
3434
}
3535

36-
}
36+
}

Diff for: templates/quarkus/events/src/test/java/functions/NativeFunctionIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
public class NativeFunctionIT extends FunctionTest {
77

88
// Execute the same tests but in native mode.
9-
}
9+
}

Diff for: templates/quarkus/http/README.md

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Welcome to your new Quarkus function project!
44

5-
This sample project contains single function: `functions.Function.echo()`,
5+
This sample project contains a single function: `functions.Function.function()`,
66
the function just returns its argument.
77

88
## Local execution
@@ -62,16 +62,22 @@ func describe
6262
### cURL
6363

6464
```shell script
65-
URL=http://localhost:8080/echo
65+
URL=http://localhost:8080/
6666
curl -v ${URL} \
6767
-H "Content-Type:application/json" \
68-
-d "{\"name\": \"$(whoami)\"}\""
68+
-d "{\"message\": \"$(whoami)\"}\""
69+
# OR
70+
URL="http://localhost:8080/?message=$(whoami)"
71+
curl -v ${URL}
6972
```
7073

7174
### HTTPie
7275

7376
```shell script
74-
URL=http://localhost:8080/echo
77+
URL=http://localhost:8080/
7578
http -v ${URL} \
76-
name=$(whoami)
79+
message=$(whoami)
80+
# OR
81+
URL="http://localhost:8080/?message=$(whoami)"
82+
http -v ${URL}
7783
```

Diff for: templates/quarkus/http/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<dependencies>
3333
<dependency>
3434
<groupId>io.quarkus</groupId>
35-
<artifactId>quarkus-funqy-http</artifactId>
35+
<artifactId>quarkus-funqy-knative-events</artifactId>
3636
</dependency>
3737
<dependency>
3838
<groupId>io.quarkus</groupId>

Diff for: templates/quarkus/http/src/main/java/functions/Function.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
public class Function {
66

77
@Funq
8-
public Object echo(Object input) {
9-
return input;
8+
public Output function(Input input) {
9+
return new Output(input.getMessage());
1010
}
1111

1212
}
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package functions;
2+
3+
public class Input {
4+
private String message;
5+
6+
public Input() {}
7+
8+
public Input(String message) {
9+
this.message = message;
10+
}
11+
12+
public String getMessage() {
13+
return message;
14+
}
15+
16+
public void setMessage(String message) {
17+
this.message = message;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package functions;
2+
3+
public class Output {
4+
private String message;
5+
6+
public Output() {}
7+
8+
public Output(String message) {
9+
this.message = message;
10+
}
11+
12+
public String getMessage() {
13+
return message;
14+
}
15+
16+
public void setMessage(String message) {
17+
this.message = message;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
# Configuration file
22
# key = value
3-
quarkus.funqy.export=echo
3+
quarkus.funqy.export=function

Diff for: templates/quarkus/http/src/test/java/functions/FunctionTest.java

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
public class FunctionTest {
1414

1515
@Test
16-
void testEcho() {
17-
Object obj = (new Function()).echo(42);
18-
Assertions.assertEquals(42, obj);
16+
void testFunction() {
17+
Output output = (new Function()).function(new Input("Hello!"));
18+
Assertions.assertEquals("Hello!", output.getMessage());
1919
}
2020

2121
@Test
22-
public void testEchoIntegration() {
22+
public void testFunctionIntegration() {
2323
RestAssured.given().contentType("application/json")
2424
.body("{\"message\": \"Hello\"}")
2525
.header("ce-id", "42")
2626
.header("ce-specversion", "1.0")
27-
.post("/echo")
27+
.post("/")
2828
.then().statusCode(200)
2929
.body("message", equalTo("Hello"));
3030
}
3131

32-
}
32+
}

Diff for: templates/quarkus/http/src/test/java/functions/NativeFunctionIT.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@
66
public class NativeFunctionIT extends FunctionTest {
77

88
// Execute the same tests but in native mode.
9-
}
9+
}

0 commit comments

Comments
 (0)