Added checkstyle for tests
This commit is contained in:
@@ -5,8 +5,8 @@ require './src/main/ruby/readme.rb'
|
||||
options = {:mkdirs => true, :safe => :unsafe, :attributes => ['linkcss', 'allow-uri-read']}
|
||||
|
||||
guard 'shell' do
|
||||
watch(/^src\/[A-Z-a-z][^#]*\.adoc$/) {|m|
|
||||
SpringCloud::Build.render_file('src/main/asciidoc/README.adoc', :to_file => './README.adoc')
|
||||
Asciidoctor.render_file('src/main/asciidoc/spring-cloud-cli.adoc', options.merge(:to_dir => 'target/generated-docs'))
|
||||
}
|
||||
watch(/^src\/[A-Z-a-z][^#]*\.adoc$/) {|m|
|
||||
SpringCloud::Build.render_file('src/main/asciidoc/README.adoc', :to_file => './README.adoc')
|
||||
Asciidoctor.render_file('src/main/asciidoc/spring-cloud-cli.adoc', options.merge(:to_dir => 'target/generated-docs'))
|
||||
}
|
||||
end
|
||||
|
||||
2
pom.xml
2
pom.xml
@@ -26,6 +26,8 @@
|
||||
<maven-checkstyle-plugin.failsOnError>true</maven-checkstyle-plugin.failsOnError>
|
||||
<maven-checkstyle-plugin.failsOnViolation>true
|
||||
</maven-checkstyle-plugin.failsOnViolation>
|
||||
<maven-checkstyle-plugin.includeTestSourceDirectory>true
|
||||
</maven-checkstyle-plugin.includeTestSourceDirectory>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
|
||||
@@ -1,3 +1,19 @@
|
||||
/*
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.adapter.aws;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -188,7 +188,7 @@ class Foo {
|
||||
Foo() {
|
||||
}
|
||||
|
||||
public Foo(String value) {
|
||||
Foo(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
@@ -217,7 +217,7 @@ class Bar {
|
||||
Bar() {
|
||||
}
|
||||
|
||||
public Bar(String value) {
|
||||
Bar(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.adapter.azure;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
@@ -36,14 +36,13 @@ import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.test.context.TestPropertySource;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Kamesh Sampath
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest()
|
||||
@SpringBootTest
|
||||
@EnableAutoConfiguration
|
||||
@TestPropertySource(locations = "classpath:/application-test.properties")
|
||||
public class OpenWhiskActionHandlerTest {
|
||||
@@ -65,9 +64,9 @@ public class OpenWhiskActionHandlerTest {
|
||||
actionRequest.setActionName("test_action");
|
||||
actionRequest.setValue(eventData);
|
||||
Object result = this.actionHandler.run(actionRequest);
|
||||
assertNotNull(result);
|
||||
assertEquals("{\"result\":{\"name\":\"Spring\",\"message\":\"Hello, Spring\"}}",
|
||||
result);
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result).isEqualTo(
|
||||
"{\"result\":{\"name\":\"Spring\",\"message\":\"Hello, Spring\"}}");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -78,8 +77,8 @@ public class OpenWhiskActionHandlerTest {
|
||||
OpenWhiskActionRequest actionRequest = new OpenWhiskActionRequest();
|
||||
actionRequest.setActionName("test_action");
|
||||
Object result = this.actionHandler.run(actionRequest);
|
||||
assertNotNull(result);
|
||||
assertEquals("{\"result\":\"No input provided\"}", result);
|
||||
assertThat(result).isNotNull();
|
||||
assertThat(result).isEqualTo("{\"result\":\"No input provided\"}");
|
||||
}
|
||||
|
||||
@Configuration
|
||||
|
||||
@@ -43,7 +43,7 @@ public class CompilationMessage {
|
||||
this.sourceCode = sourceCode;
|
||||
this.startPosition = startPosition;
|
||||
this.endPosition = endPosition;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the type of message
|
||||
@@ -84,7 +84,7 @@ public class CompilationMessage {
|
||||
StringBuilder s = new StringBuilder();
|
||||
s.append("==========\n");
|
||||
if (this.sourceCode != null) { // Cannot include source context if no source
|
||||
// available
|
||||
// available
|
||||
int[] lineStartEnd = getLineStartEnd(this.startPosition);
|
||||
s.append(this.sourceCode.substring(lineStartEnd[0], lineStartEnd[1]))
|
||||
.append("\n");
|
||||
|
||||
@@ -201,7 +201,7 @@ public final class InMemoryJavaFileObject implements JavaFileObject {
|
||||
InMemoryJavaFileObject.this.lastModifiedTime = System.currentTimeMillis();
|
||||
InMemoryJavaFileObject.this.content = new String(toCharArray())
|
||||
.getBytes(); // Ignoring encoding...
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ public class JrtEntryJavaFileObject implements JavaFileObject {
|
||||
*/
|
||||
public JrtEntryJavaFileObject(Path path) {
|
||||
this.pathToClassString = path.subpath(2, path.getNameCount()).toString(); // e.g.
|
||||
// java/lang/Object.class
|
||||
// java/lang/Object.class
|
||||
this.path = path;
|
||||
}
|
||||
|
||||
|
||||
@@ -127,8 +127,8 @@ public class JrtFsEnumeration implements Enumeration<JrtEntryJavaFileObject> {
|
||||
throws IOException {
|
||||
int fnc = file.getNameCount();
|
||||
if (fnc >= 3 && file.toString().endsWith(".class")) { // There is a preceeding
|
||||
// module name - e.g.
|
||||
// /modules/java.base/java/lang/Object.class
|
||||
// module name - e.g.
|
||||
// /modules/java.base/java/lang/Object.class
|
||||
// file.subpath(2, fnc); // e.g. java/lang/Object.class
|
||||
JrtFsEnumeration.this.jfos.add(new JrtEntryJavaFileObject(file));
|
||||
}
|
||||
|
||||
@@ -207,8 +207,8 @@ public class MemoryBasedJavaFileManager implements JavaFileManager {
|
||||
URL[] urls = loader.getURLs();
|
||||
if (urls.length > 1) { // heuristic that catches Maven surefire tests
|
||||
if (!urls[0].toString().startsWith("jar:file:")) { // heuristic for
|
||||
// Spring Boot fat
|
||||
// jar
|
||||
// Spring Boot fat
|
||||
// jar
|
||||
StringBuilder builder = new StringBuilder();
|
||||
for (URL url : urls) {
|
||||
if (builder.length() > 0) {
|
||||
@@ -627,7 +627,7 @@ public class MemoryBasedJavaFileManager implements JavaFileManager {
|
||||
if (file.getNameCount() > 3 && file.toString().endsWith(".class")) {
|
||||
int fnc = file.getNameCount();
|
||||
if (fnc > 3) { // There is a package name - e.g.
|
||||
// /modules/java.base/java/lang/Object.class
|
||||
// /modules/java.base/java/lang/Object.class
|
||||
Path packagePath = file.subpath(2, fnc - 1); // e.g. java/lang
|
||||
String packagePathString = packagePath.toString() + "/";
|
||||
CompilationInfoCache.this.packageCache.put(packagePathString,
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.compiler;
|
||||
|
||||
import java.io.File;
|
||||
@@ -42,15 +43,13 @@ import org.springframework.cloud.function.compiler.java.RuntimeJavaCompiler;
|
||||
import org.springframework.cloud.function.core.FunctionFactoryUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Tests that verify dependency resolution. Dependencies can be resolved against simple
|
||||
* classpath entries or against classes under BOOT-INF/classes or in a nested jar under
|
||||
* under BOOT-INF/lib. Finding classes in those locations enables compilation against a
|
||||
* packaged boot jar.
|
||||
*
|
||||
*
|
||||
* @author Andy Clement
|
||||
*/
|
||||
public class CompilerDependencyResolutionTests {
|
||||
@@ -60,7 +59,7 @@ public class CompilerDependencyResolutionTests {
|
||||
ClassDescriptor t1 = compile("Test1",
|
||||
"package com.test;\npublic class Test1 { public static String doit() { return \"T1\";}}\n");
|
||||
String result = (String) t1.clazz.getDeclaredMethod("doit").invoke(null);
|
||||
assertEquals("T1", result);
|
||||
assertThat(result).isEqualTo("T1");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,12 +139,12 @@ public class CompilerDependencyResolutionTests {
|
||||
"public class A {\n" + " public static Object run() {\n"
|
||||
+ " return new TestX();\n" + " }\n" + "}",
|
||||
jar.toURI().toString());
|
||||
assertTrue("Should be no problems: " + result.getCompilationMessages(),
|
||||
result.getCompilationMessages().isEmpty());
|
||||
assertThat(result.getCompilationMessages().isEmpty())
|
||||
.as("Should be no problems: " + result.getCompilationMessages()).isTrue();
|
||||
try (URLClassLoader cl = new TestClassLoader(tx, descriptorFromResult(result))) {
|
||||
Class<?> class1 = cl.loadClass("A");
|
||||
Object invoke = class1.getDeclaredMethod("run").invoke(null);
|
||||
assertEquals(tx.name, invoke.getClass().getName());
|
||||
assertThat(invoke.getClass().getName()).isEqualTo(tx.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -162,12 +161,12 @@ public class CompilerDependencyResolutionTests {
|
||||
"public class A {\n" + " public static Object run() {\n"
|
||||
+ " return new TestX();\n" + " }\n" + "}",
|
||||
jar.toURI().toString());
|
||||
assertTrue("Should be no problems: " + result.getCompilationMessages(),
|
||||
result.getCompilationMessages().isEmpty());
|
||||
assertThat(result.getCompilationMessages().isEmpty())
|
||||
.as("Should be no problems: " + result.getCompilationMessages()).isTrue();
|
||||
try (URLClassLoader cl = new TestClassLoader(t1, descriptorFromResult(result))) {
|
||||
Class<?> class1 = cl.loadClass("A");
|
||||
Object invoke = class1.getDeclaredMethod("run").invoke(null);
|
||||
assertEquals(t1.name, invoke.getClass().getName());
|
||||
assertThat(invoke.getClass().getName()).isEqualTo(t1.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,12 +184,12 @@ public class CompilerDependencyResolutionTests {
|
||||
"public class A {\n" + " public static Object run() {\n"
|
||||
+ " return new TestX();\n" + " }\n" + "}",
|
||||
jar2.toURI().toString());
|
||||
assertTrue("Should be no problems: " + result.getCompilationMessages(),
|
||||
result.getCompilationMessages().isEmpty());
|
||||
assertThat(result.getCompilationMessages().isEmpty())
|
||||
.as("Should be no problems: " + result.getCompilationMessages()).isTrue();
|
||||
try (URLClassLoader cl = new TestClassLoader(t1, descriptorFromResult(result))) {
|
||||
Class<?> class1 = cl.loadClass("A");
|
||||
Object invoke = class1.getDeclaredMethod("run").invoke(null);
|
||||
assertEquals(t1.name, invoke.getClass().getName());
|
||||
assertThat(invoke.getClass().getName()).isEqualTo(t1.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,12 +204,12 @@ public class CompilerDependencyResolutionTests {
|
||||
+ " public static Object run() {\n" + " return new Test1();\n"
|
||||
+ " }\n" + "}",
|
||||
jar.toURI().toString());
|
||||
assertTrue("Should be no problems: " + result.getCompilationMessages(),
|
||||
result.getCompilationMessages().isEmpty());
|
||||
assertThat(result.getCompilationMessages().isEmpty())
|
||||
.as("Should be no problems: " + result.getCompilationMessages()).isTrue();
|
||||
try (URLClassLoader cl = new TestClassLoader(t1, descriptorFromResult(result))) {
|
||||
Class<?> class1 = cl.loadClass("A");
|
||||
Object invoke = class1.getDeclaredMethod("run").invoke(null);
|
||||
assertEquals(t1.name, invoke.getClass().getName());
|
||||
assertThat(invoke.getClass().getName()).isEqualTo(t1.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -226,12 +225,12 @@ public class CompilerDependencyResolutionTests {
|
||||
+ " public static Object run() {\n" + " return new Test1();\n"
|
||||
+ " }\n" + "}",
|
||||
jar.toURI().toString());
|
||||
assertTrue("Should be no problems: " + result.getCompilationMessages(),
|
||||
result.getCompilationMessages().isEmpty());
|
||||
assertThat(result.getCompilationMessages().isEmpty())
|
||||
.as("Should be no problems: " + result.getCompilationMessages()).isTrue();
|
||||
try (URLClassLoader cl = new TestClassLoader(t1, descriptorFromResult(result))) {
|
||||
Class<?> class1 = cl.loadClass("A");
|
||||
Object invoke = class1.getDeclaredMethod("run").invoke(null);
|
||||
assertEquals(t1.name, invoke.getClass().getName());
|
||||
assertThat(invoke.getClass().getName()).isEqualTo(t1.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,12 +247,12 @@ public class CompilerDependencyResolutionTests {
|
||||
+ " public static Object run() {\n" + " return new Test1();\n"
|
||||
+ " }\n" + "}",
|
||||
jar2.toURI().toString());
|
||||
assertTrue("Should be no problems: " + result.getCompilationMessages(),
|
||||
result.getCompilationMessages().isEmpty());
|
||||
assertThat(result.getCompilationMessages().isEmpty())
|
||||
.as("Should be no problems: " + result.getCompilationMessages()).isTrue();
|
||||
try (URLClassLoader cl = new TestClassLoader(t1, descriptorFromResult(result))) {
|
||||
Class<?> class1 = cl.loadClass("A");
|
||||
Object invoke = class1.getDeclaredMethod("run").invoke(null);
|
||||
assertEquals(t1.name, invoke.getClass().getName());
|
||||
assertThat(invoke.getClass().getName()).isEqualTo(t1.name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -268,8 +267,8 @@ public class CompilerDependencyResolutionTests {
|
||||
private ClassDescriptor compile(String className, String classSourceCode) {
|
||||
CompilationResult compile = new RuntimeJavaCompiler().compile(className,
|
||||
classSourceCode);
|
||||
assertTrue("Should be empty: \n" + compile.getCompilationMessages(),
|
||||
compile.getCompilationMessages().isEmpty());
|
||||
assertThat(compile.getCompilationMessages().isEmpty())
|
||||
.as("Should be empty: \n" + compile.getCompilationMessages()).isTrue();
|
||||
Class<?> clazz = compile.getCompiledClasses().get(0);
|
||||
return new ClassDescriptor(clazz.getName(),
|
||||
compile.getClassBytes(clazz.getName()),
|
||||
@@ -299,7 +298,7 @@ public class CompilerDependencyResolutionTests {
|
||||
clazzes.add(prefix + classDescriptor.name.replace('.', '/') + ".class");
|
||||
}
|
||||
walkJar(jar, (entry) -> clazzes.remove(entry.getName()));
|
||||
assertTrue("Should be empty: " + clazzes, clazzes.isEmpty());
|
||||
assertThat(clazzes.isEmpty()).as("Should be empty: " + clazzes).isTrue();
|
||||
}
|
||||
|
||||
private void walkJar(File jar, Consumer<JarEntry> fn) {
|
||||
@@ -336,7 +335,7 @@ public class CompilerDependencyResolutionTests {
|
||||
|
||||
final Class<?> clazz;
|
||||
|
||||
public ClassDescriptor(String name, byte[] bytes, Class<?> clazz) {
|
||||
ClassDescriptor(String name, byte[] bytes, Class<?> clazz) {
|
||||
this.name = name;
|
||||
this.bytes = bytes;
|
||||
this.clazz = clazz;
|
||||
@@ -344,7 +343,7 @@ public class CompilerDependencyResolutionTests {
|
||||
|
||||
}
|
||||
|
||||
static class JarBuilder {
|
||||
static final class JarBuilder {
|
||||
|
||||
File jarFile;
|
||||
|
||||
@@ -446,7 +445,7 @@ public class CompilerDependencyResolutionTests {
|
||||
|
||||
ClassDescriptor[] descriptors;
|
||||
|
||||
public TestClassLoader(ClassDescriptor... descriptors) {
|
||||
TestClassLoader(ClassDescriptor... descriptors) {
|
||||
super(new URL[0], TestClassLoader.class.getClassLoader());
|
||||
this.descriptors = descriptors;
|
||||
}
|
||||
|
||||
@@ -23,8 +23,7 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Andy Clement
|
||||
@@ -37,7 +36,7 @@ public class RuntimeJavaCompilerTests {
|
||||
RuntimeJavaCompiler rjc = new RuntimeJavaCompiler();
|
||||
CompilationResult cr = rjc.compile("A", "public class A {}");
|
||||
List<CompilationMessage> compilationMessages = cr.getCompilationMessages();
|
||||
assertTrue(compilationMessages.isEmpty());
|
||||
assertThat(compilationMessages.isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,18 +51,19 @@ public class RuntimeJavaCompilerTests {
|
||||
+ " String message = (String) exp.getValue();"
|
||||
+ " return message;\n" + " }\n" + "}");
|
||||
List<CompilationMessage> compilationMessages = cr.getCompilationMessages();
|
||||
assertEquals(3, compilationMessages.size());
|
||||
assertTrue(
|
||||
compilationMessages.get(0).getMessage().contains("cannot find symbol"));
|
||||
assertTrue(compilationMessages.get(0).getMessage()
|
||||
.contains("class ExpressionParser"));
|
||||
assertTrue(
|
||||
compilationMessages.get(1).getMessage().contains("cannot find symbol"));
|
||||
assertTrue(compilationMessages.get(1).getMessage()
|
||||
.contains("class SpelExpressionParser"));
|
||||
assertTrue(
|
||||
compilationMessages.get(2).getMessage().contains("cannot find symbol"));
|
||||
assertTrue(compilationMessages.get(2).getMessage().contains("class Expression"));
|
||||
assertThat(compilationMessages.size()).isEqualTo(3);
|
||||
assertThat(compilationMessages.get(0).getMessage().contains("cannot find symbol"))
|
||||
.isTrue();
|
||||
assertThat(compilationMessages.get(0).getMessage()
|
||||
.contains("class ExpressionParser")).isTrue();
|
||||
assertThat(compilationMessages.get(1).getMessage().contains("cannot find symbol"))
|
||||
.isTrue();
|
||||
assertThat(compilationMessages.get(1).getMessage()
|
||||
.contains("class SpelExpressionParser")).isTrue();
|
||||
assertThat(compilationMessages.get(2).getMessage().contains("cannot find symbol"))
|
||||
.isTrue();
|
||||
assertThat(compilationMessages.get(2).getMessage().contains("class Expression"))
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -80,12 +80,12 @@ public class RuntimeJavaCompilerTests {
|
||||
+ " return message;\n" + " }\n" + "}",
|
||||
"maven://org.springframework:spring-expression:4.3.9.RELEASE");
|
||||
List<CompilationMessage> compilationMessages = cr.getCompilationMessages();
|
||||
assertTrue(compilationMessages.isEmpty());
|
||||
assertThat(compilationMessages.isEmpty()).isTrue();
|
||||
try (SimpleClassLoader cl = new SimpleClassLoader(
|
||||
this.getClass().getClassLoader())) {
|
||||
Class<?> clazz = cl.defineClass("A", cr.getClassBytes("A"));
|
||||
Supplier<String> supplier = (Supplier<String>) clazz.newInstance();
|
||||
assertEquals("Hello World", supplier.get());
|
||||
assertThat(supplier.get()).isEqualTo("Hello World");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,27 +100,27 @@ public class RuntimeJavaCompilerTests {
|
||||
CompilationResult cr = rjc.compile("A", source,
|
||||
"maven://joda-time:joda-time:2.9.9");
|
||||
List<CompilationMessage> compilationMessages = cr.getCompilationMessages();
|
||||
assertTrue(compilationMessages.isEmpty());
|
||||
assertThat(compilationMessages.isEmpty()).isTrue();
|
||||
List<File> resolvedAdditionalDependencies = cr
|
||||
.getResolvedAdditionalDependencies();
|
||||
try (SimpleClassLoader cl = new SimpleClassLoader(resolvedAdditionalDependencies,
|
||||
this.getClass().getClassLoader())) {
|
||||
Class<?> clazz = cl.defineClass("A", cr.getClassBytes("A"));
|
||||
Supplier<String> supplier = (Supplier<String>) clazz.newInstance();
|
||||
assertEquals("true", supplier.get());
|
||||
assertThat(supplier.get()).isEqualTo("true");
|
||||
}
|
||||
|
||||
cr = rjc.compile("A", source,
|
||||
"maven://org.springframework:spring-expression:4.3.9.RELEASE",
|
||||
"maven://joda-time:joda-time:2.9.9");
|
||||
compilationMessages = cr.getCompilationMessages();
|
||||
assertTrue(compilationMessages.isEmpty());
|
||||
assertThat(compilationMessages.isEmpty()).isTrue();
|
||||
resolvedAdditionalDependencies = cr.getResolvedAdditionalDependencies();
|
||||
try (SimpleClassLoader cl = new SimpleClassLoader(resolvedAdditionalDependencies,
|
||||
this.getClass().getClassLoader())) {
|
||||
Class<?> clazz = cl.defineClass("A", cr.getClassBytes("A"));
|
||||
Supplier<String> supplier = (Supplier<String>) clazz.newInstance();
|
||||
assertEquals("true", supplier.get());
|
||||
assertThat(supplier.get()).isEqualTo("true");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,43 +130,45 @@ public class RuntimeJavaCompilerTests {
|
||||
RuntimeJavaCompiler rjc = new RuntimeJavaCompiler();
|
||||
CompilationResult cr = rjc.compile("A", "public class A {}",
|
||||
"maven://org.springframework:spring-expression2:4.3.9.RELEASE"); // extra
|
||||
// '2'
|
||||
// in
|
||||
// there
|
||||
// '2'
|
||||
// in
|
||||
// there
|
||||
List<CompilationMessage> compilationMessages = cr.getCompilationMessages();
|
||||
assertEquals(1, compilationMessages.size());
|
||||
assertThat(compilationMessages.size()).isEqualTo(1);
|
||||
// ERROR:org.eclipse.aether.resolution.ArtifactResolutionException: Could not find
|
||||
// artifact org.springframework:spring-expression2:jar:4.3.9.RELEASE in
|
||||
// spring-snapshots (https://repo.spring.io/libs-snapshot)
|
||||
assertTrue(compilationMessages.get(0).getMessage().contains(
|
||||
"Could not find artifact org.springframework:spring-expression2:jar:4.3.9.RELEASE"));
|
||||
assertThat(compilationMessages.get(0).getMessage().contains(
|
||||
"Could not find artifact org.springframework:spring-expression2:jar:4.3.9.RELEASE"))
|
||||
.isTrue();
|
||||
|
||||
// Failure:
|
||||
rjc = new RuntimeJavaCompiler();
|
||||
cr = rjc.compile("A", "public class A {}",
|
||||
"trouble://org.springframework:spring-expression:4.3.9.RELEASE"); // rogue
|
||||
// prefix
|
||||
// (should
|
||||
// be
|
||||
// "maven:")
|
||||
// prefix
|
||||
// (should
|
||||
// be
|
||||
// "maven:")
|
||||
compilationMessages = cr.getCompilationMessages();
|
||||
assertEquals(1, compilationMessages.size());
|
||||
assertTrue(compilationMessages.get(0).toString(), compilationMessages.get(0)
|
||||
.getMessage().contains("Unrecognized dependency: "));
|
||||
assertThat(compilationMessages.size()).isEqualTo(1);
|
||||
assertThat(compilationMessages.get(0).getMessage()
|
||||
.contains("Unrecognized dependency: "))
|
||||
.as(compilationMessages.get(0).toString()).isTrue();
|
||||
|
||||
// Success
|
||||
rjc = new RuntimeJavaCompiler();
|
||||
cr = rjc.compile("A", "public class A {}", "maven://joda-time:joda-time:2.9.9");
|
||||
compilationMessages = cr.getCompilationMessages();
|
||||
assertEquals(0, compilationMessages.size());
|
||||
assertThat(compilationMessages.size()).isEqualTo(0);
|
||||
List<File> resolvedAdditionalDependencies = cr
|
||||
.getResolvedAdditionalDependencies();
|
||||
assertEquals(1, resolvedAdditionalDependencies.size());
|
||||
assertTrue(
|
||||
"Expected this to end with 'joda-time-2.9.9.jar': "
|
||||
+ resolvedAdditionalDependencies.get(0).toString(),
|
||||
resolvedAdditionalDependencies.get(0).toString()
|
||||
.endsWith("joda-time-2.9.9.jar"));
|
||||
assertThat(resolvedAdditionalDependencies.size()).isEqualTo(1);
|
||||
assertThat(resolvedAdditionalDependencies.get(0).toString()
|
||||
.endsWith("joda-time-2.9.9.jar"))
|
||||
.as("Expected this to end with 'joda-time-2.9.9.jar': "
|
||||
+ resolvedAdditionalDependencies.get(0).toString())
|
||||
.isTrue();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -87,7 +87,8 @@ public class ByteCodeLoadingFunctionTests {
|
||||
|
||||
@Test
|
||||
public void compileFluxFunction() throws Exception {
|
||||
CompiledFunctionFactory<Function<Flux<String>, Flux<String>>> compiled = new FunctionCompiler<Flux<String>, Flux<String>>(
|
||||
CompiledFunctionFactory<Function<Flux<String>, Flux<String>>> compiled = null;
|
||||
compiled = new FunctionCompiler<Flux<String>, Flux<String>>(
|
||||
String.class.getName()).compile("foos",
|
||||
"flux -> flux.map(v -> v.toUpperCase())", "Flux<String>",
|
||||
"Flux<String>");
|
||||
|
||||
@@ -5,4 +5,4 @@
|
||||
<root level="INFO">
|
||||
<appender-ref ref="CONSOLE"/>
|
||||
</root>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.context;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.context;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
@@ -24,10 +24,7 @@ import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.cloud.function.core.FluxFunction;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -43,7 +40,7 @@ public class InMemoryFunctionCatalogTests {
|
||||
InMemoryFunctionCatalog catalog = new InMemoryFunctionCatalog();
|
||||
catalog.register(registration);
|
||||
FunctionRegistration<?> registration2 = catalog.getRegistration(function);
|
||||
assertSame(registration, registration2);
|
||||
assertThat(registration2).isSameAs(registration);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -55,11 +52,11 @@ public class InMemoryFunctionCatalogTests {
|
||||
catalog.register(registration);
|
||||
|
||||
Object lookedUpFunction = catalog.lookup("hello");
|
||||
assertNull(lookedUpFunction);
|
||||
assertThat(lookedUpFunction).isNull();
|
||||
|
||||
lookedUpFunction = catalog.lookup("foo");
|
||||
assertNotNull(lookedUpFunction);
|
||||
assertTrue(lookedUpFunction instanceof FluxFunction);
|
||||
assertThat(lookedUpFunction).isNotNull();
|
||||
assertThat(lookedUpFunction instanceof FluxFunction).isTrue();
|
||||
}
|
||||
|
||||
private static class TestFunction implements Function<Integer, String> {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -132,7 +131,7 @@ public class ContextFunctionPostProcessorTests {
|
||||
System.out::println, "consumer"));
|
||||
Supplier<Mono<Void>> supplier = (Supplier<Mono<Void>>) this.processor
|
||||
.lookupSupplier("supplier|consumer");
|
||||
assertNull(supplier.get().block());
|
||||
assertThat(supplier.get().block()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -36,7 +36,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
// @checkstyle:off
|
||||
@FunctionalSpringBootTest(classes = Object.class, properties = "spring.main.sources=org.springframework.cloud.function.context.string.FunctionalStringSourceTests.TestConfiguration")
|
||||
// @checkstyle:on
|
||||
public class FunctionalStringSourceTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.inject;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.util;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
@@ -25,7 +25,7 @@ public class Emitter implements Supplier<String> {
|
||||
|
||||
private int i = 0;
|
||||
|
||||
private String[] values = { "one", "two", "three", "four" };
|
||||
private String[] values = {"one", "two", "three", "four"};
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.io.IOException;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
// @checkstyle:off
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
* @author Dave Syer
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2019-2018 the original author or authors.
|
||||
* Copyright 2012-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.deployer;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = FunctionDeployerConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@TestPropertySource(properties = {
|
||||
"function.location=file:target/it/support/target/function-sample-1.0.0.M1-exec.jar", })
|
||||
"function.location=file:target/it/support/target/function-sample-1.0.0.M1-exec.jar" })
|
||||
public abstract class SpringFunctionAppConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -39,7 +39,7 @@ import static org.hamcrest.Matchers.containsString;
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest(classes = FunctionDeployerConfiguration.class, webEnvironment = SpringBootTest.WebEnvironment.NONE)
|
||||
@TestPropertySource(properties = {
|
||||
"function.location=file:target/it/support/target/dependency", })
|
||||
"function.location=file:target/it/support/target/dependency" })
|
||||
public abstract class SpringFunctionAppExplodedConfigurationTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -98,10 +98,10 @@ class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo() {
|
||||
Foo() {
|
||||
}
|
||||
|
||||
public Foo(String value) {
|
||||
Foo(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,4 +11,4 @@ Start-Class: org.springframework.cloud.function.test.FunctionApp
|
||||
Created-By: Apache Maven 3.5.0
|
||||
Build-Jdk: 1.8.0_131
|
||||
Implementation-URL: http://projects.spring.io/spring-boot/function-sam
|
||||
ple/
|
||||
ple/
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.function.context.config.KotlinLambdaToFunctionAutoConfiguration
|
||||
org.springframework.cloud.function.context.config.KotlinLambdaToFunctionAutoConfiguration
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.function.task.TaskConfiguration
|
||||
org.springframework.cloud.function.task.TaskConfiguration
|
||||
|
||||
@@ -35,10 +35,6 @@ public final class HeaderUtils {
|
||||
|
||||
private static HttpHeaders REQUEST_ONLY = new HttpHeaders();
|
||||
|
||||
private HeaderUtils() {
|
||||
throw new IllegalStateException("Can't instantiate a utility class");
|
||||
}
|
||||
|
||||
static {
|
||||
IGNORED.add(MessageHeaders.ID, "");
|
||||
IGNORED.add(HttpHeaders.CONTENT_LENGTH, "0");
|
||||
@@ -49,6 +45,10 @@ public final class HeaderUtils {
|
||||
REQUEST_ONLY.add(HttpHeaders.HOST, "");
|
||||
}
|
||||
|
||||
private HeaderUtils() {
|
||||
throw new IllegalStateException("Can't instantiate a utility class");
|
||||
}
|
||||
|
||||
public static HttpHeaders fromMessage(MessageHeaders headers) {
|
||||
HttpHeaders result = new HttpHeaders();
|
||||
for (String name : headers.keySet()) {
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.flux;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -62,7 +63,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
// @checkstyle:off
|
||||
@SpringBootTest(classes = TestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=reactive")
|
||||
// @checkstyle:on
|
||||
public class FluxRestApplicationTests {
|
||||
|
||||
private static final MediaType EVENT_STREAM = MediaType.valueOf("text/event-stream");
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.mvc;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -60,7 +61,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
// @checkstyle:off
|
||||
@SpringBootTest(classes = TestConfiguration.class, webEnvironment = WebEnvironment.RANDOM_PORT, properties = "spring.main.web-application-type=servlet")
|
||||
// @checkstyle:on
|
||||
@RunWith(SpringRunner.class)
|
||||
public class MvcRestApplicationTests {
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.springframework.cloud.function.context.test.FunctionalSpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.reactive.server.WebTestClient;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -52,9 +52,9 @@ public class FunctionalWithInputSetTests {
|
||||
String.class)
|
||||
.exchange().expectStatus().isOk().expectBody(String.class).returnResult()
|
||||
.getResponseBody();
|
||||
assertTrue(reply.contains("FOO"));
|
||||
assertTrue(reply.contains("BAR"));
|
||||
assertTrue(reply.contains("{\"value\":\""));
|
||||
assertThat(reply.contains("FOO")).isTrue();
|
||||
assertThat(reply.contains("BAR")).isTrue();
|
||||
assertThat(reply.contains("{\"value\":\"")).isTrue();
|
||||
}
|
||||
|
||||
@SpringBootConfiguration
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.test;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
@@ -74,10 +74,10 @@ class Foo {
|
||||
|
||||
private String value;
|
||||
|
||||
public Foo() {
|
||||
Foo() {
|
||||
}
|
||||
|
||||
public Foo(String value) {
|
||||
Foo(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.web.flux;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -37,8 +38,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -62,20 +62,20 @@ public class HeadersToMessageTests {
|
||||
.exchange(RequestEntity.post(new URI("/functions/employee"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
|
||||
assertEquals("application/xml",
|
||||
postForEntity.getHeaders().get("x-content-type").get(0));
|
||||
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
|
||||
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
|
||||
assertThat(postForEntity.getHeaders().containsKey("x-content-type")).isTrue();
|
||||
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
|
||||
.isEqualTo("application/xml");
|
||||
assertThat(postForEntity.getHeaders().get("foo").get(0)).isEqualTo("bar");
|
||||
|
||||
// test simple type payload
|
||||
postForEntity = this.rest.postForEntity(new URI("/functions/string"),
|
||||
"{\"name\":\"Bob\",\"age\":25}", String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
|
||||
assertEquals("application/xml",
|
||||
postForEntity.getHeaders().get("x-content-type").get(0));
|
||||
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
|
||||
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
|
||||
assertThat(postForEntity.getHeaders().containsKey("x-content-type")).isTrue();
|
||||
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
|
||||
.isEqualTo("application/xml");
|
||||
assertThat(postForEntity.getHeaders().get("foo").get(0)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.web.flux;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.web.flux;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.web.mvc;
|
||||
|
||||
import java.net.URI;
|
||||
@@ -39,8 +40,7 @@ import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
@@ -62,11 +62,11 @@ public class HeadersToMessageTests {
|
||||
.exchange(RequestEntity.post(new URI("/functions/employee"))
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25}", postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-content-type"));
|
||||
assertEquals("application/xml",
|
||||
postForEntity.getHeaders().get("x-content-type").get(0));
|
||||
assertEquals("bar", postForEntity.getHeaders().get("foo").get(0));
|
||||
assertThat(postForEntity.getBody()).isEqualTo("{\"name\":\"Bob\",\"age\":25}");
|
||||
assertThat(postForEntity.getHeaders().containsKey("x-content-type")).isTrue();
|
||||
assertThat(postForEntity.getHeaders().get("x-content-type").get(0))
|
||||
.isEqualTo("application/xml");
|
||||
assertThat(postForEntity.getHeaders().get("foo").get(0)).isEqualTo("bar");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,10 +76,11 @@ public class HeadersToMessageTests {
|
||||
.contentType(MediaType.APPLICATION_JSON)
|
||||
.header("x-context-type", "rubbish")
|
||||
.body("{\"name\":\"Bob\",\"age\":25}"), String.class);
|
||||
assertEquals("{\"name\":\"Bob\",\"age\":25,\"foo\":\"bar\"}",
|
||||
postForEntity.getBody());
|
||||
assertTrue(postForEntity.getHeaders().containsKey("x-context-type"));
|
||||
assertEquals("rubbish", postForEntity.getHeaders().get("x-context-type").get(0));
|
||||
assertThat(postForEntity.getBody())
|
||||
.isEqualTo("{\"name\":\"Bob\",\"age\":25,\"foo\":\"bar\"}");
|
||||
assertThat(postForEntity.getHeaders().containsKey("x-context-type")).isTrue();
|
||||
assertThat(postForEntity.getHeaders().get("x-context-type").get(0))
|
||||
.isEqualTo("rubbish");
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.web.mvc;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.cloud.function.web.mvc;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
@@ -1 +1 @@
|
||||
provides: spring-cloud-function-context
|
||||
provides: spring-cloud-function-context
|
||||
|
||||
@@ -1 +1 @@
|
||||
provides: spring-cloud-function-context
|
||||
provides: spring-cloud-function-context
|
||||
|
||||
Reference in New Issue
Block a user