NIFI-728: Allow Mock Framework to use property descriptors from subclasses that are created for unit testing

This commit is contained in:
Mark Payne 2015-06-25 09:46:16 -04:00
parent 69297a3aa0
commit f58972e566
2 changed files with 19 additions and 3 deletions

View File

@ -22,14 +22,21 @@ import java.util.Map;
import org.apache.nifi.components.PropertyDescriptor;
import org.apache.nifi.components.PropertyValue;
import org.apache.nifi.controller.ConfigurationContext;
import org.apache.nifi.controller.ControllerService;
import org.apache.nifi.controller.ControllerServiceLookup;
public class MockConfigurationContext implements ConfigurationContext {
private final Map<PropertyDescriptor, String> properties;
private final ControllerServiceLookup serviceLookup;
private final ControllerService service;
public MockConfigurationContext(final Map<PropertyDescriptor, String> properties, final ControllerServiceLookup serviceLookup) {
this(null, properties, serviceLookup);
}
public MockConfigurationContext(final ControllerService service, final Map<PropertyDescriptor, String> properties, final ControllerServiceLookup serviceLookup) {
this.service = service;
this.properties = properties;
this.serviceLookup = serviceLookup;
}
@ -38,7 +45,7 @@ public class MockConfigurationContext implements ConfigurationContext {
public PropertyValue getProperty(final PropertyDescriptor property) {
String value = properties.get(property);
if (value == null) {
value = property.getDefaultValue();
value = getActualDescriptor(property).getDefaultValue();
}
return new MockPropertyValue(value, serviceLookup);
}
@ -47,4 +54,13 @@ public class MockConfigurationContext implements ConfigurationContext {
public Map<PropertyDescriptor, String> getProperties() {
return new HashMap<>(this.properties);
}
private PropertyDescriptor getActualDescriptor(final PropertyDescriptor property) {
if (service == null) {
return property;
}
final PropertyDescriptor resolved = service.getPropertyDescriptor(property.getName());
return resolved == null ? property : resolved;
}
}

View File

@ -215,7 +215,7 @@ public class StandardProcessorTestRunner implements TestRunner {
executorService.shutdown();
try {
executorService.awaitTermination(runWait, TimeUnit.MILLISECONDS);
} catch (InterruptedException e1) {
} catch (final InterruptedException e1) {
}
int finishedCount = 0;
@ -609,7 +609,7 @@ public class StandardProcessorTestRunner implements TestRunner {
}
try {
final ConfigurationContext configContext = new MockConfigurationContext(configuration.getProperties(), context);
final ConfigurationContext configContext = new MockConfigurationContext(service, configuration.getProperties(), context);
ReflectionUtils.invokeMethodsWithAnnotation(OnEnabled.class, service, configContext);
} catch (final InvocationTargetException ite) {
ite.getCause().printStackTrace();