Skip to content
This repository was archived by the owner on Nov 16, 2020. It is now read-only.

Commit d41f03a

Browse files
authored
[e2e/java] Update function tests to test Spring support (#411)
1 parent 3c77504 commit d41f03a

File tree

5 files changed

+124
-5
lines changed

5 files changed

+124
-5
lines changed

e2e/tests/functions.bats

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ load variables
8484
echo_to_log
8585
assert_success
8686

87-
run_with_retry "dispatch get function java-hello-no-schema --json | jq -r .status" "READY" 8 5
87+
run_with_retry "dispatch get function java-hello-no-schema --json | jq -r .status" "READY" 20 5
8888
}
8989

9090
@test "Execute java function no schema" {
@@ -94,7 +94,7 @@ load variables
9494
@test "Create java function with runtime deps" {
9595
run dispatch create image java8-with-deps java8-base --runtime-deps ${DISPATCH_ROOT}/examples/java8/pom.xml
9696
assert_success
97-
run_with_retry "dispatch get image java8-with-deps --json | jq -r .status" "READY" 10 5
97+
run_with_retry "dispatch get image java8-with-deps --json | jq -r .status" "READY" 20 5
9898

9999
run dispatch create function java8-with-deps java-hello-with-deps ${DISPATCH_ROOT}/examples/java8/HelloWithDeps.java
100100
echo_to_log
@@ -112,13 +112,30 @@ load variables
112112
echo_to_log
113113
assert_success
114114

115-
run_with_retry "dispatch get function java-hello-with-classes --json | jq -r .status" "READY" 8 5
115+
run_with_retry "dispatch get function java-hello-with-classes --json | jq -r .status" "READY" 20 5
116116
}
117117

118118
@test "Execute java with classes" {
119119
run_with_retry "dispatch exec java-hello-with-classes --input='{\"name\": \"Jon\", \"place\": \"Winterfell\"}' --wait --json | jq -r .output.myField" "Hello, Jon from Winterfell" 5 5
120120
}
121121

122+
@test "Create java function with spring support" {
123+
run dispatch create image java8-spring java8-base --runtime-deps ${DISPATCH_ROOT}/examples/java8/spring-pom.xml
124+
assert_success
125+
126+
run_with_retry "dispatch get image java8-spring --json | jq -r .status" "READY" 10 5
127+
128+
run dispatch create function java8-spring spring-fn ${DISPATCH_ROOT}/examples/java8/HelloSpring.java
129+
echo_to_log
130+
assert_success
131+
132+
run_with_retry "dispatch get function spring-fn --json | jq -r .status" "READY" 20 5
133+
}
134+
135+
@test "Execute java with spring support" {
136+
run_with_retry "dispatch exec spring-fn --input='{\"name\":\"Jon\", \"place\":\"Winterfell\"}' --wait --json | jq -r .output.myField" "Hello, Jon from Winterfell" 5 5
137+
}
138+
122139
@test "Create node function with schema" {
123140
run dispatch create function nodejs6 node-hello-with-schema ${DISPATCH_ROOT}/examples/nodejs6/hello.js --schema-in ${DISPATCH_ROOT}/examples/nodejs6/hello.schema.in.json --schema-out ${DISPATCH_ROOT}/examples/nodejs6/hello.schema.out.json
124141
echo_to_log

e2e/tests/images.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ tags:
2424
---
2525
kind: BaseImage
2626
name: java8-base
27-
dockerUrl: dispatchframework/java8-base:0.0.2
27+
dockerUrl: dispatchframework/java8-base:0.0.3
2828
language: java8
2929
tags:
3030
- key: role

examples/java8/HelloSpring.java

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
///////////////////////////////////////////////////////////////////////
2+
// Copyright (c) 2018 VMware, Inc. All Rights Reserved.
3+
// SPDX-License-Identifier: Apache-2.0
4+
///////////////////////////////////////////////////////////////////////
5+
package io.dispatchframework.examples;
6+
7+
import java.util.Map;
8+
import java.util.function.BiFunction;
9+
import org.springframework.beans.factory.annotation.Qualifier;
10+
import org.springframework.context.annotation.Bean;
11+
import org.springframework.context.annotation.Configuration;
12+
13+
/**
14+
* A simple example of using Dispatch with a Java function backed by a
15+
* Spring ApplicationContext.
16+
*/
17+
@Configuration
18+
public class HelloSpring {
19+
20+
21+
@Bean(name = "noone")
22+
Person noone() {
23+
return new Person("Noone", "Nowhere");
24+
}
25+
26+
@Bean
27+
HelloSpringFunction function(@Qualifier("noone") Person noone) {
28+
return new HelloSpringFunction(noone);
29+
}
30+
31+
public class HelloSpringFunction implements BiFunction<Map<Object, Object>, Person, Result> {
32+
private Person defaultPerson;
33+
34+
HelloSpringFunction(Person defaultPerson) {
35+
this.defaultPerson = defaultPerson;
36+
}
37+
38+
@Override
39+
public Result apply(Map<Object, Object> context, Person person) {
40+
final String name = person.getName() == null ? defaultPerson.getName() : person.getName();
41+
final String place = person.getPlace() == null ? defaultPerson.getPlace() : person.getPlace();
42+
return new Result("Hello, " + name + " from " + place);
43+
}
44+
}
45+
46+
private class Person {
47+
private String name;
48+
private String place;
49+
50+
public Person(String name, String place) {
51+
this.name = name;
52+
this.place = place;
53+
}
54+
55+
public String getName() {
56+
return this.name;
57+
}
58+
59+
public String getPlace() {
60+
return this.place;
61+
}
62+
}
63+
64+
private class Result {
65+
private String myField;
66+
67+
public Result(String myField) {
68+
this.myField = myField;
69+
}
70+
71+
public String getMyField() {
72+
return this.myField;
73+
}
74+
}
75+
}

examples/java8/pom.xml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
<project>
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24
<modelVersion>4.0.0</modelVersion>
35
<groupId>io.dispatchframework.examples</groupId>
46
<artifactId>hello-with-deps</artifactId>

examples/java8/spring-pom.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<project xmlns="http://maven.apache.org/POM/4.0.0"
2+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
<groupId>dispatchframework.examples</groupId>
6+
<artifactId>dispatch-spring</artifactId>
7+
<version>1.0.0</version>
8+
9+
<properties>
10+
<spring.version>5.0.5.RELEASE</spring.version>
11+
</properties>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>org.springframework</groupId>
16+
<artifactId>spring-core</artifactId>
17+
<version>${spring.version}</version>
18+
</dependency>
19+
<dependency>
20+
<groupId>org.springframework</groupId>
21+
<artifactId>spring-context</artifactId>
22+
<version>${spring.version}</version>
23+
</dependency>
24+
</dependencies>
25+
</project>

0 commit comments

Comments
 (0)