Re-order type discovery and function wrapping
Otherwise the explicit types from the function registration are not used.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
/*
|
||||
* Copyright 2016-2017 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.context;
|
||||
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class FunctionRegistrationTests {
|
||||
|
||||
@Test
|
||||
public void noTypeByDefault() {
|
||||
FunctionRegistration<?> registration = new FunctionRegistration<>(new Foos())
|
||||
.names("foos");
|
||||
assertThat(registration.getType()).isNull();
|
||||
assertThat(registration.getNames()).contains("foos");
|
||||
}
|
||||
|
||||
private static class Foos implements Function<Integer, String> {
|
||||
@Override
|
||||
public String apply(Integer t) {
|
||||
return "i=" + t;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import java.util.function.Supplier;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cloud.function.context.FunctionRegistration;
|
||||
import org.springframework.cloud.function.context.FunctionType;
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration.BeanFactoryFunctionCatalog;
|
||||
import org.springframework.cloud.function.context.config.ContextFunctionCatalogAutoConfiguration.ContextFunctionRegistry;
|
||||
|
||||
@@ -55,6 +56,26 @@ public class BeanFactoryFunctionCatalogTests {
|
||||
assertThat(foos.apply(Flux.just(2)).blockFirst()).isEqualTo("4");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerFunctionWithType() {
|
||||
processor.register(new FunctionRegistration<Function<Integer, String>>(
|
||||
(Integer i) -> "i=" + i).names("foos").type(
|
||||
FunctionType.from(Integer.class).to(String.class).getType()));
|
||||
Function<Flux<Integer>, Flux<String>> foos = processor.lookupFunction("");
|
||||
assertThat(foos.apply(Flux.just(2)).blockFirst()).isEqualTo("i=2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void registerFunctionWithFluxType() {
|
||||
processor
|
||||
.register(new FunctionRegistration<Function<Flux<Integer>, Flux<String>>>(
|
||||
ints -> ints.map(i -> "i=" + i)).names("foos")
|
||||
.type(FunctionType.from(Integer.class).to(String.class)
|
||||
.wrap(Flux.class).getType()));
|
||||
Function<Flux<Integer>, Flux<String>> foos = processor.lookupFunction("");
|
||||
assertThat(foos.apply(Flux.just(2)).blockFirst()).isEqualTo("i=2");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void lookupNonExistentConsumerWithEmptyName() {
|
||||
processor.register(new FunctionRegistration<>(new Foos()).names("foos"));
|
||||
|
||||
Reference in New Issue
Block a user