diff --git a/nifi-nar-bundles/nifi-registry-bundle/nifi-registry-service/src/test/java/org/apache/nifi/schemaregistry/services/TestAvroSchemaRegistry.java b/nifi-nar-bundles/nifi-registry-bundle/nifi-registry-service/src/test/java/org/apache/nifi/schemaregistry/services/TestAvroSchemaRegistry.java index 0d72d819bd4d..b2851df6f2b5 100644 --- a/nifi-nar-bundles/nifi-registry-bundle/nifi-registry-service/src/test/java/org/apache/nifi/schemaregistry/services/TestAvroSchemaRegistry.java +++ b/nifi-nar-bundles/nifi-registry-bundle/nifi-registry-service/src/test/java/org/apache/nifi/schemaregistry/services/TestAvroSchemaRegistry.java @@ -16,15 +16,6 @@ */ package org.apache.nifi.schemaregistry.services; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.PropertyValue; import org.apache.nifi.components.ValidationContext; @@ -33,8 +24,17 @@ import org.apache.nifi.schema.access.SchemaNotFoundException; import org.apache.nifi.serialization.record.RecordSchema; import org.apache.nifi.serialization.record.SchemaIdentifier; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestAvroSchemaRegistry { @@ -63,16 +63,11 @@ public void validateSchemaRegistrationFromrDynamicProperties() throws Exception SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name(schemaName).build(); RecordSchema locatedSchema = delegate.retrieveSchema(schemaIdentifier); assertEquals(fooSchemaText, locatedSchema.getSchemaText().get()); - try { - delegate.retrieveSchema(SchemaIdentifier.builder().name("barSchema").build()); - Assert.fail("Expected a SchemaNotFoundException to be thrown but it was not"); - } catch (final SchemaNotFoundException expected) { - } - + assertThrows(SchemaNotFoundException.class, () -> delegate.retrieveSchema(SchemaIdentifier.builder().name("barSchema").build())); } @Test - public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() throws Exception { + public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() { String schemaName = "fooSchema"; ConfigurationContext configContext = mock(ConfigurationContext.class); Map properties = new HashMap<>(); diff --git a/nifi-nar-bundles/nifi-riemann-bundle/nifi-riemann-processors/src/test/java/org/apache/nifi/processors/riemann/TestPutRiemann.java b/nifi-nar-bundles/nifi-riemann-bundle/nifi-riemann-processors/src/test/java/org/apache/nifi/processors/riemann/TestPutRiemann.java index 5e712a560cb0..aeccd81a66f6 100644 --- a/nifi-nar-bundles/nifi-riemann-bundle/nifi-riemann-processors/src/test/java/org/apache/nifi/processors/riemann/TestPutRiemann.java +++ b/nifi-nar-bundles/nifi-riemann-bundle/nifi-riemann-processors/src/test/java/org/apache/nifi/processors/riemann/TestPutRiemann.java @@ -23,10 +23,8 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -37,8 +35,9 @@ import java.util.Queue; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyLong; import static org.mockito.Mockito.any; import static org.mockito.Mockito.anyList; @@ -46,13 +45,10 @@ import static org.mockito.Mockito.when; public class TestPutRiemann { - @Rule - public final ExpectedException expectedException = ExpectedException.none(); - // Holds incoming events to Riemann private Queue eventStream = new LinkedList(); - @Before + @BeforeEach public void clearEventStream() { eventStream.clear(); } @@ -174,8 +170,7 @@ public void testInvalidEvents() { runner.assertAllFlowFilesTransferred(PutRiemann.REL_FAILURE); } - - @Test(expected = AssertionError.class) + @Test public void testFailedDeref() { TestRunner runner = getTestRunner(true); MockFlowFile flowFile = new MockFlowFile(1); @@ -184,7 +179,7 @@ public void testFailedDeref() { flowFile.putAttributes(attributes); runner.enqueue(flowFile); try { - runner.run(); + assertThrows(AssertionError.class, () -> runner.run()); } catch (ProcessException e) { runner.assertQueueNotEmpty(); throw e; diff --git a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java index 6ca73d8cbdb2..58d1413e8038 100644 --- a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java +++ b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestActionHandlerLookup.java @@ -23,14 +23,15 @@ import org.apache.nifi.rules.Action; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; +import static org.junit.jupiter.api.Assertions.assertThrows; public class TestActionHandlerLookup { @@ -39,7 +40,7 @@ public class TestActionHandlerLookup { private ActionHandlerLookup actionHandlerLookup; private TestRunner runner; - @Before + @BeforeEach public void setup() throws InitializationException { alertHandler = new MockPropertyActionHandler(); logHandler = new MockPropertyActionHandler(); @@ -93,7 +94,7 @@ public void testLookupLog() { assert logHandler.getExecuteContextCalled(); } - @Test(expected = ProcessException.class) + @Test public void testLookupInvalidActionType() { final Map attributes = new HashMap<>(); final Map metrics = new HashMap<>(); @@ -103,7 +104,7 @@ public void testLookupInvalidActionType() { metrics.put("cpu", "90"); final Action action = new Action(); action.setType("FAKE"); - actionHandlerLookup.execute(null,action,metrics); + assertThrows(ProcessException.class, () -> actionHandlerLookup.execute(null,action,metrics)); } private static class MockPropertyActionHandler extends AbstractActionHandlerService { diff --git a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestAlertHandler.java b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestAlertHandler.java index 6a9c68463cc4..3688940a0b58 100644 --- a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestAlertHandler.java +++ b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestAlertHandler.java @@ -31,8 +31,8 @@ import org.apache.nifi.util.MockBulletinRepository; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -40,13 +40,13 @@ import java.util.List; import java.util.Map; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; public class TestAlertHandler { @@ -57,7 +57,7 @@ public class TestAlertHandler { private AlertHandler alertHandler; private MockAlertBulletinRepository mockAlertBulletinRepository; - @Before + @BeforeEach public void setup() throws InitializationException { runner = TestRunners.newTestRunner(TestProcessor.class); mockComponentLog = new MockComponentLog(); @@ -95,12 +95,7 @@ public void testAlertNoReportingContext() { final Action action = new Action(); action.setType("ALERT"); action.setAttributes(attributes); - try { - alertHandler.execute(action, metrics); - fail(); - } catch (UnsupportedOperationException ex) { - assertTrue(true); - } + assertThrows(UnsupportedOperationException.class, () -> alertHandler.execute(action, metrics)); } @Test @@ -247,11 +242,7 @@ public void testInvalidActionTypeException(){ final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext, action, metrics); - fail(); - } catch (UnsupportedOperationException ex) { - } + assertThrows(UnsupportedOperationException.class, () -> alertHandler.execute(reportingContext, action, metrics)); } @Test @@ -276,12 +267,9 @@ public void testInvalidActionTypeWarn(){ final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext,action, metrics); - assertTrue(true); - } catch (UnsupportedOperationException ex) { - fail(); - } + + assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics)); + final String warnMessage = mockComponentLog.getWarnMessage(); assertTrue(StringUtils.isNotEmpty(warnMessage)); assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); @@ -309,12 +297,8 @@ public void testInvalidActionTypeIgnore(){ final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext,action, metrics); - assertTrue(true); - } catch (UnsupportedOperationException ex) { - fail(); - } + assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics)); + final String debugMessage = mockComponentLog.getDebugMessage(); assertTrue(StringUtils.isNotEmpty(debugMessage)); assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); @@ -340,12 +324,7 @@ public void testValidActionType(){ final Action action = new Action(); action.setType("ALERT"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext,action, metrics); - assertTrue(true); - } catch (UnsupportedOperationException ex) { - fail(); - } + assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics)); } private static class MockAlertHandler extends AlertHandler { diff --git a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestExpressionHandler.java b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestExpressionHandler.java index 6abe826d5cc6..e65e17469c7f 100644 --- a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestExpressionHandler.java +++ b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestExpressionHandler.java @@ -22,17 +22,18 @@ import org.apache.nifi.rules.Action; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestExpressionHandler { @@ -40,7 +41,7 @@ public class TestExpressionHandler { private MockComponentLog mockComponentLog; private ExpressionHandler expressionHandler; - @Before + @BeforeEach public void setup() throws InitializationException { runner = TestRunners.newTestRunner(TestProcessor.class); mockComponentLog = new MockComponentLog(); @@ -151,12 +152,9 @@ public void testInvalidActionTypeException() { final Action action = new Action(); action.setType("FAKE"); - action.setAttributes(attributes); try { - expressionHandler.execute(action, metrics); - fail(); - } catch (UnsupportedOperationException ex) { - assertTrue(true); - } + action.setAttributes(attributes); + + assertThrows(UnsupportedOperationException.class, () -> expressionHandler.execute(action, metrics)); } @Test @@ -173,16 +171,13 @@ public void testInvalidActionTypeWarning() { final Action action = new Action(); action.setType("FAKE"); - action.setAttributes(attributes); try { - expressionHandler.execute(action, metrics); - } catch (UnsupportedOperationException ex) { - fail(); - } + action.setAttributes(attributes); + + assertDoesNotThrow(() -> expressionHandler.execute(action, metrics)); final String warnMessage = mockComponentLog.getWarnMessage(); assertTrue(StringUtils.isNotEmpty(warnMessage)); assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); - } @Test @@ -199,11 +194,9 @@ public void testInvalidActionTypeIgnore() { final Action action = new Action(); action.setType("FAKE"); - action.setAttributes(attributes); try { - expressionHandler.execute(action, metrics); - } catch (UnsupportedOperationException ex) { - fail(); - } + action.setAttributes(attributes); + + assertDoesNotThrow(() -> expressionHandler.execute(action, metrics)); final String debugMessage = mockComponentLog.getDebugMessage(); assertTrue(StringUtils.isNotEmpty(debugMessage)); @@ -224,12 +217,7 @@ public void testValidActionType() { final Action action = new Action(); action.setType("EXPRESSION"); action.setAttributes(attributes); - try { - expressionHandler.execute(action, metrics); - assertTrue(true); - } catch (UnsupportedOperationException ex) { - fail(); - } + assertDoesNotThrow(() -> expressionHandler.execute(action, metrics)); } diff --git a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestLogHandler.java b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestLogHandler.java index b40ca32133b8..671e48504221 100644 --- a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestLogHandler.java +++ b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestLogHandler.java @@ -16,24 +16,24 @@ */ package org.apache.nifi.rules.handlers; -import junit.framework.TestCase; import org.apache.commons.lang3.StringUtils; import org.apache.nifi.logging.ComponentLog; import org.apache.nifi.reporting.InitializationException; import org.apache.nifi.rules.Action; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; -import static junit.framework.TestCase.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestLogHandler { @@ -41,7 +41,7 @@ public class TestLogHandler { MockComponentLog mockComponentLog; LogHandler logHandler; - @Before + @BeforeEach public void setup() throws InitializationException { runner = TestRunners.newTestRunner(TestProcessor.class); mockComponentLog = new MockComponentLog(); @@ -159,12 +159,7 @@ public void testInvalidActionTypeException() { final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - logHandler.execute(action, metrics); - fail(); - } catch (UnsupportedOperationException ex) { - assertTrue(true); - } + assertThrows(UnsupportedOperationException.class, () -> logHandler.execute(action, metrics)); } @Test @@ -191,15 +186,11 @@ public void testInvalidActionTypeWarning() { final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - logHandler.execute(action, metrics); - } catch (UnsupportedOperationException ex) { - fail(); - } + assertDoesNotThrow(() -> logHandler.execute(action, metrics)); final String warnMessage = mockComponentLog.getWarnMessage(); assertTrue(StringUtils.isNotEmpty(warnMessage)); - TestCase.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); + assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); } @Test @@ -226,15 +217,12 @@ public void testInvalidActionTypeDebug() { final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - logHandler.execute(action, metrics); - } catch (UnsupportedOperationException ex) { - fail(); - } + + assertDoesNotThrow(() -> logHandler.execute(action, metrics)); final String debugMessage = mockComponentLog.getDebugMessage(); assertTrue(StringUtils.isNotEmpty(debugMessage)); - TestCase.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); + assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); } @Test @@ -260,12 +248,8 @@ public void testValidActionType() { final Action action = new Action(); action.setType("LOG"); action.setAttributes(attributes); - try { - logHandler.execute(action, metrics); - assertTrue(true); - } catch (UnsupportedOperationException ex) { - fail(); - } + + assertDoesNotThrow(() -> logHandler.execute(action, metrics)); } private static class MockLogHandler extends LogHandler { diff --git a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestRecordSinkHandler.java b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestRecordSinkHandler.java index bd11534f8cd9..fb5f342200ed 100644 --- a/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestRecordSinkHandler.java +++ b/nifi-nar-bundles/nifi-rules-action-handler-bundle/nifi-rules-action-handler-service/src/test/java/org/apache/nifi/rules/handlers/TestRecordSinkHandler.java @@ -30,8 +30,8 @@ import org.apache.nifi.serialization.record.RecordSet; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigDecimal; @@ -41,11 +41,11 @@ import java.util.List; import java.util.Map; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestRecordSinkHandler { private TestRunner runner; @@ -53,7 +53,7 @@ public class TestRecordSinkHandler { private RecordSinkHandler recordSinkHandler; private MockRecordSinkService recordSinkService; - @Before + @BeforeEach public void setup() throws InitializationException { runner = TestRunners.newTestRunner(TestProcessor.class); mockComponentLog = new MockComponentLog(); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestScriptedLookupService.groovy b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestScriptedLookupService.groovy index 9c788efe2bdf..abb3daf02472 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestScriptedLookupService.groovy +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestScriptedLookupService.groovy @@ -26,9 +26,9 @@ import org.apache.nifi.script.ScriptingComponentUtils import org.apache.nifi.util.MockFlowFile import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Test +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -38,8 +38,9 @@ import java.nio.file.Paths import java.nio.file.StandardCopyOption import static junit.framework.TestCase.assertEquals -import static org.junit.Assert.assertFalse -import static org.junit.Assert.assertTrue +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue + /** * Unit tests for the ScriptedLookupService controller service */ @@ -52,7 +53,7 @@ class TestScriptedLookupService { def scriptingComponent - @BeforeClass + @BeforeAll static void setUpOnce() throws Exception { logger.metaClass.methodMissing = {String name, args -> logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}") @@ -61,7 +62,7 @@ class TestScriptedLookupService { TARGET_PATH.toFile().deleteOnExit() } - @Before + @BeforeEach void setUp() { scriptedLookupService = new MockScriptedLookupService() scriptingComponent = (AccessibleScriptingComponentHelper) scriptedLookupService diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestSimpleScriptedLookupService.groovy b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestSimpleScriptedLookupService.groovy index b7e32eb92310..0c7f44a296ed 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestSimpleScriptedLookupService.groovy +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/lookup/script/TestSimpleScriptedLookupService.groovy @@ -26,9 +26,9 @@ import org.apache.nifi.script.ScriptingComponentUtils import org.apache.nifi.util.MockFlowFile import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Test +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -37,9 +37,10 @@ import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardCopyOption -import static junit.framework.TestCase.assertEquals -import static org.junit.Assert.assertFalse -import static org.junit.Assert.assertTrue +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertFalse +import static org.junit.jupiter.api.Assertions.assertTrue + /** * Unit tests for the SimpleScriptedLookupService controller service */ @@ -52,7 +53,7 @@ class TestSimpleScriptedLookupService { def scriptingComponent - @BeforeClass + @BeforeAll static void setUpOnce() throws Exception { logger.metaClass.methodMissing = {String name, args -> logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}") @@ -61,7 +62,7 @@ class TestSimpleScriptedLookupService { TARGET_PATH.toFile().deleteOnExit() } - @Before + @BeforeEach void setUp() { scriptedLookupService = new MockScriptedLookupService() scriptingComponent = (AccessibleScriptingComponentHelper) scriptedLookupService diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy index 063efe4d5e39..39ede15b8f04 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/processors/script/ExecuteScriptGroovyTest.groovy @@ -18,34 +18,26 @@ package org.apache.nifi.processors.script import org.apache.nifi.script.ScriptingComponentUtils import org.apache.nifi.util.MockFlowFile -import org.apache.nifi.util.StopWatch import org.apache.nifi.util.TestRunners -import org.junit.After -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Ignore -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import org.slf4j.Logger import org.slf4j.LoggerFactory -import java.util.concurrent.TimeUnit +import static org.junit.jupiter.api.Assertions.assertNotNull -import static org.junit.Assert.assertNotNull - -@RunWith(JUnit4.class) class ExecuteScriptGroovyTest extends BaseScriptTest { private static final Logger logger = LoggerFactory.getLogger(ExecuteScriptGroovyTest.class) - @BeforeClass + @BeforeAll static void setUpOnce() throws Exception { logger.metaClass.methodMissing = { String name, args -> logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}") } } - @Before + @BeforeEach void setUp() throws Exception { super.setupExecuteScript() @@ -55,10 +47,6 @@ class ExecuteScriptGroovyTest extends BaseScriptTest { runner.setProperty(ScriptingComponentUtils.MODULES, TEST_RESOURCE_LOCATION + "groovy") } - @After - void tearDown() throws Exception { - } - private void setupPooledExecuteScript(int poolSize = 2) { final ExecuteScript executeScript = new ExecuteScript() // Need to do something to initialize the properties, like retrieve the list of properties @@ -150,56 +138,6 @@ class ExecuteScriptGroovyTest extends BaseScriptTest { } } - @Ignore("This test fails intermittently when the serial execution happens faster than pooled") - @Test - void testPooledExecutionShouldBeFaster() throws Exception { - // Arrange - final int ITERATIONS = 1000 - final int POOL_SIZE = 4 - - // Act - // Run serially and capture the timing - final StopWatch stopWatch = new StopWatch(true) - runner.run(ITERATIONS) - stopWatch.stop() - final long serialExecutionTime = stopWatch.getDuration(TimeUnit.MILLISECONDS) - logger.info("Serial execution time for ${ITERATIONS} executions: ${serialExecutionTime} ms") - - // Assert (1) - runner.assertAllFlowFilesTransferred(ExecuteScript.REL_SUCCESS, ITERATIONS) - final List serialResults = runner.getFlowFilesForRelationship(ExecuteScript.REL_SUCCESS) - - // Now run parallel - setupPooledExecuteScript(POOL_SIZE) - logger.info("Set up ExecuteScript processor with pool size: ${POOL_SIZE}") - runner.setThreadCount(POOL_SIZE) - runner.assertValid() - - stopWatch.start() - runner.run(ITERATIONS) - stopWatch.stop() - final long parallelExecutionTime = stopWatch.getDuration(TimeUnit.MILLISECONDS) - logger.info("Parallel execution time for ${ITERATIONS} executions using ${POOL_SIZE} threads: ${parallelExecutionTime} ms") - - // Assert (2) - runner.assertAllFlowFilesTransferred(ExecuteScript.REL_SUCCESS, ITERATIONS) - final List parallelResults = runner.getFlowFilesForRelationship(ExecuteScript.REL_SUCCESS) - - parallelResults.eachWithIndex { MockFlowFile flowFile, int i -> - flowFile.assertAttributeExists("time-updated") - flowFile.assertAttributeExists("thread") - assert flowFile.getAttribute("thread") =~ /pool-\d+-thread-[1-${POOL_SIZE}]/ - } - - serialResults.eachWithIndex { MockFlowFile flowFile, int i -> - flowFile.assertAttributeExists("time-updated") - flowFile.assertAttributeExists("thread") - assert flowFile.getAttribute("thread") =~ /pool-\d+-thread-1/ - } - - assert serialExecutionTime > parallelExecutionTime - } - @Test void testExecuteScriptRecompileOnChange() throws Exception { diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedReaderTest.groovy b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedReaderTest.groovy index cb80284f0ce9..8cb5b2213ce9 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedReaderTest.groovy +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedReaderTest.groovy @@ -27,22 +27,22 @@ import org.apache.nifi.serialization.RecordReader import org.apache.nifi.util.MockComponentLog import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardCopyOption -import static junit.framework.TestCase.assertEquals -import static org.junit.Assert.* +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertNotNull +import static org.junit.jupiter.api.Assertions.assertNull +import static org.junit.jupiter.api.Assertions.assertTrue + /** * Unit tests for the ScriptedReader class */ -@RunWith(JUnit4.class) class ScriptedReaderTest { private static final String READER_INLINE_SCRIPT = "test_record_reader_inline.groovy" private static final String READER_XML_SCRIPT = "test_record_reader_xml.groovy" @@ -57,7 +57,7 @@ class ScriptedReaderTest { def runner def scriptingComponent - @Before + @BeforeEach void setUp() { recordReaderFactory = new MockScriptedReader() runner = TestRunners diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedRecordSetWriterTest.groovy b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedRecordSetWriterTest.groovy index 57958733302a..3ff9a3422f35 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedRecordSetWriterTest.groovy +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/record/script/ScriptedRecordSetWriterTest.groovy @@ -32,11 +32,9 @@ import org.apache.nifi.serialization.record.RecordSet import org.apache.nifi.util.MockComponentLog import org.apache.nifi.util.TestRunner import org.apache.nifi.util.TestRunners -import org.junit.Before -import org.junit.BeforeClass -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 +import org.junit.jupiter.api.BeforeAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import org.slf4j.Logger import org.slf4j.LoggerFactory @@ -45,13 +43,12 @@ import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardCopyOption -import static org.junit.Assert.assertEquals -import static org.junit.Assert.assertNotNull +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertNotNull /** * Unit tests for the ScriptedReader class */ -@RunWith(JUnit4.class) class ScriptedRecordSetWriterTest { private static final Logger logger = LoggerFactory.getLogger(ScriptedRecordSetWriterTest) @@ -63,7 +60,7 @@ class ScriptedRecordSetWriterTest { def scriptingComponent - @BeforeClass + @BeforeAll static void setUpOnce() throws Exception { logger.metaClass.methodMissing = {String name, args -> logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}") @@ -72,7 +69,7 @@ class ScriptedRecordSetWriterTest { TARGET_PATH.toFile().deleteOnExit() } - @Before + @BeforeEach void setUp() { recordSetWriterFactory = new MockScriptedWriter() runner = TestRunners diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/reporting/script/ScriptedReportingTaskTest.groovy b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/reporting/script/ScriptedReportingTaskTest.groovy index 609fbb57d6f9..55f777c4cc74 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/reporting/script/ScriptedReportingTaskTest.groovy +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/groovy/org/apache/nifi/reporting/script/ScriptedReportingTaskTest.groovy @@ -29,23 +29,21 @@ import org.apache.nifi.util.MockConfigurationContext import org.apache.nifi.util.MockEventAccess import org.apache.nifi.util.MockReportingContext import org.apache.nifi.util.TestRunners -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.junit.runners.JUnit4 +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths import java.nio.file.StandardCopyOption -import static org.junit.Assert.assertEquals -import static org.junit.Assert.assertTrue +import static org.junit.jupiter.api.Assertions.assertEquals +import static org.junit.jupiter.api.Assertions.assertTrue import static org.mockito.Mockito.* /** * Unit tests for ScriptedReportingTask. */ -@RunWith(JUnit4.class) + class ScriptedReportingTaskTest { private static final String PROVENANCE_EVENTS_SCRIPT = "test_log_provenance_events.groovy" private static final String LOG_VM_STATS = "test_log_vm_stats.groovy" @@ -56,7 +54,7 @@ class ScriptedReportingTaskTest { def runner def scriptingComponent - @Before + @BeforeEach void setUp() { task = new MockScriptedReportingTask() runner = TestRunners @@ -195,6 +193,4 @@ class ScriptedReportingTaskTest { return this.@scriptingComponentHelper } } - - } \ No newline at end of file diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/BaseScriptTest.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/BaseScriptTest.java index 03ff29c85b50..e77cf4d402cf 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/BaseScriptTest.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/BaseScriptTest.java @@ -20,14 +20,14 @@ import org.apache.nifi.script.ScriptingComponentHelper; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.BeforeClass; +import org.junit.jupiter.api.BeforeAll; import java.io.File; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Paths; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; /** * An abstract class with common methods, variables, etc. used by scripting processor unit tests @@ -44,7 +44,7 @@ public abstract class BaseScriptTest { * * @throws Exception Any error encountered while testing */ - @BeforeClass + @BeforeAll public static void setupBeforeClass() throws Exception { FileUtils.copyDirectory(new File("src/test/resources"), new File("target/test/resources")); } diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteClojure.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteClojure.java index 99b377cbf3e1..b99ba4516c56 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteClojure.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteClojure.java @@ -18,15 +18,14 @@ import org.apache.nifi.script.ScriptingComponentUtils; import org.apache.nifi.util.MockFlowFile; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; -import static org.junit.Assert.assertEquals; - +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestExecuteClojure extends BaseScriptTest { @@ -34,7 +33,7 @@ public class TestExecuteClojure extends BaseScriptTest { + "female,miss,marlene,shaw\n" + "male,mr,todd,graham"; - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteGroovy.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteGroovy.java index 449f37a660a7..f91dad1e1497 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteGroovy.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteGroovy.java @@ -19,17 +19,16 @@ import org.apache.nifi.script.ScriptingComponentUtils; import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.MockProcessContext; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestExecuteGroovy extends BaseScriptTest { @@ -37,7 +36,7 @@ public class TestExecuteGroovy extends BaseScriptTest { + "female,miss,marlene,shaw\n" + "male,mr,todd,graham"; - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } @@ -85,10 +84,9 @@ public void testNoIncomingFlowFile() throws Exception { /** * Tests a script file that creates and transfers a new flow file. * - * @throws Exception Any error encountered while testing */ @Test - public void testInvalidConfiguration() throws Exception { + public void testInvalidConfiguration() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION); @@ -100,10 +98,9 @@ public void testInvalidConfiguration() throws Exception { /** * Tests a script file that creates and transfers a new flow file. * - * @throws Exception Any error encountered while testing */ @Test - public void testCreateNewFlowFileWithScriptFile() throws Exception { + public void testCreateNewFlowFileWithScriptFile() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "groovy/test_onTrigger_newFlowFile.groovy"); @@ -123,10 +120,9 @@ public void testCreateNewFlowFileWithScriptFile() throws Exception { /** * Tests a script file that creates and transfers a new flow file. * - * @throws Exception Any error encountered while testing */ @Test - public void testCreateNewFlowFileWithNoInputFile() throws Exception { + public void testCreateNewFlowFileWithNoInputFile() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, @@ -144,10 +140,9 @@ public void testCreateNewFlowFileWithNoInputFile() throws Exception { /** * Tests a script file that creates and transfers a new flow file. * - * @throws Exception Any error encountered while testing */ @Test - public void testDynamicProperties() throws Exception { + public void testDynamicProperties() { runner.setValidateExpressionUsage(true); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "groovy/test_dynamicProperties.groovy"); @@ -168,10 +163,9 @@ public void testDynamicProperties() throws Exception { /** * Tests a script file that changes the content of the incoming flowfile. * - * @throws Exception Any error encountered while testing */ @Test - public void testChangeFlowFileWithScriptFile() throws Exception { + public void testChangeFlowFileWithScriptFile() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_onTrigger_changeContent.groovy"); @@ -192,10 +186,9 @@ public void testChangeFlowFileWithScriptFile() throws Exception { /** * Tests a script that has provides the body of an onTrigger() function. * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBody() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBody() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -216,10 +209,9 @@ public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBody() t * Tests a script that has provides the body of an onTrigger() function, where the ExecuteScript processor does * not specify a modules path * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBodyNoModules() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBodyNoModules() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -237,10 +229,9 @@ public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBodyNoMo /** * Tests a script that does not transfer or remove the original flow file, thereby causing an error during commit. * - * @throws Exception Any error encountered while testing. Expecting */ - @Test(expected = AssertionError.class) - public void testScriptNoTransfer() throws Exception { + @Test + public void testScriptNoTransfer() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -249,17 +240,15 @@ public void testScriptNoTransfer() throws Exception { runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - runner.run(); - + assertThrows(AssertionError.class, () -> runner.run()); } /** * Tests a script that uses a dynamic property to set a FlowFile attribute. * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileCustomAttribute() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileCustomAttribute() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -280,23 +269,19 @@ public void testReadFlowFileContentAndStoreInFlowFileCustomAttribute() throws Ex * Tests a script that throws an Exception within. The expected result is that the flow file is rolled back * and penalized. Besides we check that we yielded the processor. * - * @throws Exception Any error encountered while testing */ @Test - public void testScriptException() throws Exception { + public void testScriptException() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(TEST_RESOURCE_LOCATION + "groovy/testScriptException.groovy")); runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - try { - runner.run(); - fail(); - } catch (AssertionError e) { - runner.assertPenalizeCount(1); // penalized - runner.assertQueueNotEmpty(); // flow file back in the input queue - assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled()); // processor yielded - } + + assertThrows(AssertionError.class, () -> runner.run()); + runner.assertPenalizeCount(1); // penalized + runner.assertQueueNotEmpty(); // flow file back in the input queue + assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled()); } } diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJRuby.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJRuby.java index 843bd5a11b27..d1af2f8d9df1 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJRuby.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJRuby.java @@ -20,28 +20,24 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; - public class TestExecuteJRuby extends BaseScriptTest { - - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } - /** * Tests a script that has provides the body of an onTrigger() function. * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttribute() { final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript()); runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ruby"); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java index e07ced07796d..643513a241d2 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java @@ -20,16 +20,15 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; - public class TestExecuteJavascript extends BaseScriptTest { - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } @@ -37,10 +36,9 @@ public void setup() throws Exception { /** * Tests a script that has provides the body of an onTrigger() function. * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttribute() { final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript()); runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJython.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJython.java index d682669b565d..4a987d172cae 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJython.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJython.java @@ -18,19 +18,21 @@ import org.apache.nifi.script.ScriptingComponentUtils; import org.apache.nifi.util.MockFlowFile; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.condition.EnabledIfSystemProperty; import java.nio.charset.StandardCharsets; import java.util.List; +import static org.junit.jupiter.api.Assertions.assertThrows; + /** * Unit tests for ExecuteScript with Jython. */ public class TestExecuteJython extends BaseScriptTest { - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } @@ -62,10 +64,9 @@ public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBody() t /** * Tests a script that does not transfer or remove the original flow file, thereby causing an error during commit. * - * @throws Exception Any error encountered while testing. Expecting */ - @Test(expected = AssertionError.class) - public void testScriptNoTransfer() throws Exception { + @Test + public void testScriptNoTransfer() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, @@ -73,12 +74,12 @@ public void testScriptNoTransfer() throws Exception { runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - runner.run(); + assertThrows(AssertionError.class, () -> runner.run()); } - @Ignore("This is more of an integration test, can be run before and after changes to ExecuteScript to measure performance improvements") + @EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true") @Test - public void testPerformance() throws Exception { + public void testPerformance() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteLua.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteLua.java index 4e72f7dedfc1..6e9aaa122a90 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteLua.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteLua.java @@ -20,28 +20,25 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; - public class TestExecuteLua extends BaseScriptTest { - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } - /** * Tests a script that has provides the body of an onTrigger() function. * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttribute() { final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript()); runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "lua"); @@ -56,5 +53,4 @@ public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exceptio final List result = runner.getFlowFilesForRelationship(ExecuteScript.REL_SUCCESS); result.get(0).assertAttributeEquals("from-content", "test content"); } - } diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java index 7934aae39ec9..a3e948f38de1 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java @@ -30,22 +30,21 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.apache.nifi.util.security.MessageDigestUtils; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestInvokeGroovy extends BaseScriptTest { - - @Before + @BeforeEach public void setup() throws Exception { super.setupInvokeScriptProcessor(); } @@ -53,10 +52,9 @@ public void setup() throws Exception { /** * Tests a script that has a Groovy Processor that that reads the first line of text from the flowfiles content and stores the value in an attribute of the outgoing flowfile. * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttribute() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy"); runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy"); @@ -74,10 +72,9 @@ public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exceptio * Tests a script that has a Groovy Processor that that reads the first line of text from the flowfiles content and * stores the value in an attribute of the outgoing flowfile. * - * @throws Exception Any error encountered while testing */ @Test - public void testScriptDefinedAttribute() throws Exception { + public void testScriptDefinedAttribute() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context); @@ -108,10 +105,9 @@ public void testScriptDefinedAttribute() throws Exception { * Tests a script that has a Groovy Processor that that reads the first line of text from the flowfiles content and * stores the value in an attribute of the outgoing flowfile. * - * @throws Exception Any error encountered while testing */ @Test - public void testScriptDefinedRelationship() throws Exception { + public void testScriptDefinedRelationship() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context); @@ -141,10 +137,9 @@ public void testScriptDefinedRelationship() throws Exception { * Tests a script that throws a ProcessException within. The expected result is that the exception will be * propagated * - * @throws Exception Any error encountered while testing */ - @Test(expected = AssertionError.class) - public void testInvokeScriptCausesException() throws Exception { + @Test + public void testInvokeScriptCausesException() { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -152,17 +147,15 @@ public void testInvokeScriptCausesException() throws Exception { ); runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - runner.run(); - + assertThrows(AssertionError.class, () -> runner.run()); } /** * Tests a script that routes the FlowFile to failure. * - * @throws Exception Any error encountered while testing */ @Test - public void testScriptRoutesToFailure() throws Exception { + public void testScriptRoutesToFailure() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( TEST_RESOURCE_LOCATION + "groovy/testScriptRoutesToFailure.groovy") @@ -177,7 +170,7 @@ public void testScriptRoutesToFailure() throws Exception { } @Test - public void testValidationResultsReset() throws Exception { + public void testValidationResultsReset() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy"); runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy"); @@ -190,10 +183,9 @@ public void testValidationResultsReset() throws Exception { /** * Tests a script that derive from AbstractProcessor as base class * - * @throws Exception Any error encountered while testing */ @Test - public void testAbstractProcessorImplementationWithBodyScriptFile() throws Exception { + public void testAbstractProcessorImplementationWithBodyScriptFile() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(TEST_RESOURCE_LOCATION + "groovy/test_implementingabstractProcessor.groovy")); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java index 9118f5a2e6c7..6003a9e14b7c 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJavascript.java @@ -25,20 +25,21 @@ import org.apache.nifi.util.MockValidationContext; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; import java.util.Set; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestInvokeJavascript extends BaseScriptTest { - @Before + @BeforeEach public void setup() throws Exception { super.setupInvokeScriptProcessor(); } @@ -48,10 +49,10 @@ public void setup() throws Exception { * and stores the value in an attribute of the outgoing flowfile. * Confirms that the scripted processor transfers the incoming flowfile with an attribute added. * - * @throws Exception Any error encountered while testing + * @Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttribute() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js"); runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/javascript"); @@ -70,10 +71,10 @@ public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exceptio * stores the value in an attribute of the outgoing flowfile. * Confirms that the scripted processor can return property descriptors defined in it. * - * @throws Exception Any error encountered while testing + * @Any error encountered while testing */ @Test - public void testScriptDefinedAttribute() throws Exception { + public void testScriptDefinedAttribute() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context); @@ -105,10 +106,10 @@ public void testScriptDefinedAttribute() throws Exception { * stores the value in an attribute of the outgoing flowfile. * Confirms that the scripted processor can return relationships defined in it. * - * @throws Exception Any error encountered while testing + * @Any error encountered while testing */ @Test - public void testScriptDefinedRelationship() throws Exception { + public void testScriptDefinedRelationship() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context); @@ -140,10 +141,9 @@ public void testScriptDefinedRelationship() throws Exception { * Tests a script that throws a ProcessException within. * The expected result is that the exception will be propagated. * - * @throws Exception Any error encountered while testing */ - @Test(expected = AssertionError.class) - public void testInvokeScriptCausesException() throws Exception { + @Test + public void testInvokeScriptCausesException() { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -151,17 +151,16 @@ public void testInvokeScriptCausesException() throws Exception { ); runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - runner.run(); - + assertThrows(AssertionError.class, () -> runner.run()); } /** * Tests a script that routes the FlowFile to failure. * - * @throws Exception Any error encountered while testing + * @Any error encountered while testing */ @Test - public void testScriptRoutesToFailure() throws Exception { + public void testScriptRoutesToFailure() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( TEST_RESOURCE_LOCATION + "javascript/testScriptRoutesToFailure.js") @@ -178,10 +177,10 @@ public void testScriptRoutesToFailure() throws Exception { /** * Tests an empty script with Nashorn (which throws an NPE if it is loaded), this test verifies an empty script is not attempted to be loaded. * - * @throws Exception Any error encountered while testing + * @Any error encountered while testing */ @Test - public void testEmptyScript() throws Exception { + public void testEmptyScript() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, ""); runner.assertNotValid(); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java index 3b90d4ac9687..bef3fb2fc329 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java @@ -23,8 +23,8 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.Collection; @@ -39,7 +39,7 @@ public class TestInvokeJython extends BaseScriptTest { * * @throws Exception Any error encountered while testing */ - @Before + @BeforeEach public void setup() throws Exception { super.setupInvokeScriptProcessor(); } @@ -47,10 +47,9 @@ public void setup() throws Exception { /** * Tests a script that has a Jython processor that is always invalid. * - * @throws Exception Any error encountered while testing */ @Test - public void testAlwaysInvalid() throws Exception { + public void testAlwaysInvalid() { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); @@ -64,10 +63,9 @@ public void testAlwaysInvalid() throws Exception { /** * Tests a script that has a Jython processor that begins invalid then is fixed. * - * @throws Exception Any error encountered while testing */ @Test - public void testInvalidThenFixed() throws Exception { + public void testInvalidThenFixed() { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); @@ -94,10 +92,9 @@ public void testInvalidThenFixed() throws Exception { * This may seem contrived but it verifies that the Jython processors properties are being considered and are able to be set and validated. It verifies the processor is able to access the property * values and flowfile attribute values during onTrigger. Lastly, it verifies the processor is able to route the flowfile to a relationship it specified. * - * @throws Exception Any error encountered while testing */ @Test - public void testUpdateAttributeFromProcessorPropertyAndFlowFileAttribute() throws Exception { + public void testUpdateAttributeFromProcessorPropertyAndFlowFileAttribute() { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); @@ -124,10 +121,9 @@ public void testUpdateAttributeFromProcessorPropertyAndFlowFileAttribute() throw /** * Tests a script that has a Jython Processor that that reads the first line of text from the flowfiles content and stores the value in an attribute of the outgoing flowfile. * - * @throws Exception Any error encountered while testing */ @Test - public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { + public void testReadFlowFileContentAndStoreInFlowFileAttribute() { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); @@ -147,10 +143,9 @@ public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exceptio /** * Tests compression and decompression using two different InvokeScriptedProcessor processor instances. A string is compressed and decompressed and compared. * - * @throws Exception Any error encountered while testing */ @Test - public void testCompressor() throws Exception { + public void testCompressor() { final TestRunner one = TestRunners.newTestRunner(new InvokeScriptedProcessor()); one.setValidateExpressionUsage(false); one.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); @@ -185,10 +180,9 @@ public void testCompressor() throws Exception { /** * Tests a script file that creates and transfers a new flow file. * - * @throws Exception Any error encountered while testing */ @Test - public void testInvalidConfiguration() throws Exception { + public void testInvalidConfiguration() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedTransformRecord.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedTransformRecord.java index c29311a2a5b5..6f6e522cd900 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedTransformRecord.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestScriptedTransformRecord.java @@ -30,7 +30,7 @@ import org.apache.nifi.util.MockFlowFile; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.ArrayList; import java.util.Collections; @@ -39,10 +39,10 @@ import java.util.Map; import java.util.Optional; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertSame; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestScriptedTransformRecord { diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/record/sink/script/ScriptedRecordSinkTest.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/record/sink/script/ScriptedRecordSinkTest.java index cf8d8485f8bf..f141587c17ec 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/record/sink/script/ScriptedRecordSinkTest.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/record/sink/script/ScriptedRecordSinkTest.java @@ -36,7 +36,7 @@ import org.apache.nifi.serialization.record.RecordSet; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Arrays; @@ -44,8 +44,7 @@ import java.util.List; import java.util.Map; -import static org.junit.Assert.assertEquals; - +import static org.junit.jupiter.api.Assertions.assertEquals; public class ScriptedRecordSinkTest { @@ -101,7 +100,6 @@ public void onTrigger(final ProcessContext context, final ProcessSession session } public static class MockScriptedRecordSink extends ScriptedRecordSink implements AccessibleScriptingComponentHelper { - @Override public ScriptingComponentHelper getScriptingComponentHelper() { return this.scriptingComponentHelper; diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/engine/script/ScriptedRulesEngineTest.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/engine/script/ScriptedRulesEngineTest.java index 4e9174920835..f6e8a93d1fe6 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/engine/script/ScriptedRulesEngineTest.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/engine/script/ScriptedRulesEngineTest.java @@ -28,8 +28,8 @@ import org.apache.nifi.serialization.record.MockRecordWriter; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.HashMap; @@ -43,7 +43,7 @@ public class ScriptedRulesEngineTest { private Map facts = new HashMap<>(); - @Before + @BeforeEach public void setup() { facts.put("predictedQueuedCount", 60); facts.put("predictedTimeToBytesBackpressureMillis", 299999); diff --git a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/handlers/script/ScriptedActionHandlerTest.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/handlers/script/ScriptedActionHandlerTest.java index 727ca7ff49a7..d0399b3b737b 100644 --- a/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/handlers/script/ScriptedActionHandlerTest.java +++ b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/rules/handlers/script/ScriptedActionHandlerTest.java @@ -34,8 +34,8 @@ import org.apache.nifi.util.MockBulletinRepository; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -64,7 +64,7 @@ public class ScriptedActionHandlerTest { private Map facts = new HashMap<>(); private Map attrs = new HashMap<>(); - @Before + @BeforeEach public void setup() { facts.put("predictedQueuedCount", 60); facts.put("predictedTimeToBytesBackpressureMillis", 299999);