Added checkstyle for tests
This commit is contained in:
@@ -48,7 +48,8 @@ public class Config implements ApplicationContextInitializer<GenericApplicationC
|
||||
@Bean
|
||||
public Function<Foo, Bar> function() {
|
||||
return value -> new Bar(
|
||||
value.uppercase() + (this.props.getFoo() != null ? "-" + this.props.getFoo() : ""));
|
||||
value.uppercase() + (this.props.getFoo() != null ? "-" + this.props
|
||||
.getFoo() : ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -57,8 +58,8 @@ public class Config implements ApplicationContextInitializer<GenericApplicationC
|
||||
this.props = properties;
|
||||
context.registerBean(Properties.class, () -> properties);
|
||||
context.registerBean("function", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<Function<Foo, Bar>>(function())
|
||||
.type(FunctionType.from(Foo.class).to(Bar.class).getType()));
|
||||
() -> new FunctionRegistration<Function<Foo, Bar>>(function())
|
||||
.type(FunctionType.from(Foo.class).to(Bar.class).getType()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MapTests {
|
||||
@Test
|
||||
public void start() throws Exception {
|
||||
SpringBootRequestHandler<Object, Object> handler = new SpringBootRequestHandler<>(
|
||||
Config.class);
|
||||
Config.class);
|
||||
handler.handleRequest(new Foo("foo"), null);
|
||||
handler.close();
|
||||
}
|
||||
|
||||
@@ -31,9 +31,9 @@ public class FooHandler extends AzureSpringBootRequestHandler<Foo, Bar> {
|
||||
|
||||
@FunctionName("uppercase")
|
||||
public Bar execute(
|
||||
@HttpTrigger(name = "req", methods = { HttpMethod.GET,
|
||||
HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) Foo foo,
|
||||
ExecutionContext context) {
|
||||
@HttpTrigger(name = "req", methods = {HttpMethod.GET,
|
||||
HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) Foo foo,
|
||||
ExecutionContext context) {
|
||||
return handleRequest(foo, context);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,7 +37,7 @@ public class MapTests {
|
||||
@Test
|
||||
public void start() throws Exception {
|
||||
AzureSpringBootRequestHandler<Foo, Bar> handler = new AzureSpringBootRequestHandler<>(
|
||||
Config.class);
|
||||
Config.class);
|
||||
Bar result = handler.handleRequest(new Foo("foo"), null);
|
||||
handler.close();
|
||||
assertThat(result.getValue()).isEqualTo("FOO");
|
||||
|
||||
@@ -26,16 +26,15 @@ import org.springframework.boot.web.server.LocalServerPort;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"spring.cloud.function.compile.test.lambda=com.example.SampleCompiledConsumerTests.Reference::set",
|
||||
"spring.cloud.function.compile.test.inputType=String",
|
||||
"spring.cloud.function.compile.test.type=consumer" })
|
||||
"spring.cloud.function.compile.test.lambda=com.example.SampleCompiledConsumerTests.Reference::set",
|
||||
"spring.cloud.function.compile.test.inputType=String",
|
||||
"spring.cloud.function.compile.test.type=consumer"})
|
||||
public class SampleCompiledConsumerTests {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -44,8 +43,9 @@ public class SampleCompiledConsumerTests {
|
||||
@Test
|
||||
public void print() {
|
||||
assertThat(new TestRestTemplate().postForObject(
|
||||
"http://localhost:" + this.port + "/test", "it works", String.class)).isNull();
|
||||
assertEquals("it works", Reference.instance);
|
||||
"http://localhost:" + this.port + "/test", "it works", String.class))
|
||||
.isNull();
|
||||
assertThat(Reference.instance).isEqualTo("it works");
|
||||
}
|
||||
|
||||
public static class Reference {
|
||||
|
||||
@@ -32,9 +32,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = {
|
||||
"spring.cloud.function.compile.test.lambda=f->f.map(s->s+\"!!!\")",
|
||||
"spring.cloud.function.compile.test.inputType=Flux<String>",
|
||||
"spring.cloud.function.compile.test.outputType=Flux<String>" })
|
||||
"spring.cloud.function.compile.test.lambda=f->f.map(s->s+\"!!!\")",
|
||||
"spring.cloud.function.compile.test.inputType=Flux<String>",
|
||||
"spring.cloud.function.compile.test.outputType=Flux<String>"})
|
||||
public class SampleCompiledFunctionTests {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -43,8 +43,8 @@ public class SampleCompiledFunctionTests {
|
||||
@Test
|
||||
public void lowercase() {
|
||||
assertThat(new TestRestTemplate().postForObject(
|
||||
"http://localhost:" + this.port + "/test", "it works", String.class))
|
||||
.contains("it works!!!");
|
||||
"http://localhost:" + this.port + "/test", "it works", String.class))
|
||||
.contains("it works!!!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -46,14 +46,14 @@ public class SampleApplication {
|
||||
return multiValueMap -> {
|
||||
Map<String, Integer> result = new HashMap<>();
|
||||
multiValueMap.forEach((s, strings) -> result.put(s,
|
||||
strings.stream().mapToInt(Integer::parseInt).sum()));
|
||||
strings.stream().mapToInt(Integer::parseInt).sum()));
|
||||
return result;
|
||||
};
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Supplier<Flux<Foo>> words() {
|
||||
return () -> Flux.fromArray(new Foo[] { new Foo("foo"), new Foo("bar") }).log();
|
||||
return () -> Flux.fromArray(new Foo[] {new Foo("foo"), new Foo("bar")}).log();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -43,10 +44,11 @@ public class SampleApplicationMvcTests {
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = this.rest.exchange(RequestEntity.get(new URI("/words"))
|
||||
ResponseEntity<String> result = this.rest
|
||||
.exchange(RequestEntity.get(new URI("/words"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class);
|
||||
assertThat(result.getBody())
|
||||
.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -58,35 +59,37 @@ public class SampleApplicationTests {
|
||||
|
||||
@Test
|
||||
public void words() {
|
||||
assertThat(this.rest.getForObject("http://localhost:" + this.port + "/words", String.class))
|
||||
.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
assertThat(this.rest
|
||||
.getForObject("http://localhost:" + this.port + "/words", String.class))
|
||||
.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uppercase() {
|
||||
assertThat(this.rest.postForObject("http://localhost:" + this.port + "/uppercase",
|
||||
new HttpEntity<>("[{\"value\":\"foo\"}]", this.headers), String.class))
|
||||
.isEqualTo("[{\"value\":\"FOO\"}]");
|
||||
new HttpEntity<>("[{\"value\":\"foo\"}]", this.headers), String.class))
|
||||
.isEqualTo("[{\"value\":\"FOO\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void composite() {
|
||||
assertThat(this.rest.getForObject("http://localhost:" + this.port + "/words,uppercase",
|
||||
assertThat(this.rest
|
||||
.getForObject("http://localhost:" + this.port + "/words,uppercase",
|
||||
String.class)).isEqualTo("[{\"value\":\"FOO\"},{\"value\":\"BAR\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void single() {
|
||||
assertThat(this.rest.postForObject("http://localhost:" + this.port + "/uppercase",
|
||||
new HttpEntity<>("{\"value\":\"foo\"}", this.headers), String.class))
|
||||
.isEqualTo("{\"value\":\"FOO\"}");
|
||||
new HttpEntity<>("{\"value\":\"foo\"}", this.headers), String.class))
|
||||
.isEqualTo("{\"value\":\"FOO\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowercase() {
|
||||
assertThat(this.rest.postForObject("http://localhost:" + this.port + "/lowercase",
|
||||
new HttpEntity<>("[{\"value\":\"Foo\"}]", this.headers), String.class))
|
||||
.isEqualTo("[{\"value\":\"foo\"}]");
|
||||
new HttpEntity<>("[{\"value\":\"Foo\"}]", this.headers), String.class))
|
||||
.isEqualTo("[{\"value\":\"foo\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -98,10 +101,10 @@ public class SampleApplicationTests {
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("http://localhost:" + this.port + "/sum"))
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
RequestEntity.post(new URI("http://localhost:" + this.port + "/sum"))
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.APPLICATION_FORM_URLENCODED).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,10 +117,10 @@ public class SampleApplicationTests {
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(this.rest.exchange(
|
||||
RequestEntity.post(new URI("http://localhost:" + this.port + "/sum"))
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
RequestEntity.post(new URI("http://localhost:" + this.port + "/sum"))
|
||||
.accept(MediaType.APPLICATION_JSON)
|
||||
.contentType(MediaType.MULTIPART_FORM_DATA).body(map),
|
||||
String.class).getBody()).isEqualTo("[{\"A\":6,\"B\":11}]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -53,25 +53,25 @@ public class SampleApplication {
|
||||
|
||||
@Bean
|
||||
public Supplier<Flux<String>> words() {
|
||||
return () -> Flux.fromArray(new String[] { "foo", "bar" });
|
||||
return () -> Flux.fromArray(new String[] {"foo", "bar"});
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> compiledUppercase(
|
||||
FunctionCompiler<String, String> compiler) {
|
||||
FunctionCompiler<String, String> compiler) {
|
||||
String lambda = "s -> s.toUpperCase()";
|
||||
LambdaCompilingFunction<String, String> function = new LambdaCompilingFunction<>(
|
||||
new ByteArrayResource(lambda.getBytes()), compiler);
|
||||
new ByteArrayResource(lambda.getBytes()), compiler);
|
||||
function.setTypeParameterizations("String", "String");
|
||||
return function;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<Flux<String>, Flux<String>> compiledLowercase(
|
||||
FunctionCompiler<Flux<String>, Flux<String>> compiler) {
|
||||
FunctionCompiler<Flux<String>, Flux<String>> compiler) {
|
||||
String lambda = "f->f.map(o->o.toString().toLowerCase())";
|
||||
return new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()),
|
||||
compiler);
|
||||
compiler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -24,7 +24,7 @@ import com.example.functions.Greeter;
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
public class FunctionTests {
|
||||
|
||||
@@ -33,36 +33,36 @@ public class FunctionTests {
|
||||
@Test
|
||||
public void testUppercase() {
|
||||
String output = this.functions.uppercase().apply("foobar");
|
||||
assertEquals("FOOBAR", output);
|
||||
assertThat(output).isEqualTo("FOOBAR");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowercase() {
|
||||
Flux<String> output = this.functions.lowercase().apply(Flux.just("FOO", "BAR"));
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(results.get(0)).isEqualTo("foo");
|
||||
assertThat(results.get(1)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHello() {
|
||||
String output = this.functions.hello().get();
|
||||
assertEquals("hello", output);
|
||||
assertThat(output).isEqualTo("hello");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWords() {
|
||||
Flux<String> output = this.functions.words().get();
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(results.get(0)).isEqualTo("foo");
|
||||
assertThat(results.get(1)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreeter() {
|
||||
assertEquals("Hello World", new Greeter().apply("World"));
|
||||
assertThat(new Greeter().apply("World")).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,14 +70,15 @@ public class FunctionTests {
|
||||
Flux<String> input = Flux.just("foo", "bar");
|
||||
Flux<String> output = new Exclaimer().apply(input);
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo!!!", results.get(0));
|
||||
assertEquals("bar!!!", results.get(1));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(results.get(0)).isEqualTo("foo!!!");
|
||||
assertThat(results.get(1)).isEqualTo("bar!!!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharCounter() {
|
||||
assertEquals((Integer) 21, new CharCounter().apply("this is 21 chars long"));
|
||||
assertThat(new CharCounter().apply("this is 21 chars long"))
|
||||
.isEqualTo((Integer) 21);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.example;
|
||||
|
||||
import org.junit.Ignore;
|
||||
@@ -40,7 +41,8 @@ public class SampleApplicationMvcTests {
|
||||
@Test
|
||||
@Ignore("FIXME")
|
||||
public void words() throws Exception {
|
||||
this.mockMvc.perform(get("/words")).andExpect(content().string("[\"foo\",\"bar\"]"));
|
||||
this.mockMvc.perform(get("/words"))
|
||||
.andExpect(content().string("[\"foo\",\"bar\"]"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
@@ -60,22 +60,22 @@ public class SampleApplicationTests {
|
||||
@Test
|
||||
public void testUppercase() {
|
||||
String output = this.uppercase.apply("foobar");
|
||||
assertEquals("FOOBAR", output);
|
||||
assertThat(output).isEqualTo("FOOBAR");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowercase() {
|
||||
Flux<String> output = this.lowercase.apply(Flux.just("FOO", "BAR"));
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(results.get(0)).isEqualTo("foo");
|
||||
assertThat(results.get(1)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHello() {
|
||||
String output = this.hello.get();
|
||||
assertEquals("hello", output);
|
||||
assertThat(output).isEqualTo("hello");
|
||||
}
|
||||
|
||||
// the following are contributed via @FunctionScan:
|
||||
@@ -84,15 +84,15 @@ public class SampleApplicationTests {
|
||||
public void testWords() {
|
||||
Flux<String> output = this.words.get();
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(results.get(0)).isEqualTo("foo");
|
||||
assertThat(results.get(1)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCompiledUppercase() {
|
||||
String output = this.compiledUppercase.apply("foobar");
|
||||
assertEquals("FOOBAR", output);
|
||||
assertThat(output).isEqualTo("FOOBAR");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -100,15 +100,15 @@ public class SampleApplicationTests {
|
||||
Flux<String> input = Flux.just("FOO", "BAR");
|
||||
Flux<String> output = this.compiledLowercase.apply(input);
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(results.get(0)).isEqualTo("foo");
|
||||
assertThat(results.get(1)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGreeter() {
|
||||
String greeting = this.greeter.apply("World");
|
||||
assertEquals("Hello World", greeting);
|
||||
assertThat(greeting).isEqualTo("Hello World");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -116,15 +116,15 @@ public class SampleApplicationTests {
|
||||
Flux<String> input = Flux.just("foo", "bar");
|
||||
Flux<String> output = this.exclaimer.apply(input);
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo!!!", results.get(0));
|
||||
assertEquals("bar!!!", results.get(1));
|
||||
assertThat(results.size()).isEqualTo(2);
|
||||
assertThat(results.get(0)).isEqualTo("foo!!!");
|
||||
assertThat(results.get(1)).isEqualTo("bar!!!");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCharCounter() {
|
||||
Integer length = this.charCounter.apply("the quick brown fox");
|
||||
assertEquals(new Integer(19), length);
|
||||
assertThat(length).isEqualTo(new Integer(19));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user