Add support for spring.cloud.function.scan.packages in functional

Fixes gh-372
This commit is contained in:
Dave Syer
2019-06-06 16:40:17 +01:00
parent 40b070a8d1
commit 57689755f2
3 changed files with 78 additions and 2 deletions

View File

@@ -40,6 +40,7 @@ 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.FunctionInspector;
import org.springframework.cloud.function.context.scan.TestFunction;
import org.springframework.context.ApplicationContextInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.support.GenericApplicationContext;
@@ -162,8 +163,23 @@ public class ContextFunctionCatalogInitializerTests {
assertThat(function.apply(Flux.just("foo")).blockFirst()).isEqualTo("FOO");
assertThat(bean).isNotSameAs(function);
assertThat(this.inspector.getRegistration(function)).isNotNull();
assertThat(this.inspector.getRegistration(function).getType()).isEqualTo(
FunctionType.from(String.class).to(String.class));
assertThat(this.inspector.getRegistration(function).getType())
.isEqualTo(FunctionType.from(String.class).to(String.class));
}
@Test
public void scanFunction() {
create(EmptyConfiguration.class,
"spring.cloud.function.scan.packages=org.springframework.cloud.function.context.scan");
Object bean = this.context.getBean(TestFunction.class.getName());
assertThat(bean).isInstanceOf(Function.class);
Function<Flux<String>, Flux<String>> function = this.catalog
.lookup(Function.class, TestFunction.class.getName());
assertThat(function.apply(Flux.just("foo")).blockFirst()).isEqualTo("FOO");
assertThat(bean).isNotSameAs(function);
assertThat(this.inspector.getRegistration(function)).isNotNull();
assertThat(this.inspector.getRegistration(function).getType())
.isEqualTo(FunctionType.from(String.class).to(String.class));
}
@Test

View File

@@ -0,0 +1,32 @@
/*
* 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.scan;
import java.util.function.Function;
/**
* @author Dave Syer
*
*/
public class TestFunction implements Function<String, String> {
@Override
public String apply(String t) {
return t.toUpperCase();
}
}