use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.
the class StandardProcessorTestRunner method addControllerService.
@Override
public void addControllerService(final String identifier, final ControllerService service, final Map<String, String> properties) throws InitializationException {
final MockComponentLog logger = new MockComponentLog(identifier, service);
controllerServiceLoggers.put(identifier, logger);
final MockStateManager serviceStateManager = new MockStateManager(service);
final MockControllerServiceInitializationContext initContext = new MockControllerServiceInitializationContext(requireNonNull(service), requireNonNull(identifier), logger, serviceStateManager);
controllerServiceStateManagers.put(identifier, serviceStateManager);
initContext.addControllerServices(context);
service.initialize(initContext);
final Map<PropertyDescriptor, String> resolvedProps = new HashMap<>();
for (final Map.Entry<String, String> entry : properties.entrySet()) {
resolvedProps.put(service.getPropertyDescriptor(entry.getKey()), entry.getValue());
}
try {
ReflectionUtils.invokeMethodsWithAnnotation(OnAdded.class, service);
} catch (final InvocationTargetException | IllegalAccessException | IllegalArgumentException e) {
throw new InitializationException(e);
}
context.addControllerService(identifier, service, resolvedProps, null);
}
use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.
the class StandardProcessorTestRunner method setProperty.
@Override
public ValidationResult setProperty(final ControllerService service, final PropertyDescriptor property, final String value) {
final MockStateManager serviceStateManager = controllerServiceStateManagers.get(service.getIdentifier());
if (serviceStateManager == null) {
throw new IllegalStateException("Controller service " + service + " has not been added to this TestRunner via the #addControllerService method");
}
final ControllerServiceConfiguration configuration = getConfigToUpdate(service);
final Map<PropertyDescriptor, String> curProps = configuration.getProperties();
final Map<PropertyDescriptor, String> updatedProps = new HashMap<>(curProps);
final ValidationContext validationContext = new MockValidationContext(context, serviceStateManager, variableRegistry).getControllerServiceValidationContext(service);
final ValidationResult validationResult = property.validate(value, validationContext);
final String oldValue = updatedProps.get(property);
updatedProps.put(property, value);
configuration.setProperties(updatedProps);
if ((value == null && oldValue != null) || (value != null && !value.equals(oldValue))) {
service.onPropertyModified(property, oldValue, value);
}
return validationResult;
}
use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.
the class TestStandardProcessorTestRunner method testControllerServiceUpdateShouldCallOnSetProperty.
@Test
public void testControllerServiceUpdateShouldCallOnSetProperty() {
// Arrange
final ControllerService testService = new SimpleTestService();
final AddAttributeProcessor proc = new AddAttributeProcessor();
final TestRunner runner = TestRunners.newTestRunner(proc);
final String serviceIdentifier = "test";
final String pdName = "name";
final String pdValue = "exampleName";
try {
runner.addControllerService(serviceIdentifier, testService);
} catch (InitializationException e) {
fail(e.getMessage());
}
assertFalse("onPropertyModified has been called", ((SimpleTestService) testService).isOpmCalled());
// Act
ValidationResult vr = runner.setProperty(testService, pdName, pdValue);
// Assert
assertTrue(vr.isValid());
ControllerServiceConfiguration csConf = ((MockProcessContext) runner.getProcessContext()).getConfiguration(serviceIdentifier);
PropertyDescriptor propertyDescriptor = testService.getPropertyDescriptor(pdName);
String retrievedPDValue = csConf.getProperties().get(propertyDescriptor);
assertEquals(pdValue, retrievedPDValue);
assertTrue("onPropertyModified has not been called", ((SimpleTestService) testService).isOpmCalled());
}
use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.
the class TestCredentialsProviderFactory method testAssumeRoleCredentials.
@Test
public void testAssumeRoleCredentials() throws Throwable {
final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
runner.setProperty(CredentialPropertyDescriptors.CREDENTIALS_FILE, "src/test/resources/mock-aws-credentials.properties");
runner.setProperty(CredentialPropertyDescriptors.ASSUME_ROLE_ARN, "BogusArn");
runner.setProperty(CredentialPropertyDescriptors.ASSUME_ROLE_NAME, "BogusSession");
runner.assertValid();
Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
final CredentialsProviderFactory factory = new CredentialsProviderFactory();
final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
Assert.assertNotNull(credentialsProvider);
assertEquals("credentials provider should be equal", STSAssumeRoleSessionCredentialsProvider.class, credentialsProvider.getClass());
}
use of org.apache.nifi.components.PropertyDescriptor in project nifi by apache.
the class TestCredentialsProviderFactory method testAnonymousCredentials.
@Test
public void testAnonymousCredentials() throws Throwable {
final TestRunner runner = TestRunners.newTestRunner(MockAWSProcessor.class);
runner.setProperty(CredentialPropertyDescriptors.USE_ANONYMOUS_CREDENTIALS, "true");
runner.assertValid();
Map<PropertyDescriptor, String> properties = runner.getProcessContext().getProperties();
final CredentialsProviderFactory factory = new CredentialsProviderFactory();
final AWSCredentialsProvider credentialsProvider = factory.getCredentialsProvider(properties);
Assert.assertNotNull(credentialsProvider);
final AWSCredentials creds = credentialsProvider.getCredentials();
assertEquals("credentials should be equal", AnonymousAWSCredentials.class, creds.getClass());
}
Aggregations