GH-685 Update Kotlin documentation
Add test for collections polishing
This commit is contained in:
@@ -467,7 +467,7 @@ The above represents Kotlin lambdas configured as Spring beans. The signature of
|
|||||||
While mechanics of Kotlin-to-Java mapping are outside of the scope of this documentation, it is important to understand that the
|
While mechanics of Kotlin-to-Java mapping are outside of the scope of this documentation, it is important to understand that the
|
||||||
same rules for signature transformation outlined in "Java 8 function support" section are applied here as well.
|
same rules for signature transformation outlined in "Java 8 function support" section are applied here as well.
|
||||||
|
|
||||||
To enable Kotlin support all you need is to add `spring-cloud-function-kotlin` module to your classpath which contains the appropriate
|
To enable Kotlin support all you need is to add Kotlin SDK libraries on the classpath which will trigger appropriate
|
||||||
autoconfiguration and supporting classes.
|
autoconfiguration and supporting classes.
|
||||||
|
|
||||||
=== Function Component Scan
|
=== Function Component Scan
|
||||||
|
|||||||
2
pom.xml
2
pom.xml
@@ -51,8 +51,8 @@
|
|||||||
<module>spring-cloud-function-samples</module>
|
<module>spring-cloud-function-samples</module>
|
||||||
<module>spring-cloud-function-deployer</module>
|
<module>spring-cloud-function-deployer</module>
|
||||||
<module>spring-cloud-function-adapters</module>
|
<module>spring-cloud-function-adapters</module>
|
||||||
<module>spring-cloud-function-kotlin</module>
|
|
||||||
<module>spring-cloud-function-rsocket</module>
|
<module>spring-cloud-function-rsocket</module>
|
||||||
|
<module>spring-cloud-function-kotlin</module>
|
||||||
<module>docs</module>
|
<module>docs</module>
|
||||||
</modules>
|
</modules>
|
||||||
|
|
||||||
|
|||||||
4
spring-cloud-function-kotlin/README.adoc
Normal file
4
spring-cloud-function-kotlin/README.adoc
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
!!! INTERNAL !!!
|
||||||
|
|
||||||
|
Contains only Kotlin tests.
|
||||||
|
Since version 3.1.3, user's should not be declaring explicit dependency on this module.
|
||||||
@@ -33,6 +33,7 @@ import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry
|
|||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.context.annotation.Configuration;
|
import org.springframework.context.annotation.Configuration;
|
||||||
import org.springframework.context.support.GenericApplicationContext;
|
import org.springframework.context.support.GenericApplicationContext;
|
||||||
|
import org.springframework.messaging.support.MessageBuilder;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
@@ -83,6 +84,30 @@ public class ContextFunctionCatalogAutoConfigurationKotlinTests {
|
|||||||
assertThat(functionType.getActualTypeArguments().length).isEqualTo(2);
|
assertThat(functionType.getActualTypeArguments().length).isEqualTo(2);
|
||||||
assertThat(functionType.getActualTypeArguments()[0].getTypeName()).isEqualTo(Person.class.getName());
|
assertThat(functionType.getActualTypeArguments()[0].getTypeName()).isEqualTo(Person.class.getName());
|
||||||
assertThat(functionType.getActualTypeArguments()[1].getTypeName()).isEqualTo(String.class.getName());
|
assertThat(functionType.getActualTypeArguments()[1].getTypeName()).isEqualTo(String.class.getName());
|
||||||
|
|
||||||
|
|
||||||
|
function = this.context.getBean("kotlinListPojoFunction");
|
||||||
|
functionType = (ParameterizedType) FunctionTypeUtils.discoverFunctionType(function, "kotlinListPojoFunction", this.context);
|
||||||
|
assertThat(functionType.getRawType().getTypeName()).isEqualTo(Function.class.getName());
|
||||||
|
assertThat(functionType.getActualTypeArguments().length).isEqualTo(2);
|
||||||
|
assertThat(functionType.getActualTypeArguments()[0].getTypeName()).isEqualTo("java.util.List<org.springframework.cloud.function.kotlin.Person>");
|
||||||
|
assertThat(functionType.getActualTypeArguments()[1].getTypeName()).isEqualTo(String.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWithComplexTypesAndRouting() {
|
||||||
|
create(new Class[] { KotlinLambdasConfiguration.class,
|
||||||
|
SimpleConfiguration.class });
|
||||||
|
|
||||||
|
FunctionInvocationWrapper function = this.catalog.lookup("kotlinListPojoFunction");
|
||||||
|
String result = (String) function.apply("[{\"name\":\"Ricky\"}]");
|
||||||
|
assertThat(result).isEqualTo("List of: Ricky");
|
||||||
|
|
||||||
|
function = this.catalog.lookup(Function.class, "functionRouter");
|
||||||
|
result = (String) function.apply(MessageBuilder.withPayload("[{\"name\":\"Ricky\"}]")
|
||||||
|
.setHeader("spring.cloud.function.definition", "kotlinListPojoFunction").build());
|
||||||
|
assertThat(result).isEqualTo("List of: Ricky");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
|||||||
import org.springframework.context.annotation.Bean
|
import org.springframework.context.annotation.Bean
|
||||||
import org.springframework.context.annotation.Configuration
|
import org.springframework.context.annotation.Configuration
|
||||||
import java.util.function.Function
|
import java.util.function.Function
|
||||||
|
import java.util.List
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Oleg Zhurakousky
|
* @author Oleg Zhurakousky
|
||||||
@@ -37,6 +38,13 @@ class KotlinLambdasConfiguration {
|
|||||||
fun kotlinPojoFunction(): (Person) -> String {
|
fun kotlinPojoFunction(): (Person) -> String {
|
||||||
return { it.name.toString()}
|
return { it.name.toString()}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Bean
|
||||||
|
fun kotlinListPojoFunction(): (List<Person>) -> String {
|
||||||
|
return {
|
||||||
|
"List of: " + it.get(0).name
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
fun kotlinConsumer(): (String) -> Unit {
|
fun kotlinConsumer(): (String) -> Unit {
|
||||||
|
|||||||
Reference in New Issue
Block a user