1
pom.xml
1
pom.xml
@@ -52,6 +52,7 @@
|
||||
<module>spring-cloud-function-samples</module>
|
||||
<module>spring-cloud-function-deployer</module>
|
||||
<module>spring-cloud-function-adapters</module>
|
||||
<module>spring-cloud-function-kotlin</module>
|
||||
<module>docs</module>
|
||||
</modules>
|
||||
|
||||
|
||||
@@ -42,11 +42,6 @@
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration,\
|
||||
org.springframework.cloud.function.context.config.KotlinLambdaToFunctionAutoConfiguration
|
||||
org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration
|
||||
|
||||
org.springframework.cloud.function.context.WrapperDetector=\
|
||||
org.springframework.cloud.function.context.config.FluxWrapperDetector
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
* Copyright 2017-2018 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.
|
||||
@@ -28,7 +28,6 @@ import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
|
||||
@@ -67,15 +66,13 @@ import org.springframework.util.StreamUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Artem Bilan
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
|
||||
@@ -376,47 +373,6 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore("Cannot make this work in Eclipse (since the tools upgraded to 0.8.9)")
|
||||
public void kotlinLambdas() {
|
||||
create("org.springframework.cloud.function.context.config.KotlinLambdasConfiguration",
|
||||
new Class[] { SimpleConfiguration.class });
|
||||
|
||||
assertThat(context.getBean("kotlinFunction")).isInstanceOf(Function.class);
|
||||
assertThat(context.getBean("kotlinFunction")).isInstanceOf(Function1.class);
|
||||
assertThat((Function<?, ?>) catalog.lookup(Function.class, "kotlinFunction"))
|
||||
.isInstanceOf(Function.class);
|
||||
assertThat(
|
||||
inspector.getInputType(catalog.lookup(Function.class, "kotlinFunction")))
|
||||
.isAssignableFrom(String.class);
|
||||
assertThat(
|
||||
inspector.getOutputType(catalog.lookup(Function.class, "kotlinFunction")))
|
||||
.isAssignableFrom(String.class);
|
||||
|
||||
assertThat(context.getBean("kotlinConsumer")).isInstanceOf(Consumer.class);
|
||||
assertThat(context.getBean("kotlinConsumer")).isInstanceOf(Function1.class);
|
||||
assertThat((Function<?, ?>) catalog.lookup(Function.class, "kotlinConsumer"))
|
||||
.isInstanceOf(Function.class);
|
||||
assertThat(
|
||||
inspector.getInputType(catalog.lookup(Function.class, "kotlinConsumer")))
|
||||
.isAssignableFrom(String.class);
|
||||
|
||||
assertThat(context.getBean("kotlinSupplier")).isInstanceOf(Supplier.class);
|
||||
assertThat(context.getBean("kotlinSupplier")).isInstanceOf(Function0.class);
|
||||
Supplier<Flux<String>> supplier = catalog.lookup(Supplier.class,
|
||||
"kotlinSupplier");
|
||||
assertThat(supplier.get().blockFirst()).isEqualTo("Hello");
|
||||
assertThat((Supplier<?>) catalog.lookup(Supplier.class, "kotlinSupplier"))
|
||||
.isInstanceOf(Supplier.class);
|
||||
assertThat(
|
||||
inspector.getOutputType(catalog.lookup(Supplier.class, "kotlinSupplier")))
|
||||
.isAssignableFrom(String.class);
|
||||
|
||||
Function<Flux<String>, Flux<String>> function = catalog.lookup(Function.class,
|
||||
"kotlinFunction|function2");
|
||||
assertThat(function.apply(Flux.just("Hello")).blockFirst())
|
||||
.isEqualTo("HELLOfunction2");
|
||||
}
|
||||
|
||||
private void create(String jarfile, Class<?> config, String... props) {
|
||||
try {
|
||||
@@ -572,13 +528,6 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
create(new Class<?>[] { type }, props);
|
||||
}
|
||||
|
||||
private void create(String typeName, Class<?>[] types, String... props) {
|
||||
Class<?>[] typesToUse = new Class<?>[types.length + 1];
|
||||
typesToUse[0] = ClassUtils.resolveClassName(typeName, null);
|
||||
System.arraycopy(types, 0, typesToUse, 1, types.length);
|
||||
create(typesToUse, props);
|
||||
}
|
||||
|
||||
private void create(Class<?>[] types, String... props) {
|
||||
context = new SpringApplicationBuilder(types).properties(props).run();
|
||||
catalog = context.getBean(FunctionCatalog.class);
|
||||
|
||||
0
spring-cloud-function-kotlin/.jdk8
Normal file
0
spring-cloud-function-kotlin/.jdk8
Normal file
98
spring-cloud-function-kotlin/pom.xml
Normal file
98
spring-cloud-function-kotlin/pom.xml
Normal file
@@ -0,0 +1,98 @@
|
||||
<?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">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>spring-cloud-function-kotlin</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Cloud Function Kotlin Support</name>
|
||||
<description>Spring Cloud Function Kotlin Support</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-parent</artifactId>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.cloud</groupId>
|
||||
<artifactId>spring-cloud-function-context</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>kotlin-maven-plugin</artifactId>
|
||||
<groupId>org.jetbrains.kotlin</groupId>
|
||||
<version>1.2.71</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>compile</id>
|
||||
<goals> <goal>compile</goal> </goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
|
||||
<sourceDir>${project.basedir}/src/main/java</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>test-compile</id>
|
||||
<goals> <goal>test-compile</goal> </goals>
|
||||
<configuration>
|
||||
<sourceDirs>
|
||||
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
|
||||
<sourceDir>${project.basedir}/src/test/java</sourceDir>
|
||||
</sourceDirs>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<executions>
|
||||
<!-- Replacing default-compile as it is treated specially by maven -->
|
||||
<execution>
|
||||
<id>default-compile</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<!-- Replacing default-testCompile as it is treated specially by maven -->
|
||||
<execution>
|
||||
<id>default-testCompile</id>
|
||||
<phase>none</phase>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>java-compile</id>
|
||||
<phase>compile</phase>
|
||||
<goals> <goal>compile</goal> </goals>
|
||||
</execution>
|
||||
<execution>
|
||||
<id>java-test-compile</id>
|
||||
<phase>test-compile</phase>
|
||||
<goals> <goal>testCompile</goal> </goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,2 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.springframework.cloud.function.context.config.KotlinLambdaToFunctionAutoConfiguration
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* Copyright 2018 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.kotlin;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*/
|
||||
public class ContextFunctionCatalogAutoConfigurationKotlinTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
private FunctionCatalog catalog;
|
||||
private FunctionInspector inspector;
|
||||
|
||||
@After
|
||||
public void close() {
|
||||
if (context != null) {
|
||||
context.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinLambdas() {
|
||||
create(new Class[] {KotlinLambdasConfiguration.class, SimpleConfiguration.class});
|
||||
|
||||
assertThat(context.getBean("kotlinFunction")).isInstanceOf(Function.class);
|
||||
assertThat(context.getBean("kotlinFunction")).isInstanceOf(Function1.class);
|
||||
assertThat((Function<?, ?>) catalog.lookup(Function.class, "kotlinFunction"))
|
||||
.isInstanceOf(Function.class);
|
||||
assertThat(
|
||||
inspector.getInputType(catalog.lookup(Function.class, "kotlinFunction")))
|
||||
.isAssignableFrom(String.class);
|
||||
assertThat(
|
||||
inspector.getOutputType(catalog.lookup(Function.class, "kotlinFunction")))
|
||||
.isAssignableFrom(String.class);
|
||||
|
||||
assertThat(context.getBean("kotlinConsumer")).isInstanceOf(Consumer.class);
|
||||
assertThat(context.getBean("kotlinConsumer")).isInstanceOf(Function1.class);
|
||||
assertThat((Function<?, ?>) catalog.lookup(Function.class, "kotlinConsumer"))
|
||||
.isInstanceOf(Function.class);
|
||||
assertThat(
|
||||
inspector.getInputType(catalog.lookup(Function.class, "kotlinConsumer")))
|
||||
.isAssignableFrom(String.class);
|
||||
|
||||
assertThat(context.getBean("kotlinSupplier")).isInstanceOf(Supplier.class);
|
||||
assertThat(context.getBean("kotlinSupplier")).isInstanceOf(Function0.class);
|
||||
Supplier<Flux<String>> supplier = catalog.lookup(Supplier.class,
|
||||
"kotlinSupplier");
|
||||
assertThat(supplier.get().blockFirst()).isEqualTo("Hello");
|
||||
assertThat((Supplier<?>) catalog.lookup(Supplier.class, "kotlinSupplier"))
|
||||
.isInstanceOf(Supplier.class);
|
||||
assertThat(
|
||||
inspector.getOutputType(catalog.lookup(Supplier.class, "kotlinSupplier")))
|
||||
.isAssignableFrom(String.class);
|
||||
|
||||
Function<Flux<String>, Flux<String>> function = catalog.lookup(Function.class,
|
||||
"kotlinFunction|function2");
|
||||
assertThat(function.apply(Flux.just("Hello")).blockFirst())
|
||||
.isEqualTo("HELLOfunction2");
|
||||
}
|
||||
|
||||
private void create(Class<?>[] types, String... props) {
|
||||
context = new SpringApplicationBuilder(types).properties(props).run();
|
||||
catalog = context.getBean(FunctionCatalog.class);
|
||||
inspector = context.getBean(FunctionInspector.class);
|
||||
}
|
||||
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
protected static class SimpleConfiguration {
|
||||
|
||||
@Bean
|
||||
public Function<String, String> function2() {
|
||||
return value -> value + "function2";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user