Turned on checkstyle
This commit is contained in:
@@ -11,8 +11,8 @@ buildscript {
|
||||
maven { url "https://repo.spring.io/snapshot" }
|
||||
maven { url "https://repo.spring.io/milestone" }
|
||||
}
|
||||
dependencies {
|
||||
classpath "com.github.jengelman.gradle.plugins:shadow:${shadowVersion}"
|
||||
dependencies {
|
||||
classpath "com.github.jengelman.gradle.plugins:shadow:${shadowVersion}"
|
||||
classpath("org.springframework.boot.experimental:spring-boot-thin-gradle-plugin:${wrapperVersion}")
|
||||
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
|
||||
}
|
||||
@@ -40,39 +40,40 @@ repositories {
|
||||
|
||||
ext {
|
||||
springCloudFunctionVersion = "2.0.0.BUILD-SNAPSHOT"
|
||||
awsLambdaEventsVersion = "1.2.1"
|
||||
awsLambdaCoreVersion = "1.1.0"
|
||||
awsLambdaEventsVersion = "1.2.1"
|
||||
awsLambdaCoreVersion = "1.1.0"
|
||||
}
|
||||
ext['reactor.version'] = "3.1.7.RELEASE"
|
||||
|
||||
assemble.dependsOn = [shadowJar, thinJar]
|
||||
|
||||
jar {
|
||||
manifest {
|
||||
attributes 'Main-Class': 'example.Config'
|
||||
}
|
||||
manifest {
|
||||
attributes 'Main-Class': 'example.Config'
|
||||
}
|
||||
}
|
||||
|
||||
import com.github.jengelman.gradle.plugins.shadow.transformers.*
|
||||
|
||||
shadowJar {
|
||||
classifier = 'aws'
|
||||
dependencies {
|
||||
exclude(dependency("org.springframework.cloud:spring-cloud-function-web:${springCloudFunctionVersion}"))
|
||||
}
|
||||
// Required for Spring
|
||||
mergeServiceFiles()
|
||||
append 'META-INF/spring.handlers'
|
||||
append 'META-INF/spring.schemas'
|
||||
append 'META-INF/spring.tooling'
|
||||
transform(PropertiesFileTransformer) {
|
||||
paths = ['META-INF/spring.factories' ]
|
||||
mergeStrategy = "append"
|
||||
}
|
||||
classifier = 'aws'
|
||||
dependencies {
|
||||
exclude(
|
||||
dependency("org.springframework.cloud:spring-cloud-function-web:${springCloudFunctionVersion}"))
|
||||
}
|
||||
// Required for Spring
|
||||
mergeServiceFiles()
|
||||
append 'META-INF/spring.handlers'
|
||||
append 'META-INF/spring.schemas'
|
||||
append 'META-INF/spring.tooling'
|
||||
transform(PropertiesFileTransformer) {
|
||||
paths = ['META-INF/spring.factories']
|
||||
mergeStrategy = "append"
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
testCompile.extendsFrom(compileOnly)
|
||||
testCompile.extendsFrom(compileOnly)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.spring.sample</groupId>
|
||||
@@ -15,7 +16,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@@ -24,7 +25,8 @@
|
||||
<java.version>1.8</java.version>
|
||||
<wrapper.version>1.0.17.RELEASE</wrapper.version>
|
||||
<aws-lambda-events.version>2.0.2</aws-lambda-events.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT
|
||||
</spring-cloud-function.version>
|
||||
<start-class>example.Config</start-class>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* 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,
|
||||
@@ -27,6 +27,7 @@ import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
@EnableConfigurationProperties(Properties.class)
|
||||
public class Config implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
@@ -40,14 +41,14 @@ public class Config implements ApplicationContextInitializer<GenericApplicationC
|
||||
this.props = props;
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
FunctionalSpringApplication.run(Config.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<Foo, Bar> function() {
|
||||
return value -> new Bar(
|
||||
value.uppercase() + (props.getFoo() != null ? "-" + props.getFoo() : ""));
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
FunctionalSpringApplication.run(Config.class, args);
|
||||
value.uppercase() + (this.props.getFoo() != null ? "-" + this.props.getFoo() : ""));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,6 +62,7 @@ public class Config implements ApplicationContextInitializer<GenericApplicationC
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
class Foo {
|
||||
|
||||
@@ -69,25 +71,26 @@ class Foo {
|
||||
Foo() {
|
||||
}
|
||||
|
||||
public String lowercase() {
|
||||
return value.toLowerCase();
|
||||
}
|
||||
|
||||
public Foo(String value) {
|
||||
Foo(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String lowercase() {
|
||||
return this.value.toLowerCase();
|
||||
}
|
||||
|
||||
public String uppercase() {
|
||||
return value.toUpperCase();
|
||||
return this.value.toUpperCase();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Bar {
|
||||
@@ -97,12 +100,12 @@ class Bar {
|
||||
Bar() {
|
||||
}
|
||||
|
||||
public Bar(String value) {
|
||||
Bar(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* 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,
|
||||
@@ -18,16 +18,21 @@ package example;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
|
||||
|
||||
// @checkstyle:off
|
||||
@ConfigurationProperties("app")
|
||||
public class Properties {
|
||||
|
||||
public String foo;
|
||||
|
||||
public String getFoo() {
|
||||
return foo;
|
||||
return this.foo;
|
||||
}
|
||||
|
||||
public void setFoo(String foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
log4j.rootCategory=DEBUG, LAMBDA
|
||||
|
||||
PID=????
|
||||
LOG_LEVEL_PATTERN=%5p
|
||||
LOG_PATTERN=[%d{yyyy-MM-dd HH:mm:ss.SSS}] boot%X{context} - ${PID} ${LOG_LEVEL_PATTERN} [%t] --- %c{1}: %m%n
|
||||
|
||||
# CONSOLE is set to be a ConsoleAppender using a PatternLayout.
|
||||
log4j.appender.LAMBDA=com.amazonaws.services.lambda.runtime.log4j.LambdaAppender
|
||||
log4j.appender.LAMBDA.layout=org.apache.log4j.PatternLayout
|
||||
log4j.appender.LAMBDA.layout.conversionPattern=${LOG_PATTERN}
|
||||
|
||||
log4j.category.org.apache.catalina.startup.DigesterFactory=ERROR
|
||||
log4j.category.org.apache.catalina.util.LifecycleBase=ERROR
|
||||
log4j.category.org.apache.coyote.http11.Http11NioProtocol=WARN
|
||||
@@ -20,4 +17,4 @@ log4j.category.org.eclipse.jetty.util.component.AbstractLifeCycle=ERROR
|
||||
log4j.category.org.hibernate.validator.internal.util.Version=WARN
|
||||
log4j.category.org.springframework.boot.actuate.autoconfigure.CrshAutoConfiguration=WARN
|
||||
log4j.category.org.springframework.boot.actuate.endpoint.jmx=WARN
|
||||
log4j.category.org.thymeleaf=WARN
|
||||
log4j.category.org.thymeleaf=WARN
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -36,7 +36,8 @@ public class MapTests {
|
||||
|
||||
@Test
|
||||
public void start() throws Exception {
|
||||
SpringBootRequestHandler<Object, Object> handler = new SpringBootRequestHandler<>(Config.class);
|
||||
SpringBootRequestHandler<Object, Object> handler = new SpringBootRequestHandler<>(
|
||||
Config.class);
|
||||
handler.handleRequest(new Foo("foo"), null);
|
||||
handler.close();
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.spring.sample</groupId>
|
||||
@@ -14,7 +15,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath /> <!-- lookup parent from repository -->
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@@ -24,7 +25,8 @@
|
||||
<functionAppName>function-sample-azure</functionAppName>
|
||||
<functionAppRegion>westus</functionAppRegion>
|
||||
<functionResourceGroup>java-function-group</functionResourceGroup>
|
||||
<stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}</stagingDirectory>
|
||||
<stagingDirectory>${project.build.directory}/azure-functions/${functionAppName}
|
||||
</stagingDirectory>
|
||||
<start-class>example.Config</start-class>
|
||||
<wrapper.version>1.0.15.RELEASE</wrapper.version>
|
||||
</properties>
|
||||
@@ -92,11 +94,11 @@
|
||||
<artifactId>azure-functions-maven-plugin</artifactId>
|
||||
<version>1.0.0-beta-7</version>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>javax.xml.bind</groupId>
|
||||
<artifactId>jaxb-api</artifactId>
|
||||
<version>2.3.1</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</plugin>
|
||||
</plugins>
|
||||
@@ -168,11 +170,13 @@
|
||||
</goals>
|
||||
<configuration>
|
||||
<overwrite>true</overwrite>
|
||||
<outputDirectory>${project.build.directory}/azure-functions/${functionAppName}
|
||||
<outputDirectory>
|
||||
${project.build.directory}/azure-functions/${functionAppName}
|
||||
</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${project.basedir}/src/main/azure</directory>
|
||||
<directory>${project.basedir}/src/main/azure
|
||||
</directory>
|
||||
<includes>
|
||||
<include>**</include>
|
||||
</includes>
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
{
|
||||
"IsEncrypted": false,
|
||||
"Values": {
|
||||
"AzureWebJobsStorage": "",
|
||||
"AzureWebJobsDashboard": "",
|
||||
"FUNCTIONS_WORKER_RUNTIME": "java"
|
||||
}
|
||||
"IsEncrypted": false,
|
||||
"Values": {
|
||||
"AzureWebJobsStorage": "",
|
||||
"AzureWebJobsDashboard": "",
|
||||
"FUNCTIONS_WORKER_RUNTIME": "java"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* 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,
|
||||
@@ -22,6 +22,7 @@ import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
public class Config {
|
||||
|
||||
@@ -33,7 +34,9 @@ public class Config {
|
||||
public Function<Foo, Bar> uppercase() {
|
||||
return foo -> new Bar(foo.getValue().toUpperCase());
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
class Foo {
|
||||
|
||||
@@ -42,25 +45,26 @@ class Foo {
|
||||
Foo() {
|
||||
}
|
||||
|
||||
public String lowercase() {
|
||||
return value.toLowerCase();
|
||||
}
|
||||
|
||||
public Foo(String value) {
|
||||
Foo(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String lowercase() {
|
||||
return this.value.toLowerCase();
|
||||
}
|
||||
|
||||
public String uppercase() {
|
||||
return value.toUpperCase();
|
||||
return this.value.toUpperCase();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Bar {
|
||||
@@ -70,16 +74,16 @@ class Bar {
|
||||
Bar() {
|
||||
}
|
||||
|
||||
public Bar(String value) {
|
||||
Bar(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
* 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,
|
||||
@@ -28,6 +28,7 @@ import org.springframework.cloud.function.adapter.azure.AzureSpringBootRequestHa
|
||||
* @author Soby Chacko
|
||||
*/
|
||||
public class FooHandler extends AzureSpringBootRequestHandler<Foo, Bar> {
|
||||
|
||||
@FunctionName("uppercase")
|
||||
public Bar execute(
|
||||
@HttpTrigger(name = "req", methods = { HttpMethod.GET,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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.
|
||||
|
||||
@@ -39,9 +39,9 @@ ext {
|
||||
ext['reactor.version'] = "3.1.7.RELEASE"
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.spring.sample</groupId>
|
||||
@@ -19,7 +20,8 @@
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT
|
||||
</spring-cloud-function.version>
|
||||
<reactor.version>3.1.2.RELEASE</reactor.version>
|
||||
<wrapper.version>1.0.17.RELEASE</wrapper.version>
|
||||
</properties>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -19,10 +19,13 @@ package com.example;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
public class SampleApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -44,7 +44,7 @@ public class SampleCompiledConsumerTests {
|
||||
@Test
|
||||
public void print() {
|
||||
assertThat(new TestRestTemplate().postForObject(
|
||||
"http://localhost:" + port + "/test", "it works", String.class)).isNull();
|
||||
"http://localhost:" + this.port + "/test", "it works", String.class)).isNull();
|
||||
assertEquals("it works", Reference.instance);
|
||||
}
|
||||
|
||||
@@ -55,5 +55,7 @@ public class SampleCompiledConsumerTests {
|
||||
public static void set(Object o) {
|
||||
instance = o;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -43,7 +43,7 @@ public class SampleCompiledFunctionTests {
|
||||
@Test
|
||||
public void lowercase() {
|
||||
assertThat(new TestRestTemplate().postForObject(
|
||||
"http://localhost:" + port + "/test", "it works", String.class))
|
||||
"http://localhost:" + this.port + "/test", "it works", String.class))
|
||||
.contains("it works!!!");
|
||||
}
|
||||
|
||||
|
||||
@@ -39,9 +39,9 @@ ext {
|
||||
ext['reactor.version'] = "3.1.7.RELEASE"
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.spring.sample</groupId>
|
||||
@@ -13,7 +14,7 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath />
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
@@ -21,7 +22,8 @@
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<reactor.version>3.1.2.RELEASE</reactor.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT
|
||||
</spring-cloud-function.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -19,10 +19,13 @@ package functions;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -18,9 +18,12 @@ package functions;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
// @checkstyle:off
|
||||
public class Greeter implements Function<String, String> {
|
||||
|
||||
public String apply(String name) {
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -39,9 +39,9 @@ ext {
|
||||
ext['reactor.version'] = "3.1.7.RELEASE"
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.spring.sample</groupId>
|
||||
@@ -14,12 +15,13 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.1.2.RELEASE</version>
|
||||
<relativePath />
|
||||
<relativePath/>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT
|
||||
</spring-cloud-function.version>
|
||||
<wrapper.version>1.0.17.RELEASE</wrapper.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -18,11 +18,11 @@ package com.example;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2016 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 com.example;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -20,25 +21,26 @@ import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
public class SampleApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<Foo, Bar> uppercase() {
|
||||
return value -> new Bar(value.uppercase());
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<MultiValueMap<String, String>, Map<String, Integer>> sum() {
|
||||
return multiValueMap -> {
|
||||
@@ -55,6 +57,7 @@ public class SampleApplication {
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
class Foo {
|
||||
|
||||
@@ -63,25 +66,26 @@ class Foo {
|
||||
Foo() {
|
||||
}
|
||||
|
||||
public String lowercase() {
|
||||
return value.toLowerCase();
|
||||
}
|
||||
|
||||
public Foo(String value) {
|
||||
Foo(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String lowercase() {
|
||||
return this.value.toLowerCase();
|
||||
}
|
||||
|
||||
public String uppercase() {
|
||||
return value.toUpperCase();
|
||||
return this.value.toUpperCase();
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class Bar {
|
||||
@@ -91,12 +95,12 @@ class Bar {
|
||||
Bar() {
|
||||
}
|
||||
|
||||
public Bar(String value) {
|
||||
Bar(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public void setValue(String value) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
spring.cloud.stream.bindings.input.destination: foos
|
||||
spring.cloud.stream.bindings.output.destination: bars
|
||||
spring.cloud.function.stream.processor.name: uppercase
|
||||
management.security.enabled: false
|
||||
spring.cloud.stream.bindings.input.destination:foos
|
||||
spring.cloud.stream.bindings.output.destination:bars
|
||||
spring.cloud.function.stream.processor.name:uppercase
|
||||
management.security.enabled:false
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-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.
|
||||
@@ -15,12 +15,11 @@
|
||||
*/
|
||||
package com.example;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.net.URI;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
|
||||
@@ -30,6 +29,8 @@ import org.springframework.http.RequestEntity;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*/
|
||||
@@ -38,13 +39,14 @@ import org.springframework.test.context.junit4.SpringRunner;
|
||||
public class SampleApplicationMvcTests {
|
||||
|
||||
@Autowired
|
||||
private TestRestTemplate rest;
|
||||
private TestRestTemplate rest;
|
||||
|
||||
@Test
|
||||
public void words() throws Exception {
|
||||
ResponseEntity<String> result = rest.exchange(RequestEntity.get(new URI("/words"))
|
||||
.accept(MediaType.APPLICATION_JSON).build(), String.class);
|
||||
assertThat(result.getBody()).isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
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\"}]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-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.
|
||||
@@ -19,7 +19,6 @@ import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
@@ -48,43 +47,45 @@ public class SampleApplicationTests {
|
||||
|
||||
@LocalServerPort
|
||||
private int port;
|
||||
|
||||
private TestRestTemplate rest = new TestRestTemplate();
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
this.headers = new HttpHeaders();
|
||||
this.headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void words() {
|
||||
assertThat(rest.getForObject("http://localhost:" + port + "/words", String.class))
|
||||
assertThat(this.rest.getForObject("http://localhost:" + this.port + "/words", String.class))
|
||||
.isEqualTo("[{\"value\":\"foo\"},{\"value\":\"bar\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uppercase() {
|
||||
assertThat(rest.postForObject("http://localhost:" + port + "/uppercase",
|
||||
new HttpEntity<>("[{\"value\":\"foo\"}]", headers), String.class))
|
||||
assertThat(this.rest.postForObject("http://localhost:" + this.port + "/uppercase",
|
||||
new HttpEntity<>("[{\"value\":\"foo\"}]", this.headers), String.class))
|
||||
.isEqualTo("[{\"value\":\"FOO\"}]");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void composite() {
|
||||
assertThat(rest.getForObject("http://localhost:" + 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(rest.postForObject("http://localhost:" + port + "/uppercase",
|
||||
new HttpEntity<>("{\"value\":\"foo\"}", headers), String.class)).isEqualTo("{\"value\":\"FOO\"}");
|
||||
assertThat(this.rest.postForObject("http://localhost:" + this.port + "/uppercase",
|
||||
new HttpEntity<>("{\"value\":\"foo\"}", this.headers), String.class))
|
||||
.isEqualTo("{\"value\":\"FOO\"}");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lowercase() {
|
||||
assertThat(rest.postForObject("http://localhost:" + port + "/lowercase",
|
||||
new HttpEntity<>("[{\"value\":\"Foo\"}]", headers), String.class))
|
||||
assertThat(this.rest.postForObject("http://localhost:" + this.port + "/lowercase",
|
||||
new HttpEntity<>("[{\"value\":\"Foo\"}]", this.headers), String.class))
|
||||
.isEqualTo("[{\"value\":\"foo\"}]");
|
||||
}
|
||||
|
||||
@@ -96,8 +97,8 @@ public class SampleApplicationTests {
|
||||
map.put("A", Arrays.asList("1", "2", "3"));
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(rest.exchange(
|
||||
RequestEntity.post(new URI("http://localhost:" + port + "/sum"))
|
||||
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}]");
|
||||
@@ -112,9 +113,11 @@ public class SampleApplicationTests {
|
||||
map.put("A", Arrays.asList("1", "2", "3"));
|
||||
map.put("B", Arrays.asList("5", "6"));
|
||||
|
||||
assertThat(rest.exchange(
|
||||
RequestEntity.post(new URI("http://localhost:" + port + "/sum")).accept(MediaType.APPLICATION_JSON)
|
||||
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}]");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ ext {
|
||||
ext['reactor.version'] = "3.1.7.RELEASE"
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.spring.sample</groupId>
|
||||
@@ -19,7 +20,8 @@
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT
|
||||
</spring-cloud-function.version>
|
||||
<wrapper.version>1.0.10.RELEASE</wrapper.version>
|
||||
<reactor.version>3.1.2.RELEASE</reactor.version>
|
||||
</properties>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -19,10 +19,13 @@ package com.example;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
public class SampleApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -4,7 +4,7 @@ spring:
|
||||
task:
|
||||
supplier: words
|
||||
function: uppercase
|
||||
consumer: print
|
||||
consumer: print
|
||||
compile:
|
||||
words:
|
||||
type: supplier
|
||||
|
||||
@@ -38,9 +38,9 @@ ext {
|
||||
}
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
imports {
|
||||
mavenBom "org.springframework.cloud:spring-cloud-function-dependencies:${springCloudFunctionVersion}"
|
||||
}
|
||||
}
|
||||
|
||||
dependencies {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>io.spring.sample</groupId>
|
||||
@@ -19,7 +20,8 @@
|
||||
|
||||
<properties>
|
||||
<java.version>1.8</java.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT</spring-cloud-function.version>
|
||||
<spring-cloud-function.version>2.0.2.BUILD-SNAPSHOT
|
||||
</spring-cloud-function.version>
|
||||
<wrapper.version>1.0.17.RELEASE</wrapper.version>
|
||||
</properties>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-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.
|
||||
@@ -19,6 +19,8 @@ package com.example;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.cloud.function.compiler.FunctionCompiler;
|
||||
@@ -26,11 +28,14 @@ import org.springframework.cloud.function.compiler.proxy.LambdaCompilingFunction
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
// @checkstyle:off
|
||||
@SpringBootApplication
|
||||
public class SampleApplication {
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> uppercase() {
|
||||
return value -> value.toUpperCase();
|
||||
@@ -52,17 +57,21 @@ public class SampleApplication {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public Function<String, String> compiledUppercase(FunctionCompiler<String, String> compiler) {
|
||||
public Function<String, String> compiledUppercase(
|
||||
FunctionCompiler<String, String> compiler) {
|
||||
String lambda = "s -> s.toUpperCase()";
|
||||
LambdaCompilingFunction<String, String> function = new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()), compiler);
|
||||
LambdaCompilingFunction<String, String> function = new LambdaCompilingFunction<>(
|
||||
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) {
|
||||
public Function<Flux<String>, Flux<String>> compiledLowercase(
|
||||
FunctionCompiler<Flux<String>, Flux<String>> compiler) {
|
||||
String lambda = "f->f.map(o->o.toString().toLowerCase())";
|
||||
return new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()), compiler);
|
||||
return new LambdaCompilingFunction<>(new ByteArrayResource(lambda.getBytes()),
|
||||
compiler);
|
||||
}
|
||||
|
||||
@Bean
|
||||
@@ -70,7 +79,5 @@ public class SampleApplication {
|
||||
return new FunctionCompiler<>();
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
SpringApplication.run(SampleApplication.class, args);
|
||||
}
|
||||
}
|
||||
// @checkstyle:on
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -27,4 +27,5 @@ public class CharCounter implements Function<String, Integer> {
|
||||
public Integer apply(String word) {
|
||||
return word.length();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -27,6 +27,7 @@ public class Exclaimer implements Function<Flux<String>, Flux<String>> {
|
||||
|
||||
@Override
|
||||
public Flux<String> apply(Flux<String> words) {
|
||||
return words.map(word->word+"!!!");
|
||||
return words.map(word -> word + "!!!");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -27,4 +27,5 @@ public class Greeter implements Function<String, String> {
|
||||
public String apply(String name) {
|
||||
return "Hello " + name;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
boms.spring-cloud-dependencies: org.springframework.cloud:spring-cloud-dependencies:Edgware.SR3
|
||||
dependencies.spring-cloud-function-stream: org.springframework.cloud:spring-cloud-function-stream
|
||||
dependencies.spring-cloud-stream-rabbit: org.springframework.cloud:spring-cloud-starter-stream-rabbit
|
||||
exclusions.spring-cloud-function-web: org.springframework.cloud:spring-cloud-starter-function-web
|
||||
exclusions.http-client: com.rabbitmq:http-client
|
||||
boms.spring-cloud-dependencies:org.springframework.cloud:spring-cloud-dependencies:Edgware.SR3
|
||||
dependencies.spring-cloud-function-stream:org.springframework.cloud:spring-cloud-function-stream
|
||||
dependencies.spring-cloud-stream-rabbit:org.springframework.cloud:spring-cloud-starter-stream-rabbit
|
||||
exclusions.spring-cloud-function-web:org.springframework.cloud:spring-cloud-starter-function-web
|
||||
exclusions.http-client:com.rabbitmq:http-client
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
spring.cloud.function.stream.processor.name: uppercase
|
||||
spring.cloud.function.scan.packages: com.example.functions
|
||||
spring.cloud.function.stream.processor.name:uppercase
|
||||
spring.cloud.function.scan.packages:com.example.functions
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 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.
|
||||
@@ -16,31 +16,29 @@
|
||||
|
||||
package com.example;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.example.functions.CharCounter;
|
||||
import com.example.functions.Exclaimer;
|
||||
import com.example.functions.Greeter;
|
||||
|
||||
import org.junit.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class FunctionTests {
|
||||
|
||||
private final SampleApplication functions = new SampleApplication();
|
||||
|
||||
@Test
|
||||
public void testUppercase() {
|
||||
String output = functions.uppercase().apply("foobar");
|
||||
String output = this.functions.uppercase().apply("foobar");
|
||||
assertEquals("FOOBAR", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowercase() {
|
||||
Flux<String> output = functions.lowercase().apply(Flux.just("FOO", "BAR"));
|
||||
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));
|
||||
@@ -49,13 +47,13 @@ public class FunctionTests {
|
||||
|
||||
@Test
|
||||
public void testHello() {
|
||||
String output = functions.hello().get();
|
||||
assertEquals("hello", output);
|
||||
String output = this.functions.hello().get();
|
||||
assertEquals("hello", output);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWords() {
|
||||
Flux<String> output = functions.words().get();
|
||||
Flux<String> output = this.functions.words().get();
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo", results.get(0));
|
||||
@@ -81,4 +79,5 @@ public class FunctionTests {
|
||||
public void testCharCounter() {
|
||||
assertEquals((Integer) 21, new CharCounter().apply("this is 21 chars long"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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,7 @@ public class SampleApplicationMvcTests {
|
||||
@Test
|
||||
@Ignore("FIXME")
|
||||
public void words() throws Exception {
|
||||
mockMvc.perform(get("/words")).andExpect(content().string("[\"foo\",\"bar\"]"));
|
||||
this.mockMvc.perform(get("/words")).andExpect(content().string("[\"foo\",\"bar\"]"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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.
|
||||
@@ -16,61 +16,69 @@
|
||||
|
||||
package com.example;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import reactor.core.publisher.Flux;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class SampleApplicationTests {
|
||||
|
||||
@Autowired
|
||||
private Function<String, String> uppercase;
|
||||
@Autowired
|
||||
private Function<Flux<String>, Flux<String>> lowercase;
|
||||
@Autowired
|
||||
private Supplier<String> hello;
|
||||
@Autowired
|
||||
private Supplier<Flux<String>> words;
|
||||
@Autowired
|
||||
private Function<String, String> compiledUppercase;
|
||||
@Autowired
|
||||
private Function<Flux<String>, Flux<String>> compiledLowercase;
|
||||
@Autowired
|
||||
private Function<String, String> greeter;
|
||||
@Autowired
|
||||
private Function<Flux<String>, Flux<String>> exclaimer;
|
||||
@Autowired
|
||||
private Function<String, Integer> charCounter;
|
||||
|
||||
@Test
|
||||
public void contextLoads() {
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Function<String, String> uppercase;
|
||||
|
||||
@Test
|
||||
public void testUppercase() {
|
||||
String output = this.uppercase.apply("foobar");
|
||||
assertEquals("FOOBAR", output);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Function<Flux<String>, Flux<String>> lowercase;
|
||||
|
||||
@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));
|
||||
assertEquals("bar", results.get(1));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Supplier<String> hello;
|
||||
|
||||
@Test
|
||||
public void testHello() {
|
||||
String output = this.hello.get();
|
||||
assertEquals("hello", output);
|
||||
assertEquals("hello", output);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Supplier<Flux<String>> words;
|
||||
// the following are contributed via @FunctionScan:
|
||||
|
||||
@Test
|
||||
public void testWords() {
|
||||
@@ -78,21 +86,15 @@ public class SampleApplicationTests {
|
||||
List<String> results = output.collectList().block();
|
||||
assertEquals(2, results.size());
|
||||
assertEquals("foo", results.get(0));
|
||||
assertEquals("bar", results.get(1));
|
||||
assertEquals("bar", results.get(1));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Function<String, String> compiledUppercase;
|
||||
|
||||
@Test
|
||||
public void testCompiledUppercase() {
|
||||
String output = this.compiledUppercase.apply("foobar");
|
||||
assertEquals("FOOBAR", output);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Function<Flux<String>, Flux<String>> compiledLowercase;
|
||||
|
||||
@Test
|
||||
public void testCompiledLowercase() {
|
||||
Flux<String> input = Flux.just("FOO", "BAR");
|
||||
@@ -103,20 +105,12 @@ public class SampleApplicationTests {
|
||||
assertEquals("bar", results.get(1));
|
||||
}
|
||||
|
||||
// the following are contributed via @FunctionScan:
|
||||
|
||||
@Autowired
|
||||
private Function<String, String> greeter;
|
||||
|
||||
@Test
|
||||
public void testGreeter() {
|
||||
String greeting = this.greeter.apply("World");
|
||||
assertEquals("Hello World", greeting);
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Function<Flux<String>, Flux<String>> exclaimer;
|
||||
|
||||
@Test
|
||||
public void testExclaimer() {
|
||||
Flux<String> input = Flux.just("foo", "bar");
|
||||
@@ -127,12 +121,10 @@ public class SampleApplicationTests {
|
||||
assertEquals("bar!!!", results.get(1));
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private Function<String, Integer> charCounter;
|
||||
|
||||
@Test
|
||||
public void testCharCounter() {
|
||||
Integer length = this.charCounter.apply("the quick brown fox");
|
||||
assertEquals(new Integer(19), length);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-function-samples</artifactId>
|
||||
|
||||
Reference in New Issue
Block a user