use of org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor in project nifi by apache.
the class TestStandardProcessorNode method testDisabledValidationErrors.
@Test
public void testDisabledValidationErrors() {
final MockReloadComponent reloadComponent = new MockReloadComponent();
final ModifiesClasspathNoAnnotationProcessor processor = new ModifiesClasspathNoAnnotationProcessor();
final StandardProcessorNode procNode = createProcessorNode(processor, reloadComponent);
// Set a property to an invalid value
final Map<String, String> properties = new HashMap<>();
properties.put(ModifiesClasspathNoAnnotationProcessor.CLASSPATH_RESOURCE.getName(), "");
procNode.setProperties(properties);
Assert.assertTrue(procNode.getValidationErrors().size() > 0);
// Disabled processors skip property validation
procNode.disable();
Assert.assertFalse(procNode.getValidationErrors().size() > 0);
}
use of org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor in project nifi by apache.
the class TestStandardProcessorNode method testPropertyModifiesClasspathWhenProcessorMissingAnnotation.
@Test
public void testPropertyModifiesClasspathWhenProcessorMissingAnnotation() throws MalformedURLException {
final MockReloadComponent reloadComponent = new MockReloadComponent();
final ModifiesClasspathNoAnnotationProcessor processor = new ModifiesClasspathNoAnnotationProcessor();
final StandardProcessorNode procNode = createProcessorNode(processor, reloadComponent);
try (final NarCloseable narCloseable = NarCloseable.withComponentNarLoader(procNode.getProcessor().getClass(), procNode.getIdentifier())) {
final Map<String, String> properties = new HashMap<>();
properties.put(ModifiesClasspathNoAnnotationProcessor.CLASSPATH_RESOURCE.getName(), "src/test/resources/TestClasspathResources/resource1.txt");
procNode.setProperties(properties);
final URL[] testResources = getTestResources();
assertTrue(containsResource(reloadComponent.getAdditionalUrls(), testResources[0]));
assertFalse(containsResource(reloadComponent.getAdditionalUrls(), testResources[1]));
assertFalse(containsResource(reloadComponent.getAdditionalUrls(), testResources[2]));
assertEquals(ModifiesClasspathNoAnnotationProcessor.class.getCanonicalName(), reloadComponent.getNewType());
// Should pass validation
assertTrue(procNode.isValid());
} finally {
ExtensionManager.removeInstanceClassLoader(procNode.getIdentifier());
}
}
use of org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor in project nifi by apache.
the class TestStandardProcessorNode method testVerifyCanUpdateBundle.
@Test
public void testVerifyCanUpdateBundle() {
final ReloadComponent reloadComponent = new MockReloadComponent();
final ModifiesClasspathNoAnnotationProcessor processor = new ModifiesClasspathNoAnnotationProcessor();
final StandardProcessorNode procNode = createProcessorNode(processor, reloadComponent);
final BundleCoordinate existingCoordinate = procNode.getBundleCoordinate();
// should be allowed to update when the bundle is the same
procNode.verifyCanUpdateBundle(existingCoordinate);
// should be allowed to update when the group and id are the same but version is different
final BundleCoordinate diffVersion = new BundleCoordinate(existingCoordinate.getGroup(), existingCoordinate.getId(), "v2");
assertTrue(!existingCoordinate.getVersion().equals(diffVersion.getVersion()));
procNode.verifyCanUpdateBundle(diffVersion);
// should not be allowed to update when the bundle id is different
final BundleCoordinate diffId = new BundleCoordinate(existingCoordinate.getGroup(), "different-id", existingCoordinate.getVersion());
assertTrue(!existingCoordinate.getId().equals(diffId.getId()));
try {
procNode.verifyCanUpdateBundle(diffId);
Assert.fail("Should have thrown exception");
} catch (Exception e) {
}
// should not be allowed to update when the bundle group is different
final BundleCoordinate diffGroup = new BundleCoordinate("different-group", existingCoordinate.getId(), existingCoordinate.getVersion());
assertTrue(!existingCoordinate.getGroup().equals(diffGroup.getGroup()));
try {
procNode.verifyCanUpdateBundle(diffGroup);
Assert.fail("Should have thrown exception");
} catch (Exception e) {
}
}
Aggregations