Search in sources :

Example 1 with ModifiesClasspathNoAnnotationProcessor

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);
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ModifiesClasspathNoAnnotationProcessor(org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor) Test(org.junit.Test)

Example 2 with ModifiesClasspathNoAnnotationProcessor

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());
    }
}
Also used : NarCloseable(org.apache.nifi.nar.NarCloseable) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ModifiesClasspathNoAnnotationProcessor(org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor) URL(java.net.URL) Test(org.junit.Test)

Example 3 with ModifiesClasspathNoAnnotationProcessor

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) {
    }
}
Also used : ModifiesClasspathNoAnnotationProcessor(org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor) BundleCoordinate(org.apache.nifi.bundle.BundleCoordinate) ProcessorInstantiationException(org.apache.nifi.controller.exception.ProcessorInstantiationException) ReportingTaskInstantiationException(org.apache.nifi.controller.reporting.ReportingTaskInstantiationException) ProcessException(org.apache.nifi.processor.exception.ProcessException) MalformedURLException(java.net.MalformedURLException) ControllerServiceInstantiationException(org.apache.nifi.controller.exception.ControllerServiceInstantiationException) Test(org.junit.Test)

Aggregations

ModifiesClasspathNoAnnotationProcessor (org.apache.nifi.test.processors.ModifiesClasspathNoAnnotationProcessor)3 Test (org.junit.Test)3 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 BundleCoordinate (org.apache.nifi.bundle.BundleCoordinate)1 ControllerServiceInstantiationException (org.apache.nifi.controller.exception.ControllerServiceInstantiationException)1 ProcessorInstantiationException (org.apache.nifi.controller.exception.ProcessorInstantiationException)1 ReportingTaskInstantiationException (org.apache.nifi.controller.reporting.ReportingTaskInstantiationException)1 NarCloseable (org.apache.nifi.nar.NarCloseable)1 ProcessException (org.apache.nifi.processor.exception.ProcessException)1