GH-77 added initial Kotlin support
Added mixed java/kotlin POM configuration added tests, javadocs Resolves #77 Resolves #204
This commit is contained in:
@@ -27,6 +27,8 @@ import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import kotlin.jvm.functions.Function0;
|
||||
import kotlin.jvm.functions.Function1;
|
||||
import org.junit.After;
|
||||
import org.junit.Test;
|
||||
import org.reactivestreams.Publisher;
|
||||
@@ -48,6 +50,7 @@ import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionScan;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionInspector;
|
||||
import org.springframework.cloud.function.inject.FooConfiguration;
|
||||
import org.springframework.cloud.function.kotlin.KotlinLambdasConfiguration;
|
||||
import org.springframework.cloud.function.scan.ScannedFunction;
|
||||
import org.springframework.cloud.function.test.GenericFunction;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -372,6 +375,34 @@ public class ContextFunctionCatalogAutoConfigurationTests {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void kotlinLambdas() {
|
||||
create(KotlinLambdasConfiguration.class);
|
||||
|
||||
assertThat(context.getBean("kotlinFunction")).isInstanceOf(Function.class);
|
||||
assertThat(context.getBean("kotlinFunction")).isInstanceOf(Function1.class);
|
||||
assertThat(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(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);
|
||||
assertThat(catalog.lookup(Supplier.class, "kotlinSupplier"))
|
||||
.isInstanceOf(Supplier.class);
|
||||
assertThat(inspector.getOutputType(catalog.lookup(Supplier.class, "kotlinSupplier")))
|
||||
.isAssignableFrom(String.class);
|
||||
}
|
||||
|
||||
private void create(String jarfile, Class<?> config, String... props) {
|
||||
try {
|
||||
URL[] urls = new URL[] { new ClassPathResource(jarfile).getURL() };
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 org.springframework.boot.autoconfigure.EnableAutoConfiguration
|
||||
import org.springframework.context.annotation.Bean
|
||||
import org.springframework.context.annotation.Configuration
|
||||
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
@EnableAutoConfiguration
|
||||
@Configuration
|
||||
open class KotlinLambdasConfiguration {
|
||||
@Bean
|
||||
open fun kotlinFunction(): (String) -> String {
|
||||
return { it.toUpperCase() }
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun kotlinConsumer(): (String) -> Unit {
|
||||
return { }
|
||||
}
|
||||
|
||||
@Bean
|
||||
open fun kotlinSupplier(): () -> String {
|
||||
return { "Hello" }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user