GH-191 Made 'name' required in FunctionRegistration

This commit is contained in:
Oleg Zhurakousky
2018-07-30 13:48:48 +02:00
parent 32ee27165b
commit ed14474b9f
4 changed files with 25 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-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.
@@ -38,7 +38,6 @@ import reactor.core.publisher.Mono;
/**
* @author Dave Syer
* @author Oleg Zhurakousky
*
*/
public class FunctionRegistration<T> {
@@ -50,11 +49,30 @@ public class FunctionRegistration<T> {
private FunctionType type;
/**
* @deprecated as of v1.0.0 in favor of {@link #FunctionRegistration(Object, String, String...)}
*/
@Deprecated
public FunctionRegistration(T target) {
Assert.notNull(target, "'target' must not be null");
this.target = target;
}
/**
* Creates instance of FunctionRegistration.
*
* @param target instance of {@link Supplier}, {@link Function} or {@link Consumer}
* @param name initial name for this registration.
* @param names additional set of names for this registration. Additional names
* can be provided {@link #name(String)} or {@link #names(String...)} operations.
*/
public FunctionRegistration(T target, String name, String... additionalNames) {
Assert.notNull(target, "'target' must not be null");
this.target = target;
this.names(name);
this.names(additionalNames);
}
public Map<String, String> getProperties() {
return properties;
}

View File

@@ -65,6 +65,7 @@ public class InMemoryFunctionCatalog
@Override
public <T> void register(FunctionRegistration<T> registration) {
Assert.notEmpty(registration.getNames(), "'registration' must contain at least one name before it is registered in catalog.");
Class<?> type = Object.class;
if (registration.getTarget() instanceof Function) {
type = Function.class;

View File

@@ -82,6 +82,7 @@ import org.springframework.core.io.Resource;
import org.springframework.core.type.StandardMethodMetadata;
import org.springframework.core.type.classreading.MethodMetadataReadingVisitor;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;
import org.springframework.util.ClassUtils;
import org.springframework.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -128,6 +129,7 @@ public class ContextFunctionCatalogAutoConfiguration {
@Override
public <T> void register(FunctionRegistration<T> registration) {
Assert.notEmpty(registration.getNames(), "'registration' must contain at least one name before it is registered in catalog.");
processor.register(registration);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 the original author or authors.
* 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.
@@ -34,7 +34,7 @@ public class InMemoryFunctionCatalogTests {
@Test
public void testFunctionRegistration() {
TestFunction function = new TestFunction();
FunctionRegistration<TestFunction> registration = new FunctionRegistration<>(function)
FunctionRegistration<TestFunction> registration = new FunctionRegistration<>(function, "foo")
.type(FunctionType.of(TestFunction.class).getType());
InMemoryFunctionCatalog catalog = new InMemoryFunctionCatalog();
catalog.register(registration);