Remove FunctionType and dependencies on it
This commit is contained in:
@@ -1,346 +0,0 @@
|
||||
/*
|
||||
* 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
|
||||
*
|
||||
* https://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.context;
|
||||
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuple3;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class FunctionTypeTests {
|
||||
|
||||
@Test
|
||||
public void functionWithTuples() {
|
||||
FunctionType functionType = FunctionType.of(MyFunction.class);
|
||||
assertThat(functionType.getType()).isInstanceOf(ParameterizedType.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plainFunction() {
|
||||
FunctionType function = new FunctionType(IntegerToString.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(String.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(String.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supplierOfRegistration() {
|
||||
FunctionType function = new FunctionType(
|
||||
SupplierOfRegistrationOfIntegerToString.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(String.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(String.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supplier() {
|
||||
FunctionType function = new FunctionType(SupplierOfIntegerToString.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(String.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(String.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void genericFunction() {
|
||||
FunctionType function = new FunctionType(StringToMap.class);
|
||||
assertThat(function.getInputType()).isEqualTo(String.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Map.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(String.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Map.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojoFunction() {
|
||||
FunctionType function = new FunctionType(FooToFoo.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Bar.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Bar.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fluxFunction() {
|
||||
FunctionType function = new FunctionType(FluxToFlux.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Bar.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fluxMessageFunction() {
|
||||
FunctionType function = new FunctionType(FluxMessageToFluxMessage.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Bar.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.isMessage()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plainFunctionFromType() {
|
||||
Type type = ResolvableType
|
||||
.forClassWithGenerics(Function.class, Integer.class, String.class)
|
||||
.getType();
|
||||
FunctionType function = new FunctionType(type);
|
||||
assertThat(function.getInputType()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(String.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(String.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojoConsumerFromType() {
|
||||
Type type = ResolvableType.forClassWithGenerics(Consumer.class, Foo.class)
|
||||
.getType();
|
||||
FunctionType function = new FunctionType(type);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Void.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Void.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojoSupplierFromType() {
|
||||
Type type = ResolvableType.forClassWithGenerics(Supplier.class, Foo.class)
|
||||
.getType();
|
||||
FunctionType function = new FunctionType(type);
|
||||
assertThat(function.getInputType()).isEqualTo(Void.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Void.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Foo.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojoSupplierFrom() {
|
||||
FunctionType function = new FunctionType(Supplier.class).to(Foo.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Void.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Void.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Foo.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojoSupplier() {
|
||||
FunctionType function = FunctionType.supplier(Foo.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Void.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Void.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Foo.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void pojoConsumer() {
|
||||
FunctionType function = FunctionType.consumer(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Void.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Void.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Foo.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void plainFunctionFromApi() {
|
||||
FunctionType function = FunctionType.from(Integer.class).to(String.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(String.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Integer.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(String.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fluxMessageFunctionFromType() {
|
||||
Type type = ResolvableType
|
||||
.forClassWithGenerics(Function.class,
|
||||
ResolvableType.forClassWithGenerics(
|
||||
Flux.class,
|
||||
ResolvableType.forClassWithGenerics(Message.class,
|
||||
Foo.class)),
|
||||
ResolvableType.forClassWithGenerics(Flux.class, ResolvableType
|
||||
.forClassWithGenerics(Message.class, Bar.class)))
|
||||
.getType();
|
||||
FunctionType function = new FunctionType(type);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Bar.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.isMessage()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fluxMessageFunctionFromApi() {
|
||||
FunctionType function = FunctionType.from(Foo.class).to(Bar.class).message()
|
||||
.wrap(Flux.class);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(Bar.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.isMessage()).isEqualTo(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void compose() {
|
||||
FunctionType input = FunctionType.from(Foo.class).to(Bar.class).wrap(Flux.class);
|
||||
FunctionType output = FunctionType.from(Bar.class).to(String.class);
|
||||
FunctionType function = FunctionType.compose(input, output);
|
||||
assertThat(function.getInputType()).isEqualTo(Foo.class);
|
||||
assertThat(function.getOutputType()).isEqualTo(String.class);
|
||||
assertThat(function.getInputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.getOutputWrapper()).isEqualTo(Flux.class);
|
||||
assertThat(function.isMessage()).isEqualTo(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void idempotentMessage() {
|
||||
FunctionType function = FunctionType.from(Foo.class).to(Bar.class).message()
|
||||
.wrap(Flux.class);
|
||||
assertThat(function).isSameAs(function.message());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void idempotentWrapper() {
|
||||
FunctionType function = FunctionType.from(Foo.class).to(Bar.class).message()
|
||||
.wrap(Flux.class);
|
||||
assertThat(function).isSameAs(function.wrap(Flux.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nonWrapper() {
|
||||
FunctionType function = FunctionType.from(Foo.class).to(Bar.class);
|
||||
assertThat(function).isSameAs(function.wrap(Object.class));
|
||||
}
|
||||
|
||||
private static class SupplierOfRegistrationOfIntegerToString
|
||||
implements Supplier<FunctionRegistration<Function<Integer, String>>> {
|
||||
|
||||
@Override
|
||||
public FunctionRegistration<Function<Integer, String>> get() {
|
||||
return new FunctionRegistration<Function<Integer, String>>(
|
||||
new IntegerToString(), "ints");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class SupplierOfIntegerToString
|
||||
implements Supplier<Function<Integer, String>> {
|
||||
|
||||
@Override
|
||||
public Function<Integer, String> get() {
|
||||
return new IntegerToString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class IntegerToString implements Function<Integer, String> {
|
||||
|
||||
@Override
|
||||
public String apply(Integer t) {
|
||||
return "" + t;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class StringToMap implements Function<String, Map<String, Integer>> {
|
||||
|
||||
@Override
|
||||
public Map<String, Integer> apply(String t) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class FooToFoo implements Function<Foo, Bar> {
|
||||
|
||||
@Override
|
||||
public Bar apply(Foo t) {
|
||||
return new Bar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class FluxToFlux implements Function<Flux<Foo>, Flux<Bar>> {
|
||||
|
||||
@Override
|
||||
public Flux<Bar> apply(Flux<Foo> t) {
|
||||
return t.map(f -> new Bar());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class FluxMessageToFluxMessage
|
||||
implements Function<Flux<Message<Foo>>, Flux<Message<Bar>>> {
|
||||
|
||||
@Override
|
||||
public Flux<Message<Bar>> apply(Flux<Message<Foo>> t) {
|
||||
return t.map(f -> MessageBuilder.withPayload(new Bar())
|
||||
.copyHeadersIfAbsent(f.getHeaders()).build());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class Foo {
|
||||
|
||||
}
|
||||
|
||||
private static class Bar {
|
||||
|
||||
}
|
||||
|
||||
private static class MyFunction
|
||||
implements Function<Tuple2<Flux<String>, Flux<Integer>>, Tuple3<Flux<String>, Flux<Integer>, Flux<Object>>> {
|
||||
|
||||
@Override
|
||||
public Tuple3<Flux<String>, Flux<Integer>, Flux<Object>> apply(Tuple2<Flux<String>, Flux<Integer>> t) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,239 +0,0 @@
|
||||
/*
|
||||
* Copyright 2019-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
|
||||
*
|
||||
* https://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.context;
|
||||
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Oleg Zhurakousky
|
||||
*
|
||||
*/
|
||||
public class SpringFunctionAdapterInitializerTests {
|
||||
|
||||
private AbstractSpringFunctionAdapterInitializer<Object> initializer;
|
||||
|
||||
@AfterEach
|
||||
public void after() {
|
||||
System.clearProperty("function.name");
|
||||
if (this.initializer != null) {
|
||||
this.initializer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullSource() {
|
||||
Assertions.assertThrows(IllegalArgumentException.class, () ->
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(null) {
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sourceAsMainClassProperty() {
|
||||
try {
|
||||
System.setProperty("MAIN_CLASS", FluxFunctionConfig.class.getName());
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>() {
|
||||
|
||||
};
|
||||
}
|
||||
finally {
|
||||
System.clearProperty("MAIN_CLASS");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionBean() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(FluxFunctionConfig.class) {
|
||||
|
||||
};
|
||||
this.initializer.initialize(null);
|
||||
Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo())));
|
||||
assertThat(result.blockFirst()).isInstanceOf(Bar.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionApp() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(FluxFunctionApp.class) {
|
||||
|
||||
};
|
||||
this.initializer.initialize(null);
|
||||
Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo())));
|
||||
Object o = result.blockFirst();
|
||||
assertThat(result.blockFirst()).isInstanceOf(Bar.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void functionCatalog() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(FunctionConfig.class) {
|
||||
|
||||
};
|
||||
this.initializer.initialize(null);
|
||||
Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo())));
|
||||
assertThat(result.blockFirst()).isInstanceOf(Bar.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled // related to boot 2.1 no bean override change
|
||||
public void functionRegistrar() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(FunctionRegistrar.class) {
|
||||
|
||||
};
|
||||
this.initializer.initialize(null);
|
||||
Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo())));
|
||||
assertThat(result.blockFirst()).isInstanceOf(Bar.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void namedFunctionCatalog() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(NamedFunctionConfig.class) {
|
||||
|
||||
};
|
||||
System.setProperty("function.name", "other");
|
||||
this.initializer.initialize(null);
|
||||
Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo())));
|
||||
assertThat(result.blockFirst()).isInstanceOf(Bar.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void consumerCatalog() {
|
||||
this.initializer = new AbstractSpringFunctionAdapterInitializer<Object>(ConsumerConfig.class) {
|
||||
|
||||
};
|
||||
this.initializer.initialize(null);
|
||||
Flux<?> result = Flux.from(this.initializer.apply(Flux.just(new Foo())));
|
||||
assertThat(result.toStream().collect(Collectors.toList())).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void supplierCatalog() {
|
||||
initializer = new AbstractSpringFunctionAdapterInitializer<Object>(SupplierConfig.class) {
|
||||
|
||||
};
|
||||
initializer.initialize(null);
|
||||
Flux result = Flux.from(initializer.apply(null));
|
||||
assertThat(result.blockFirst()).isInstanceOf(Bar.class);
|
||||
}
|
||||
|
||||
@Configuration
|
||||
protected static class FluxFunctionConfig {
|
||||
|
||||
@Bean
|
||||
public Function<Flux<Foo>, Flux<Bar>> function() {
|
||||
return flux -> flux.map(foo -> new Bar());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class FluxFunctionApp implements Function<Flux<Foo>, Flux<Bar>> {
|
||||
|
||||
@Override
|
||||
public Flux<Bar> apply(Flux<Foo> flux) {
|
||||
return flux.map(foo -> new Bar());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class FunctionRegistrar
|
||||
implements ApplicationContextInitializer<GenericApplicationContext> {
|
||||
|
||||
public Function<Flux<Foo>, Flux<Bar>> function() {
|
||||
return flux -> flux.map(foo -> new Bar());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(GenericApplicationContext context) {
|
||||
context.registerBean("function", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<Function<Flux<Foo>, Flux<Bar>>>(
|
||||
function()).name("function")
|
||||
.type(FunctionType.from(Foo.class).to(Bar.class)
|
||||
.wrap(Flux.class).getType()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(ContextFunctionCatalogAutoConfiguration.class)
|
||||
protected static class FunctionConfig {
|
||||
|
||||
@Bean
|
||||
public Function<Foo, Bar> function() {
|
||||
return foo -> new Bar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(ContextFunctionCatalogAutoConfiguration.class)
|
||||
protected static class NamedFunctionConfig {
|
||||
|
||||
@Bean
|
||||
public Function<Foo, Bar> other() {
|
||||
return foo -> new Bar();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(ContextFunctionCatalogAutoConfiguration.class)
|
||||
protected static class SupplierConfig {
|
||||
@Bean
|
||||
public Supplier<Bar> supplier() {
|
||||
return () -> {
|
||||
return new Bar();
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Import(ContextFunctionCatalogAutoConfiguration.class)
|
||||
protected static class ConsumerConfig {
|
||||
|
||||
@Bean
|
||||
public Consumer<Foo> consumer() {
|
||||
return foo -> {
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected static class Foo {
|
||||
|
||||
}
|
||||
|
||||
protected static class Bar {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,6 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||
import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.cloud.function.json.JsonMapper;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -498,30 +497,35 @@ public class BeanFactoryAwareFunctionRegistryTests {
|
||||
assertThat(func).isNull();
|
||||
FunctionRegistry registry = (FunctionRegistry) catalog;
|
||||
try {
|
||||
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "a").type(FunctionType.from(Integer.class).to(String.class));
|
||||
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "a")
|
||||
.type(FunctionTypeUtils.functionType(Integer.class, String.class));
|
||||
registry.register(registration);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalArgumentException e) {
|
||||
// good as we expect it to fail
|
||||
}
|
||||
//
|
||||
try {
|
||||
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "b").type(FunctionType.from(String.class).to(Integer.class));
|
||||
FunctionRegistration registration = new FunctionRegistration(new MyFunction(), "b")
|
||||
.type(FunctionTypeUtils.functionType(String.class, Integer.class));
|
||||
registry.register(registration);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException e) {
|
||||
catch (IllegalArgumentException e) {
|
||||
// good as we expect it to fail
|
||||
}
|
||||
//
|
||||
FunctionRegistration c = new FunctionRegistration(new MyFunction(), "c").type(FunctionType.from(String.class).to(String.class));
|
||||
FunctionRegistration c = new FunctionRegistration(new MyFunction(), "c")
|
||||
.type(FunctionTypeUtils.functionType(String.class, String.class));
|
||||
registry.register(c);
|
||||
//
|
||||
FunctionRegistration d = new FunctionRegistration(new RawFunction(), "d").type(FunctionType.from(Person.class).to(String.class));
|
||||
FunctionRegistration d = new FunctionRegistration(new RawFunction(), "d")
|
||||
.type(FunctionTypeUtils.functionType(Person.class, String.class));
|
||||
registry.register(d);
|
||||
//
|
||||
FunctionRegistration e = new FunctionRegistration(new RawFunction(), "e").type(FunctionType.from(Object.class).to(Object.class));
|
||||
FunctionRegistration e = new FunctionRegistration(new RawFunction(), "e")
|
||||
.type(FunctionTypeUtils.functionType(Object.class, Object.class));
|
||||
registry.register(e);
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,6 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.util.function.Tuple2;
|
||||
import reactor.util.function.Tuple3;
|
||||
|
||||
import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.messaging.Message;
|
||||
|
||||
@@ -114,29 +113,29 @@ public class FunctionTypeUtilsTests {
|
||||
|
||||
@Test
|
||||
public void testFunctionTypeByClassDiscovery() {
|
||||
FunctionType type = FunctionType.of(FunctionTypeUtils.discoverFunctionTypeFromClass(Function.class));
|
||||
assertThat(type.getInputType()).isAssignableFrom(Object.class);
|
||||
Type type = FunctionTypeUtils.discoverFunctionTypeFromClass(Function.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getInputType(type))).isAssignableFrom(Object.class);
|
||||
|
||||
type = FunctionType.of(FunctionTypeUtils.discoverFunctionTypeFromClass(MessageFunction.class));
|
||||
assertThat(type.getInputType()).isAssignableFrom(String.class);
|
||||
assertThat(type.getOutputType()).isAssignableFrom(String.class);
|
||||
type = FunctionTypeUtils.discoverFunctionTypeFromClass(MessageFunction.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfInputType(type))).isAssignableFrom(String.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfOutputType(type))).isAssignableFrom(String.class);
|
||||
|
||||
type = FunctionType.of(FunctionTypeUtils.discoverFunctionTypeFromClass(MyMessageFunction.class));
|
||||
assertThat(type.getInputType()).isAssignableFrom(String.class);
|
||||
assertThat(type.getOutputType()).isAssignableFrom(String.class);
|
||||
type = FunctionTypeUtils.discoverFunctionTypeFromClass(MyMessageFunction.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfInputType(type))).isAssignableFrom(String.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfOutputType(type))).isAssignableFrom(String.class);
|
||||
|
||||
type = FunctionType.of(FunctionTypeUtils.discoverFunctionTypeFromClass(MessageConsumer.class));
|
||||
assertThat(type.getInputType()).isAssignableFrom(String.class);
|
||||
type = FunctionTypeUtils.discoverFunctionTypeFromClass(MessageConsumer.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfInputType(type))).isAssignableFrom(String.class);
|
||||
|
||||
type = FunctionType.of(FunctionTypeUtils.discoverFunctionTypeFromClass(MyMessageConsumer.class));
|
||||
assertThat(type.getInputType()).isAssignableFrom(String.class);
|
||||
type = FunctionTypeUtils.discoverFunctionTypeFromClass(MyMessageConsumer.class);
|
||||
assertThat(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfInputType(type))).isAssignableFrom(String.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithComplexHierarchy() {
|
||||
FunctionType type = FunctionType.of(FunctionTypeUtils.discoverFunctionTypeFromClass(ReactiveFunctionImpl.class));
|
||||
assertThat(String.class).isAssignableFrom(type.getInputType());
|
||||
assertThat(Integer.class).isAssignableFrom(type.getOutputType());
|
||||
Type type = FunctionTypeUtils.discoverFunctionTypeFromClass(ReactiveFunctionImpl.class);
|
||||
assertThat(String.class).isAssignableFrom(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfInputType(type)));
|
||||
assertThat(Integer.class).isAssignableFrom(FunctionTypeUtils.getRawType(FunctionTypeUtils.getComponentTypeOfOutputType(type)));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -40,7 +40,6 @@ import org.springframework.boot.builder.SpringApplicationBuilder;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionRegistry;
|
||||
import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.cloud.function.context.HybridFunctionalRegistrationTests.UppercaseFunction;
|
||||
import org.springframework.cloud.function.context.catalog.SimpleFunctionRegistry.FunctionInvocationWrapper;
|
||||
import org.springframework.cloud.function.context.config.JsonMessageConverter;
|
||||
@@ -91,7 +90,7 @@ public class SimpleFunctionRegistryTests {
|
||||
public void testCachingOfFunction() {
|
||||
Echo function = new Echo();
|
||||
FunctionRegistration<Echo> registration = new FunctionRegistration<>(
|
||||
function, "echo").type(FunctionType.of(Echo.class));
|
||||
function, "echo").type(Echo.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
@@ -107,7 +106,7 @@ public class SimpleFunctionRegistryTests {
|
||||
public void testNoCachingOfFunction() {
|
||||
Echo function = new Echo();
|
||||
FunctionRegistration<Echo> registration = new FunctionRegistration<>(
|
||||
function, "echo").type(FunctionType.of(Echo.class));
|
||||
function, "echo").type(Echo.class);
|
||||
registration.getProperties().put("singleton", "false");
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
@@ -124,7 +123,7 @@ public class SimpleFunctionRegistryTests {
|
||||
public void testSCF640() {
|
||||
Echo function = new Echo();
|
||||
FunctionRegistration<Echo> registration = new FunctionRegistration<>(
|
||||
function, "echo").type(FunctionType.of(Echo.class));
|
||||
function, "echo").type(Echo.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
@@ -142,27 +141,27 @@ public class SimpleFunctionRegistryTests {
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
|
||||
FunctionRegistration<UpperCase> reg1 = new FunctionRegistration<>(
|
||||
new UpperCase(), "uppercase").type(FunctionType.of(UpperCase.class));
|
||||
new UpperCase(), "uppercase").type(UpperCase.class);
|
||||
catalog.register(reg1);
|
||||
//
|
||||
FunctionRegistration<UpperCaseMessage> reg2 = new FunctionRegistration<>(
|
||||
new UpperCaseMessage(), "uppercaseMessage").type(FunctionType.of(UpperCaseMessage.class));
|
||||
new UpperCaseMessage(), "uppercaseMessage").type(UpperCaseMessage.class);
|
||||
catalog.register(reg2);
|
||||
//
|
||||
FunctionRegistration<StringArrayFunction> reg3 = new FunctionRegistration<>(
|
||||
new StringArrayFunction(), "stringArray").type(FunctionType.of(StringArrayFunction.class));
|
||||
new StringArrayFunction(), "stringArray").type(StringArrayFunction.class);
|
||||
catalog.register(reg3);
|
||||
//
|
||||
FunctionRegistration<TypelessFunction> reg4 = new FunctionRegistration<>(
|
||||
new TypelessFunction(), "typeless").type(FunctionType.of(TypelessFunction.class));
|
||||
new TypelessFunction(), "typeless").type(TypelessFunction.class);
|
||||
catalog.register(reg4);
|
||||
//
|
||||
FunctionRegistration<ByteArrayFunction> reg5 = new FunctionRegistration<>(
|
||||
new ByteArrayFunction(), "typeless").type(FunctionType.of(ByteArrayFunction.class));
|
||||
new ByteArrayFunction(), "typeless").type(ByteArrayFunction.class);
|
||||
catalog.register(reg5);
|
||||
//
|
||||
FunctionRegistration<StringListFunction> reg6 = new FunctionRegistration<>(
|
||||
new StringListFunction(), "stringList").type(FunctionType.of(StringListFunction.class));
|
||||
new StringListFunction(), "stringList").type(StringListFunction.class);
|
||||
catalog.register(reg6);
|
||||
|
||||
Message<String> collectionMessage = MessageBuilder.withPayload("[\"ricky\", \"julien\", \"bubbles\"]").build();
|
||||
@@ -218,7 +217,7 @@ public class SimpleFunctionRegistryTests {
|
||||
|
||||
UpperCase function = new UpperCase();
|
||||
FunctionRegistration<UpperCase> registration = new FunctionRegistration<>(
|
||||
function, "foo").type(FunctionType.of(UppercaseFunction.class));
|
||||
function, "foo").type(UppercaseFunction.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
@@ -237,7 +236,7 @@ public class SimpleFunctionRegistryTests {
|
||||
|
||||
TestFunction function = new TestFunction();
|
||||
FunctionRegistration<TestFunction> registration = new FunctionRegistration<>(
|
||||
function, "foo").type(FunctionType.of(TestFunction.class));
|
||||
function, "foo").type(TestFunction.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
@@ -246,7 +245,7 @@ public class SimpleFunctionRegistryTests {
|
||||
FunctionInvocationWrapper lookedUpFunction = catalog.lookup("hello");
|
||||
assertThat(lookedUpFunction).isNotNull(); // because we only have one and can look it up with any name
|
||||
FunctionRegistration<TestFunction> registration2 = new FunctionRegistration<>(
|
||||
function, "foo2").type(FunctionType.of(TestFunction.class));
|
||||
function, "foo2").type(TestFunction.class);
|
||||
catalog.register(registration2);
|
||||
lookedUpFunction = catalog.lookup("hello");
|
||||
assertThat(lookedUpFunction).isNull();
|
||||
@@ -257,9 +256,9 @@ public class SimpleFunctionRegistryTests {
|
||||
@Test
|
||||
public void testFunctionComposition() {
|
||||
FunctionRegistration<UpperCase> upperCaseRegistration = new FunctionRegistration<>(
|
||||
new UpperCase(), "uppercase").type(FunctionType.of(UpperCase.class));
|
||||
new UpperCase(), "uppercase").type(UpperCase.class);
|
||||
FunctionRegistration<Reverse> reverseRegistration = new FunctionRegistration<>(
|
||||
new Reverse(), "reverse").type(FunctionType.of(Reverse.class));
|
||||
new Reverse(), "reverse").type(Reverse.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(upperCaseRegistration);
|
||||
@@ -268,23 +267,15 @@ public class SimpleFunctionRegistryTests {
|
||||
Function<Flux<String>, Flux<String>> lookedUpFunction = catalog
|
||||
.lookup("uppercase|reverse");
|
||||
assertThat(lookedUpFunction).isNotNull();
|
||||
|
||||
Flux flux = lookedUpFunction.apply(Flux.just("star"));
|
||||
flux.subscribe(v -> {
|
||||
System.out.println(v);
|
||||
});
|
||||
|
||||
// assertThat(lookedUpFunction.apply(Flux.just("star")).blockFirst())
|
||||
// .isEqualTo("RATS");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Disabled
|
||||
public void testFunctionCompositionImplicit() {
|
||||
FunctionRegistration<Words> wordsRegistration = new FunctionRegistration<>(
|
||||
new Words(), "words").type(FunctionType.of(Words.class));
|
||||
new Words(), "words").type(Words.class);
|
||||
FunctionRegistration<Reverse> reverseRegistration = new FunctionRegistration<>(
|
||||
new Reverse(), "reverse").type(FunctionType.of(Reverse.class));
|
||||
new Reverse(), "reverse").type(Reverse.class);
|
||||
FunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(wordsRegistration);
|
||||
@@ -301,9 +292,9 @@ public class SimpleFunctionRegistryTests {
|
||||
@Disabled
|
||||
public void testFunctionCompletelyImplicitComposition() {
|
||||
FunctionRegistration<Words> wordsRegistration = new FunctionRegistration<>(
|
||||
new Words(), "words").type(FunctionType.of(Words.class));
|
||||
new Words(), "words").type(Words.class);
|
||||
FunctionRegistration<Reverse> reverseRegistration = new FunctionRegistration<>(
|
||||
new Reverse(), "reverse").type(FunctionType.of(Reverse.class));
|
||||
new Reverse(), "reverse").type(Reverse.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(wordsRegistration);
|
||||
@@ -319,9 +310,9 @@ public class SimpleFunctionRegistryTests {
|
||||
@Test
|
||||
public void testFunctionCompositionExplicit() {
|
||||
FunctionRegistration<Words> wordsRegistration = new FunctionRegistration<>(
|
||||
new Words(), "words").type(FunctionType.of(Words.class));
|
||||
new Words(), "words").type(Words.class);
|
||||
FunctionRegistration<Reverse> reverseRegistration = new FunctionRegistration<>(
|
||||
new Reverse(), "reverse").type(FunctionType.of(Reverse.class));
|
||||
new Reverse(), "reverse").type(Reverse.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(wordsRegistration);
|
||||
@@ -337,10 +328,10 @@ public class SimpleFunctionRegistryTests {
|
||||
public void testFunctionCompositionWithMessages() {
|
||||
FunctionRegistration<UpperCaseMessage> upperCaseRegistration = new FunctionRegistration<>(
|
||||
new UpperCaseMessage(), "uppercase")
|
||||
.type(FunctionType.of(UpperCaseMessage.class));
|
||||
.type(UpperCaseMessage.class);
|
||||
FunctionRegistration<ReverseMessage> reverseRegistration = new FunctionRegistration<>(
|
||||
new ReverseMessage(), "reverse")
|
||||
.type(FunctionType.of(ReverseMessage.class));
|
||||
.type(ReverseMessage.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(upperCaseRegistration);
|
||||
@@ -359,9 +350,9 @@ public class SimpleFunctionRegistryTests {
|
||||
public void testFunctionCompositionMixedMessages() {
|
||||
FunctionRegistration<UpperCaseMessage> upperCaseRegistration = new FunctionRegistration<>(
|
||||
new UpperCaseMessage(), "uppercase")
|
||||
.type(FunctionType.of(UpperCaseMessage.class));
|
||||
.type(UpperCaseMessage.class);
|
||||
FunctionRegistration<Reverse> reverseRegistration = new FunctionRegistration<>(
|
||||
new Reverse(), "reverse").type(FunctionType.of(Reverse.class));
|
||||
new Reverse(), "reverse").type(Reverse.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(upperCaseRegistration);
|
||||
@@ -379,7 +370,7 @@ public class SimpleFunctionRegistryTests {
|
||||
@Test
|
||||
public void testReactiveFunctionMessages() {
|
||||
FunctionRegistration<ReactiveFunction> registration = new FunctionRegistration<>(new ReactiveFunction(), "reactive")
|
||||
.type(FunctionType.of(ReactiveFunction.class));
|
||||
.type(ReactiveFunction.class);
|
||||
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
@@ -407,6 +398,7 @@ public class SimpleFunctionRegistryTests {
|
||||
assertThat(result).isEqualTo("Jim Lahey");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void lookup() {
|
||||
SimpleFunctionRegistry functionRegistry = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
@@ -416,7 +408,7 @@ public class SimpleFunctionRegistryTests {
|
||||
|
||||
Function userFunction = uppercase();
|
||||
FunctionRegistration functionRegistration = new FunctionRegistration(userFunction, "uppercase")
|
||||
.type(FunctionType.from(String.class).to(String.class));
|
||||
.type(FunctionTypeUtils.functionType(String.class, String.class));
|
||||
functionRegistry.register(functionRegistration);
|
||||
|
||||
function = functionRegistry.lookup("uppercase");
|
||||
@@ -424,20 +416,21 @@ public class SimpleFunctionRegistryTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void lookupDefaultName() {
|
||||
SimpleFunctionRegistry functionRegistry = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
Function userFunction = uppercase();
|
||||
FunctionRegistration functionRegistration = new FunctionRegistration(userFunction, "uppercase")
|
||||
.type(FunctionType.from(String.class).to(String.class));
|
||||
.type(FunctionTypeUtils.functionType(String.class, String.class));
|
||||
functionRegistry.register(functionRegistration);
|
||||
|
||||
FunctionInvocationWrapper function = functionRegistry.lookup("");
|
||||
assertThat(function).isNotNull();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void lookupWithCompositionFunctionAndConsumer() {
|
||||
SimpleFunctionRegistry functionRegistry = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
@@ -445,7 +438,7 @@ public class SimpleFunctionRegistryTests {
|
||||
|
||||
Object userFunction = uppercase();
|
||||
FunctionRegistration functionRegistration = new FunctionRegistration(userFunction, "uppercase")
|
||||
.type(FunctionType.from(String.class).to(String.class));
|
||||
.type(FunctionTypeUtils.functionType(String.class, String.class));
|
||||
functionRegistry.register(functionRegistration);
|
||||
|
||||
userFunction = consumer();
|
||||
@@ -458,6 +451,7 @@ public class SimpleFunctionRegistryTests {
|
||||
functionWrapper.apply("123");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "rawtypes" })
|
||||
@Test
|
||||
public void lookupWithReactiveConsumer() {
|
||||
SimpleFunctionRegistry functionRegistry = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
@@ -474,12 +468,11 @@ public class SimpleFunctionRegistryTests {
|
||||
functionWrapper.apply("123");
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "rawtypes", "unchecked" })
|
||||
@Test
|
||||
public void testHeaderEnricherFunction() {
|
||||
FunctionRegistration<HeaderEnricherFunction> registration =
|
||||
new FunctionRegistration<>(new HeaderEnricherFunction(), "headerEnricher")
|
||||
.type(FunctionType.of(HeaderEnricherFunction.class));
|
||||
.type(HeaderEnricherFunction.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
@@ -493,7 +486,7 @@ public class SimpleFunctionRegistryTests {
|
||||
@Test
|
||||
public void testReactiveMonoSupplier() {
|
||||
FunctionRegistration<ReactiveMonoGreeter> registration = new FunctionRegistration<>(new ReactiveMonoGreeter(),
|
||||
"greeter").type(FunctionType.of(ReactiveMonoGreeter.class));
|
||||
"greeter").type(ReactiveMonoGreeter.class);
|
||||
SimpleFunctionRegistry catalog = new SimpleFunctionRegistry(this.conversionService, this.messageConverter,
|
||||
new JacksonMapper(new ObjectMapper()));
|
||||
catalog.register(registration);
|
||||
|
||||
@@ -39,7 +39,7 @@ import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.cloud.function.context.FunctionCatalog;
|
||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.cloud.function.context.catalog.FunctionTypeUtils;
|
||||
import org.springframework.cloud.function.context.scan.TestFunction;
|
||||
import org.springframework.context.ApplicationContextInitializer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -245,17 +245,18 @@ public class ContextFunctionCatalogInitializerTests {
|
||||
|
||||
private List<String> list = new ArrayList<>();
|
||||
|
||||
|
||||
@Override
|
||||
public void initialize(GenericApplicationContext context) {
|
||||
|
||||
context.registerBean("function", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(function()).type(
|
||||
FunctionType.from(Person.class).to(Person.class).getType()));
|
||||
() -> new FunctionRegistration<>(function()).type(FunctionTypeUtils.functionType(Person.class, Person.class)));
|
||||
context.registerBean("supplier", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(supplier())
|
||||
.type(FunctionType.supplier(String.class).getType()));
|
||||
.type(FunctionTypeUtils.supplierType(String.class)));
|
||||
context.registerBean("consumer", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(consumer())
|
||||
.type(FunctionType.consumer(String.class).getType()));
|
||||
.type(FunctionTypeUtils.consumerType(String.class)));
|
||||
context.registerBean(SimpleConfiguration.class, () -> this);
|
||||
}
|
||||
|
||||
@@ -296,8 +297,7 @@ public class ContextFunctionCatalogInitializerTests {
|
||||
@Override
|
||||
public void initialize(GenericApplicationContext context) {
|
||||
context.registerBean("function", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(function()).type(
|
||||
FunctionType.from(String.class).to(String.class).getType()));
|
||||
() -> new FunctionRegistration<>(function()).type(FunctionTypeUtils.functionType(String.class, String.class)));
|
||||
context.registerBean(PropertiesConfiguration.class, () -> this);
|
||||
}
|
||||
|
||||
@@ -317,8 +317,7 @@ public class ContextFunctionCatalogInitializerTests {
|
||||
@Override
|
||||
public void initialize(GenericApplicationContext context) {
|
||||
context.registerBean("function", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(function()).type(
|
||||
FunctionType.from(String.class).to(String.class).getType()));
|
||||
() -> new FunctionRegistration<>(function()).type(FunctionTypeUtils.functionType(String.class, String.class)));
|
||||
context.registerBean(ValueConfiguration.class, () -> this);
|
||||
}
|
||||
|
||||
@@ -355,8 +354,7 @@ public class ContextFunctionCatalogInitializerTests {
|
||||
context.registerBean(String.class, () -> value());
|
||||
context.registerBean("foos", FunctionRegistration.class,
|
||||
() -> new FunctionRegistration<>(foos(context.getBean(String.class)))
|
||||
.type(FunctionType.from(String.class).to(Foo.class)
|
||||
.getType()));
|
||||
.type(FunctionTypeUtils.functionType(String.class, Foo.class)));
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
Reference in New Issue
Block a user