From e93dbcac9d496d0839fe8ee93016431eaa7195db Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Mon, 30 Aug 2021 15:10:44 -0400 Subject: [PATCH 1/7] NIFI-9144 Refactored nifi-registry-bundle to use JUnit 5. --- .../services/TestAvroSchemaRegistry.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) 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..c360fd970f51 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,15 @@ 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.Assertions; +import org.junit.jupiter.api.Test; + +import java.util.Collection; +import java.util.HashMap; +import java.util.Map; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; public class TestAvroSchemaRegistry { @@ -62,10 +60,10 @@ public void validateSchemaRegistrationFromrDynamicProperties() throws Exception SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name(schemaName).build(); RecordSchema locatedSchema = delegate.retrieveSchema(schemaIdentifier); - assertEquals(fooSchemaText, locatedSchema.getSchemaText().get()); + Assertions.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"); + Assertions.fail("Expected a SchemaNotFoundException to be thrown but it was not"); } catch (final SchemaNotFoundException expected) { } @@ -104,11 +102,11 @@ public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() // Strict parsing when(propertyValue.asBoolean()).thenReturn(true); Collection results = delegate.customValidate(validationContext); - assertTrue(results.stream().anyMatch(result -> !result.isValid())); + Assertions.assertTrue(results.stream().anyMatch(result -> !result.isValid())); // Non-strict parsing when(propertyValue.asBoolean()).thenReturn(false); results = delegate.customValidate(validationContext); - results.forEach(result -> assertTrue(result.isValid())); + results.forEach(result -> Assertions.assertTrue(result.isValid())); } } From 66d07babc7d36cd61a98d03b8edd5bfe50d3dfa4 Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Tue, 31 Aug 2021 08:04:22 -0400 Subject: [PATCH 2/7] NIFI-9146 Refactored nifi-riemann-bundle to use JUnit 5. --- .../processors/riemann/TestPutRiemann.java | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) 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; From 5562e5d88b7a690ab18beb619b6a3eedaedcbe46 Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Tue, 31 Aug 2021 08:08:43 -0400 Subject: [PATCH 3/7] NIFI-9147 Refactored nifi-rules-action-handler-bundle to use JUnit 5. --- .../handlers/TestActionHandlerLookup.java | 11 ++-- .../nifi/rules/handlers/TestAlertHandler.java | 66 +++++++++---------- .../rules/handlers/TestExpressionHandler.java | 50 +++++++------- .../nifi/rules/handlers/TestLogHandler.java | 47 +++++++------ .../rules/handlers/TestRecordSinkHandler.java | 26 ++++---- 5 files changed, 95 insertions(+), 105 deletions(-) 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..c4b3ef69bc00 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,10 @@ 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.hamcrest.MatcherAssert; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.ArrayList; @@ -40,13 +42,7 @@ import java.util.List; import java.util.Map; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; 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.mockito.ArgumentMatchers.anyString; public class TestAlertHandler { @@ -57,7 +53,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(); @@ -78,7 +74,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(alertHandler); - assertThat(alertHandler, instanceOf(AlertHandler.class)); + MatcherAssert.assertThat(alertHandler, instanceOf(AlertHandler.class)); } @Test @@ -97,9 +93,9 @@ public void testAlertNoReportingContext() { action.setAttributes(attributes); try { alertHandler.execute(action, metrics); - fail(); + Assertions.fail(); } catch (UnsupportedOperationException ex) { - assertTrue(true); + Assertions.assertTrue(true); } } @@ -129,11 +125,11 @@ public void testAlertWithBulletinLevel() { alertHandler.execute(reportingContext, action, metrics); BulletinRepository bulletinRepository = reportingContext.getBulletinRepository(); List bulletins = bulletinRepository.findBulletinsForController(); - assertFalse(bulletins.isEmpty()); + Assertions.assertFalse(bulletins.isEmpty()); Bulletin bulletin = bulletins.get(0); - assertEquals(bulletin.getCategory(), category); - assertEquals(bulletin.getMessage(), expectedOutput); - assertEquals(bulletin.getLevel(), severity); + Assertions.assertEquals(bulletin.getCategory(), category); + Assertions.assertEquals(bulletin.getMessage(), expectedOutput); + Assertions.assertEquals(bulletin.getLevel(), severity); } @Test @@ -159,11 +155,11 @@ public void testAlertWithDefaultValues() { alertHandler.execute(reportingContext, action, metrics); BulletinRepository bulletinRepository = reportingContext.getBulletinRepository(); List bulletins = bulletinRepository.findBulletinsForController(); - assertFalse(bulletins.isEmpty()); + Assertions.assertFalse(bulletins.isEmpty()); Bulletin bulletin = bulletins.get(0); - assertEquals(bulletin.getCategory(), category); - assertEquals(bulletin.getMessage(), expectedOutput); - assertEquals(bulletin.getLevel(), severity); + Assertions.assertEquals(bulletin.getCategory(), category); + Assertions.assertEquals(bulletin.getMessage(), expectedOutput); + Assertions.assertEquals(bulletin.getLevel(), severity); } @Test @@ -196,8 +192,8 @@ public Map getAllProperties() { }; alertHandler.execute(fakeContext, action, metrics); final String debugMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(debugMessage)); - assertEquals(debugMessage,"Reporting context was not provided to create bulletins."); + Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); + Assertions.assertEquals(debugMessage,"Reporting context was not provided to create bulletins."); } @Test @@ -221,8 +217,8 @@ public void testEmptyBulletinRepository(){ Mockito.when(reportingContext.getBulletinRepository()).thenReturn(null); alertHandler.execute(fakeContext, action, metrics); final String warnMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(warnMessage)); - assertEquals(warnMessage,"Bulletin Repository is not available which is unusual. Cannot send a bulletin."); + Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); + Assertions.assertEquals(warnMessage,"Bulletin Repository is not available which is unusual. Cannot send a bulletin."); } @Test @@ -249,7 +245,7 @@ public void testInvalidActionTypeException(){ action.setAttributes(attributes); try { alertHandler.execute(reportingContext, action, metrics); - fail(); + Assertions.fail(); } catch (UnsupportedOperationException ex) { } } @@ -278,13 +274,13 @@ public void testInvalidActionTypeWarn(){ action.setAttributes(attributes); try { alertHandler.execute(reportingContext,action, metrics); - assertTrue(true); + Assertions.assertTrue(true); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } final String warnMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(warnMessage)); - assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); + Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); } @Test @@ -311,13 +307,13 @@ public void testInvalidActionTypeIgnore(){ action.setAttributes(attributes); try { alertHandler.execute(reportingContext,action, metrics); - assertTrue(true); + Assertions.assertTrue(true); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } final String debugMessage = mockComponentLog.getDebugMessage(); - assertTrue(StringUtils.isNotEmpty(debugMessage)); - assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); + Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); } @Test @@ -342,9 +338,9 @@ public void testValidActionType(){ action.setAttributes(attributes); try { alertHandler.execute(reportingContext,action, metrics); - assertTrue(true); + Assertions.assertTrue(true); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } } 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..a27dfe85bd3b 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,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.hamcrest.MatcherAssert; +import org.junit.jupiter.api.Assertions; +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.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; public class TestExpressionHandler { @@ -40,7 +38,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(); @@ -55,7 +53,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(expressionHandler); - assertThat(expressionHandler, instanceOf(ExpressionHandler.class)); + MatcherAssert.assertThat(expressionHandler, instanceOf(ExpressionHandler.class)); } @Test @@ -75,8 +73,8 @@ public void testMvelExpression(){ action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getDebugMessage(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertTrue(logMessage.startsWith(expectedMessage)); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -95,8 +93,8 @@ public void testSpelExpression(){ action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getDebugMessage(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertTrue(logMessage.startsWith(expectedMessage)); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -115,8 +113,8 @@ public void testInvalidType() { action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertTrue(logMessage.startsWith(expectedMessage)); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -133,8 +131,8 @@ public void testNoCommandProvided() { action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertTrue(logMessage.startsWith(expectedMessage)); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -153,9 +151,9 @@ public void testInvalidActionTypeException() { action.setType("FAKE"); action.setAttributes(attributes); try { expressionHandler.execute(action, metrics); - fail(); + Assertions.fail(); } catch (UnsupportedOperationException ex) { - assertTrue(true); + Assertions.assertTrue(true); } } @@ -176,12 +174,12 @@ public void testInvalidActionTypeWarning() { action.setAttributes(attributes); try { expressionHandler.execute(action, metrics); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } final String warnMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(warnMessage)); - assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); + Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); } @@ -202,12 +200,12 @@ public void testInvalidActionTypeIgnore() { action.setAttributes(attributes); try { expressionHandler.execute(action, metrics); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } final String debugMessage = mockComponentLog.getDebugMessage(); - assertTrue(StringUtils.isNotEmpty(debugMessage)); - assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); + Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); } @Test @@ -226,9 +224,9 @@ public void testValidActionType() { action.setAttributes(attributes); try { expressionHandler.execute(action, metrics); - assertTrue(true); + Assertions.assertTrue(true); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } } 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..0e62a58b3c98 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,21 @@ */ 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.hamcrest.MatcherAssert; +import org.junit.jupiter.api.Assertions; +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.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; public class TestLogHandler { @@ -41,7 +38,7 @@ public class TestLogHandler { MockComponentLog mockComponentLog; LogHandler logHandler; - @Before + @BeforeEach public void setup() throws InitializationException { runner = TestRunners.newTestRunner(TestProcessor.class); mockComponentLog = new MockComponentLog(); @@ -57,7 +54,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(logHandler); - assertThat(logHandler, instanceOf(LogHandler.class)); + MatcherAssert.assertThat(logHandler, instanceOf(LogHandler.class)); } @Test @@ -81,8 +78,8 @@ public void testWarningLogged() { action.setAttributes(attributes); logHandler.execute(action, metrics); String logMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertEquals(expectedMessage, logMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertEquals(expectedMessage, logMessage); } @Test @@ -104,8 +101,8 @@ public void testNoLogAttributesProvided() { action.setAttributes(attributes); logHandler.execute(action, metrics); String logMessage = mockComponentLog.getInfoMessage(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertEquals(expectedMessage, logMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertEquals(expectedMessage, logMessage); } @@ -130,8 +127,8 @@ public void testInvalidLogLevelProvided() { action.setAttributes(attributes); logHandler.execute(action, metrics); String logMessage = mockComponentLog.getInfoMessage(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertEquals(expectedMessage, logMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertEquals(expectedMessage, logMessage); } @@ -161,9 +158,9 @@ public void testInvalidActionTypeException() { action.setAttributes(attributes); try { logHandler.execute(action, metrics); - fail(); + Assertions.fail(); } catch (UnsupportedOperationException ex) { - assertTrue(true); + Assertions.assertTrue(true); } } @@ -194,12 +191,12 @@ public void testInvalidActionTypeWarning() { try { logHandler.execute(action, metrics); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } final String warnMessage = mockComponentLog.getWarnMessage(); - assertTrue(StringUtils.isNotEmpty(warnMessage)); - TestCase.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); + Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); } @Test @@ -229,12 +226,12 @@ public void testInvalidActionTypeDebug() { try { logHandler.execute(action, metrics); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } final String debugMessage = mockComponentLog.getDebugMessage(); - assertTrue(StringUtils.isNotEmpty(debugMessage)); - TestCase.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); + Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); + Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); } @Test @@ -262,9 +259,9 @@ public void testValidActionType() { action.setAttributes(attributes); try { logHandler.execute(action, metrics); - assertTrue(true); + Assertions.assertTrue(true); } catch (UnsupportedOperationException ex) { - fail(); + Assertions.fail(); } } 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..30a573af1fee 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,10 @@ 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.hamcrest.MatcherAssert; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.math.BigDecimal; @@ -41,11 +43,7 @@ import java.util.List; import java.util.Map; -import static junit.framework.TestCase.assertEquals; -import static junit.framework.TestCase.assertTrue; import static org.hamcrest.core.IsInstanceOf.instanceOf; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThat; public class TestRecordSinkHandler { private TestRunner runner; @@ -53,7 +51,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(); @@ -72,7 +70,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(recordSinkHandler); - assertThat(recordSinkHandler, instanceOf(RecordSinkHandler.class)); + MatcherAssert.assertThat(recordSinkHandler, instanceOf(RecordSinkHandler.class)); } @Test @@ -93,13 +91,13 @@ public void testRecordSendViaSink() throws InitializationException, IOException recordSinkHandler.execute(action, metrics); String logMessage = mockComponentLog.getDebugMessage(); List> rows = recordSinkService.getRows(); - assertTrue(StringUtils.isNotEmpty(logMessage)); - assertTrue(logMessage.startsWith(expectedMessage)); - assertFalse(rows.isEmpty()); + Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); + Assertions.assertTrue(logMessage.startsWith(expectedMessage)); + Assertions.assertFalse(rows.isEmpty()); Map record = rows.get(0); - assertEquals("90", (record.get("cpu"))); - assertEquals("1000000", (record.get("jvmHeap"))); - assertEquals(bigDecimalValue, (record.get("custom"))); + Assertions.assertEquals("90", (record.get("cpu"))); + Assertions.assertEquals("1000000", (record.get("jvmHeap"))); + Assertions.assertEquals(bigDecimalValue, (record.get("custom"))); } private static class MockRecordSinkHandler extends RecordSinkHandler { From 114a6f1ee7ba3c7100724659fde8bf2008b3d57a Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Tue, 31 Aug 2021 08:17:13 -0400 Subject: [PATCH 4/7] NIFI-9148 Refactored nifi-scripting-bundle to use JUnit 5. --- .../processors/script/BaseScriptTest.java | 4 +-- .../processors/script/TestExecuteClojure.java | 8 +++--- .../processors/script/TestExecuteGroovy.java | 12 ++++----- .../processors/script/TestExecuteJRuby.java | 6 ++--- .../script/TestExecuteJavascript.java | 6 ++--- .../processors/script/TestExecuteJython.java | 23 +++++++++-------- .../processors/script/TestExecuteLua.java | 6 ++--- .../processors/script/TestInvokeGroovy.java | 19 +++++++------- .../script/TestInvokeJavascript.java | 25 +++++++++---------- .../processors/script/TestInvokeJython.java | 16 ++++++------ .../script/TestScriptedTransformRecord.java | 12 ++++----- .../sink/script/ScriptedRecordSinkTest.java | 2 +- .../script/ScriptedRulesEngineTest.java | 6 ++--- .../script/ScriptedActionHandlerTest.java | 10 ++++---- 14 files changed, 78 insertions(+), 77 deletions(-) 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..b149b75026e6 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,7 +20,7 @@ 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; @@ -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..30cb1a4698e6 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,8 +18,8 @@ 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; @@ -34,7 +34,7 @@ public class TestExecuteClojure extends BaseScriptTest { + "female,miss,marlene,shaw\n" + "male,mr,todd,graham"; - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } @@ -65,7 +65,7 @@ public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptFile() t * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testNoIncomingFlowFile() throws Exception { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Clojure"); 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..52a1321b0bf6 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,8 +19,8 @@ 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; @@ -29,6 +29,7 @@ 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.assertThrows; public class TestExecuteGroovy extends BaseScriptTest { @@ -37,7 +38,7 @@ public class TestExecuteGroovy extends BaseScriptTest { + "female,miss,marlene,shaw\n" + "male,mr,todd,graham"; - @Before + @BeforeEach public void setup() throws Exception { super.setupExecuteScript(); } @@ -239,7 +240,7 @@ public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBodyNoMo * * @throws Exception Any error encountered while testing. Expecting */ - @Test(expected = AssertionError.class) + @Test public void testScriptNoTransfer() throws Exception { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); @@ -249,8 +250,7 @@ public void testScriptNoTransfer() throws Exception { runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - runner.run(); - + assertThrows(AssertionError.class, () -> runner.run()); } /** 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..702c9584fcd9 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,8 +20,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.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; @@ -29,7 +29,7 @@ public class TestExecuteJRuby extends BaseScriptTest { - @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/TestExecuteJavascript.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJavascript.java index e07ced07796d..c408c5212320 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,8 +20,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.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; @@ -29,7 +29,7 @@ public class TestExecuteJavascript extends BaseScriptTest { - @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/TestExecuteJython.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestExecuteJython.java index d682669b565d..4cf600d6d9e3 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,22 @@ 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.Disabled; +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 +65,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 +75,13 @@ 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") +// @Disabled("This is more of an integration test, can be run before and after changes to ExecuteScript to measure performance improvements") @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..d61a02e1e91f 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,8 +20,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.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.nio.charset.StandardCharsets; import java.util.List; @@ -29,7 +29,7 @@ public class TestExecuteLua extends BaseScriptTest { - @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/TestInvokeGroovy.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java index 7934aae39ec9..d474fed03dd6 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,8 +30,8 @@ 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; @@ -41,11 +41,12 @@ 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.assertThrows; public class TestInvokeGroovy extends BaseScriptTest { - @Before + @BeforeEach public void setup() throws Exception { super.setupInvokeScriptProcessor(); } @@ -55,7 +56,7 @@ public void setup() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy"); @@ -110,7 +111,7 @@ public void testScriptDefinedAttribute() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testScriptDefinedRelationship() throws Exception { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); @@ -141,10 +142,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,8 +152,7 @@ public void testInvokeScriptCausesException() throws Exception { ); runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - runner.run(); - + assertThrows(AssertionError.class, () -> runner.run()); } /** 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..ec1c1e96a02a 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,8 +25,8 @@ 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; @@ -35,10 +35,11 @@ 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.assertThrows; public class TestInvokeJavascript extends BaseScriptTest { - @Before + @BeforeEach public void setup() throws Exception { super.setupInvokeScriptProcessor(); } @@ -50,7 +51,7 @@ public void setup() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js"); @@ -72,7 +73,7 @@ public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exceptio * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testScriptDefinedAttribute() throws Exception { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); @@ -107,7 +108,7 @@ public void testScriptDefinedAttribute() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testScriptDefinedRelationship() throws Exception { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); @@ -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,8 +151,7 @@ public void testInvokeScriptCausesException() throws Exception { ); runner.assertValid(); runner.enqueue("test content".getBytes(StandardCharsets.UTF_8)); - runner.run(); - + assertThrows(AssertionError.class, () -> runner.run()); } /** @@ -160,7 +159,7 @@ public void testInvokeScriptCausesException() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testScriptRoutesToFailure() throws Exception { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -180,7 +179,7 @@ public void testScriptRoutesToFailure() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testEmptyScript() throws Exception { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); 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/TestInvokeJython.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeJython.java index 3b90d4ac9687..0b794341cab3 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(); } @@ -49,7 +49,7 @@ public void setup() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testAlwaysInvalid() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setValidateExpressionUsage(false); @@ -66,7 +66,7 @@ public void testAlwaysInvalid() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testInvalidThenFixed() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setValidateExpressionUsage(false); @@ -96,7 +96,7 @@ public void testInvalidThenFixed() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testUpdateAttributeFromProcessorPropertyAndFlowFileAttribute() throws Exception { final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor()); runner.setValidateExpressionUsage(false); @@ -149,7 +149,7 @@ public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exceptio * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testCompressor() throws Exception { final TestRunner one = TestRunners.newTestRunner(new InvokeScriptedProcessor()); one.setValidateExpressionUsage(false); @@ -187,7 +187,7 @@ public void testCompressor() throws Exception { * * @throws Exception Any error encountered while testing */ - @Test + @org.junit.jupiter.api.Test public void testInvalidConfiguration() throws Exception { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python"); 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..9febe6b42521 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; @@ -55,7 +55,7 @@ public void testSimpleGroovyScript() throws InitializationException { testPassThrough("Groovy", "record"); } - @Test + @org.junit.jupiter.api.Test public void testSimpleJythonScript() throws InitializationException { testPassThrough("python", "_ = record"); } @@ -128,7 +128,7 @@ public void testAddFieldToSchema() throws InitializationException { } - @Test + @org.junit.jupiter.api.Test public void testZeroRecordInput() throws InitializationException { final RecordSchema schema = createSimpleNumberSchema(); setup(schema); @@ -173,7 +173,7 @@ public void testAllRecordsFiltered() throws InitializationException { - @Test + @org.junit.jupiter.api.Test public void testCollectionOfRecords() throws InitializationException { final RecordSchema schema = createSimpleNumberSchema(); setup(schema); @@ -325,7 +325,7 @@ public void testScriptReturnsNull() throws InitializationException { assertEquals(4, recordsWritten.get(1).getAsInt("num").intValue()); } - @Test + @org.junit.jupiter.api.Test public void testScriptReturnsWrongObject() throws InitializationException { final RecordSchema schema = createSimpleNumberSchema(); setup(schema); @@ -375,7 +375,7 @@ public void testScriptReturnsCollectionWithWrongObject() throws InitializationEx assertSame(inputFlowFile, out); } - @Test + @org.junit.jupiter.api.Test public void testScriptWithFunctions() throws InitializationException { final List bookFields = new ArrayList<>(); bookFields.add(new RecordField("author", RecordFieldType.STRING.getDataType())); 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..ecef43db8860 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; 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..dc43c059f91b 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); @@ -72,7 +72,7 @@ public void setup() { attrs.put("message", "Time to backpressure < 5 mins"); } - @Test + @org.junit.jupiter.api.Test public void testActions() throws InitializationException { actionHandler = initTask("src/test/resources/groovy/test_action_handler.groovy"); List actions = Arrays.asList(new Action("LOG", attrs), new Action("ALERT", attrs)); @@ -97,7 +97,7 @@ public void testActionHandlerNotPropertyContextActionHandler() throws Initializa assertEquals(42, facts.get("testFact")); } - @Test + @org.junit.jupiter.api.Test public void testPropertyContextActionHandler() throws InitializationException { actionHandler = initTask("src/test/resources/groovy/test_propertycontext_action_handler.groovy"); mockScriptedBulletinRepository = new MockScriptedBulletinRepository(); From b4d810aa1ba152dd8a9574c6ed93c5938df53df8 Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Tue, 31 Aug 2021 11:17:32 -0400 Subject: [PATCH 5/7] NIFI-9148 Refactored the nifi-scripting-bundle to use JUnit 5. --- .../script/TestScriptedLookupService.groovy | 15 ++++---- .../TestSimpleScriptedLookupService.groovy | 17 +++++---- .../script/ExecuteScriptGroovyTest.groovy | 27 ++++++-------- .../record/script/ScriptedReaderTest.groovy | 16 ++++---- .../script/ScriptedRecordSetWriterTest.groovy | 17 ++++----- .../script/ScriptedReportingTaskTest.groovy | 16 +++----- .../processors/script/BaseScriptTest.java | 2 +- .../processors/script/TestExecuteClojure.java | 3 +- .../processors/script/TestExecuteGroovy.java | 37 +++++++------------ .../processors/script/TestExecuteJRuby.java | 6 +-- .../script/TestExecuteJavascript.java | 4 +- .../processors/script/TestExecuteJython.java | 2 - .../processors/script/TestExecuteLua.java | 6 +-- .../processors/script/TestInvokeGroovy.java | 27 +++++--------- .../script/TestInvokeJavascript.java | 26 ++++++------- .../processors/script/TestInvokeJython.java | 28 ++++++-------- .../script/TestScriptedTransformRecord.java | 18 ++++----- .../sink/script/ScriptedRecordSinkTest.java | 4 +- 18 files changed, 111 insertions(+), 160 deletions(-) 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..fc001a263faf 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 @@ -20,32 +20,28 @@ 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.junit.jupiter.api.condition.EnabledIfSystemProperty import org.slf4j.Logger import org.slf4j.LoggerFactory import java.util.concurrent.TimeUnit -import static org.junit.Assert.assertNotNull +import static org.junit.jupiter.api.Assertions.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 +51,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,7 +142,10 @@ class ExecuteScriptGroovyTest extends BaseScriptTest { } } - @Ignore("This test fails intermittently when the serial execution happens faster than pooled") + @EnabledIfSystemProperty( + named = "nifi.test.unstable", + matches = "true", + disabledReason = "This test fails intermittently when the serial execution happens faster than pooled") @Test void testPooledExecutionShouldBeFaster() throws Exception { // Arrange 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 b149b75026e6..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 @@ -27,7 +27,7 @@ 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 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 30cb1a4698e6..d5a26f91f5e8 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 @@ -25,8 +25,7 @@ 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 { 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 52a1321b0bf6..b511ccd71eb9 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 @@ -26,11 +26,10 @@ 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; +import static org.junit.jupiter.api.Assertions.fail; public class TestExecuteGroovy extends BaseScriptTest { @@ -86,10 +85,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); @@ -101,10 +99,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"); @@ -124,10 +121,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, @@ -145,10 +141,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"); @@ -169,10 +164,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"); @@ -193,10 +187,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( @@ -217,10 +210,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( @@ -238,10 +230,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 - public void testScriptNoTransfer() throws Exception { + public void testScriptNoTransfer() { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -256,10 +247,9 @@ public void testScriptNoTransfer() throws Exception { /** * 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,10 +270,9 @@ 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")); 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 702c9584fcd9..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 @@ -26,22 +26,18 @@ import java.nio.charset.StandardCharsets; import java.util.List; - public class TestExecuteJRuby extends BaseScriptTest { - @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 c408c5212320..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 @@ -26,7 +26,6 @@ import java.nio.charset.StandardCharsets; import java.util.List; - public class TestExecuteJavascript extends BaseScriptTest { @BeforeEach @@ -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 4cf600d6d9e3..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 @@ -19,7 +19,6 @@ import org.apache.nifi.script.ScriptingComponentUtils; import org.apache.nifi.util.MockFlowFile; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.EnabledIfSystemProperty; @@ -79,7 +78,6 @@ public void testScriptNoTransfer() { } @EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true") -// @Disabled("This is more of an integration test, can be run before and after changes to ExecuteScript to measure performance improvements") @Test public void testPerformance() { runner.setValidateExpressionUsage(false); 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 d61a02e1e91f..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 @@ -26,7 +26,6 @@ import java.nio.charset.StandardCharsets; import java.util.List; - public class TestExecuteLua extends BaseScriptTest { @BeforeEach @@ -34,14 +33,12 @@ 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 d474fed03dd6..ed69e6a1a8ce 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 @@ -37,15 +37,13 @@ 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 { - @BeforeEach public void setup() throws Exception { super.setupInvokeScriptProcessor(); @@ -54,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 */ @org.junit.jupiter.api.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"); @@ -75,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); @@ -109,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 */ @org.junit.jupiter.api.Test - public void testScriptDefinedRelationship() throws Exception { + public void testScriptDefinedRelationship() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context); @@ -158,10 +153,9 @@ public void testInvokeScriptCausesException() { /** * 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") @@ -176,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"); @@ -189,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 ec1c1e96a02a..ea2d65e12561 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 @@ -32,10 +32,10 @@ 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 { @@ -49,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 */ @org.junit.jupiter.api.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"); @@ -71,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 */ @org.junit.jupiter.api.Test - public void testScriptDefinedAttribute() throws Exception { + public void testScriptDefinedAttribute() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context); @@ -106,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 */ @org.junit.jupiter.api.Test - public void testScriptDefinedRelationship() throws Exception { + public void testScriptDefinedRelationship() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context); @@ -157,10 +157,10 @@ public void testInvokeScriptCausesException() { /** * Tests a script that routes the FlowFile to failure. * - * @throws Exception Any error encountered while testing + * @Any error encountered while testing */ @org.junit.jupiter.api.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") @@ -177,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 */ @org.junit.jupiter.api.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 0b794341cab3..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 @@ -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 */ - @org.junit.jupiter.api.Test - public void testAlwaysInvalid() throws Exception { + @Test + 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 */ - @org.junit.jupiter.api.Test - public void testInvalidThenFixed() throws Exception { + @Test + 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 */ - @org.junit.jupiter.api.Test - public void testUpdateAttributeFromProcessorPropertyAndFlowFileAttribute() throws Exception { + @Test + 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 */ - @org.junit.jupiter.api.Test - public void testCompressor() throws Exception { + @Test + 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 */ - @org.junit.jupiter.api.Test - public void testInvalidConfiguration() throws Exception { + @Test + 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 9febe6b42521..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 @@ -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 { @@ -55,7 +55,7 @@ public void testSimpleGroovyScript() throws InitializationException { testPassThrough("Groovy", "record"); } - @org.junit.jupiter.api.Test + @Test public void testSimpleJythonScript() throws InitializationException { testPassThrough("python", "_ = record"); } @@ -128,7 +128,7 @@ public void testAddFieldToSchema() throws InitializationException { } - @org.junit.jupiter.api.Test + @Test public void testZeroRecordInput() throws InitializationException { final RecordSchema schema = createSimpleNumberSchema(); setup(schema); @@ -173,7 +173,7 @@ public void testAllRecordsFiltered() throws InitializationException { - @org.junit.jupiter.api.Test + @Test public void testCollectionOfRecords() throws InitializationException { final RecordSchema schema = createSimpleNumberSchema(); setup(schema); @@ -325,7 +325,7 @@ public void testScriptReturnsNull() throws InitializationException { assertEquals(4, recordsWritten.get(1).getAsInt("num").intValue()); } - @org.junit.jupiter.api.Test + @Test public void testScriptReturnsWrongObject() throws InitializationException { final RecordSchema schema = createSimpleNumberSchema(); setup(schema); @@ -375,7 +375,7 @@ public void testScriptReturnsCollectionWithWrongObject() throws InitializationEx assertSame(inputFlowFile, out); } - @org.junit.jupiter.api.Test + @Test public void testScriptWithFunctions() throws InitializationException { final List bookFields = new ArrayList<>(); bookFields.add(new RecordField("author", RecordFieldType.STRING.getDataType())); 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 ecef43db8860..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 @@ -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; From e502161dcc97e4dc95820a7f00d16c5b8c252a5a Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Wed, 1 Sep 2021 12:24:45 -0400 Subject: [PATCH 6/7] Made multiple changes requested in a code review. --- .../services/TestAvroSchemaRegistry.java | 19 ++--- .../nifi/rules/handlers/TestAlertHandler.java | 75 +++++++------------ .../rules/handlers/TestExpressionHandler.java | 62 +++++++-------- .../nifi/rules/handlers/TestLogHandler.java | 53 +++++-------- .../rules/handlers/TestRecordSinkHandler.java | 16 ++-- .../script/ExecuteScriptGroovyTest.groovy | 57 -------------- .../processors/script/TestExecuteClojure.java | 2 +- .../processors/script/TestExecuteGroovy.java | 14 ++-- .../processors/script/TestInvokeGroovy.java | 4 +- .../script/TestInvokeJavascript.java | 10 +-- .../script/ScriptedActionHandlerTest.java | 4 +- 11 files changed, 107 insertions(+), 209 deletions(-) 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 c360fd970f51..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 @@ -24,13 +24,15 @@ import org.apache.nifi.schema.access.SchemaNotFoundException; import org.apache.nifi.serialization.record.RecordSchema; import org.apache.nifi.serialization.record.SchemaIdentifier; -import org.junit.jupiter.api.Assertions; 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; @@ -60,17 +62,12 @@ public void validateSchemaRegistrationFromrDynamicProperties() throws Exception SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name(schemaName).build(); RecordSchema locatedSchema = delegate.retrieveSchema(schemaIdentifier); - Assertions.assertEquals(fooSchemaText, locatedSchema.getSchemaText().get()); - try { - delegate.retrieveSchema(SchemaIdentifier.builder().name("barSchema").build()); - Assertions.fail("Expected a SchemaNotFoundException to be thrown but it was not"); - } catch (final SchemaNotFoundException expected) { - } - + assertEquals(fooSchemaText, locatedSchema.getSchemaText().get()); + 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<>(); @@ -102,11 +99,11 @@ public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() // Strict parsing when(propertyValue.asBoolean()).thenReturn(true); Collection results = delegate.customValidate(validationContext); - Assertions.assertTrue(results.stream().anyMatch(result -> !result.isValid())); + assertTrue(results.stream().anyMatch(result -> !result.isValid())); // Non-strict parsing when(propertyValue.asBoolean()).thenReturn(false); results = delegate.customValidate(validationContext); - results.forEach(result -> Assertions.assertTrue(result.isValid())); + results.forEach(result -> assertTrue(result.isValid())); } } 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 c4b3ef69bc00..8bf499c0dd67 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 @@ -32,7 +32,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.hamcrest.MatcherAssert; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -43,6 +42,11 @@ import java.util.Map; import static org.hamcrest.core.IsInstanceOf.instanceOf; +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 { @@ -91,12 +95,7 @@ public void testAlertNoReportingContext() { final Action action = new Action(); action.setType("ALERT"); action.setAttributes(attributes); - try { - alertHandler.execute(action, metrics); - Assertions.fail(); - } catch (UnsupportedOperationException ex) { - Assertions.assertTrue(true); - } + assertThrows(UnsupportedOperationException.class, () -> alertHandler.execute(action, metrics)); } @Test @@ -125,11 +124,11 @@ public void testAlertWithBulletinLevel() { alertHandler.execute(reportingContext, action, metrics); BulletinRepository bulletinRepository = reportingContext.getBulletinRepository(); List bulletins = bulletinRepository.findBulletinsForController(); - Assertions.assertFalse(bulletins.isEmpty()); + assertFalse(bulletins.isEmpty()); Bulletin bulletin = bulletins.get(0); - Assertions.assertEquals(bulletin.getCategory(), category); - Assertions.assertEquals(bulletin.getMessage(), expectedOutput); - Assertions.assertEquals(bulletin.getLevel(), severity); + assertEquals(bulletin.getCategory(), category); + assertEquals(bulletin.getMessage(), expectedOutput); + assertEquals(bulletin.getLevel(), severity); } @Test @@ -155,11 +154,11 @@ public void testAlertWithDefaultValues() { alertHandler.execute(reportingContext, action, metrics); BulletinRepository bulletinRepository = reportingContext.getBulletinRepository(); List bulletins = bulletinRepository.findBulletinsForController(); - Assertions.assertFalse(bulletins.isEmpty()); + assertFalse(bulletins.isEmpty()); Bulletin bulletin = bulletins.get(0); - Assertions.assertEquals(bulletin.getCategory(), category); - Assertions.assertEquals(bulletin.getMessage(), expectedOutput); - Assertions.assertEquals(bulletin.getLevel(), severity); + assertEquals(bulletin.getCategory(), category); + assertEquals(bulletin.getMessage(), expectedOutput); + assertEquals(bulletin.getLevel(), severity); } @Test @@ -192,8 +191,8 @@ public Map getAllProperties() { }; alertHandler.execute(fakeContext, action, metrics); final String debugMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); - Assertions.assertEquals(debugMessage,"Reporting context was not provided to create bulletins."); + assertTrue(StringUtils.isNotEmpty(debugMessage)); + assertEquals(debugMessage,"Reporting context was not provided to create bulletins."); } @Test @@ -217,8 +216,8 @@ public void testEmptyBulletinRepository(){ Mockito.when(reportingContext.getBulletinRepository()).thenReturn(null); alertHandler.execute(fakeContext, action, metrics); final String warnMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); - Assertions.assertEquals(warnMessage,"Bulletin Repository is not available which is unusual. Cannot send a bulletin."); + assertTrue(StringUtils.isNotEmpty(warnMessage)); + assertEquals(warnMessage,"Bulletin Repository is not available which is unusual. Cannot send a bulletin."); } @Test @@ -243,11 +242,7 @@ public void testInvalidActionTypeException(){ final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext, action, metrics); - Assertions.fail(); - } catch (UnsupportedOperationException ex) { - } + assertThrows(UnsupportedOperationException.class, () -> alertHandler.execute(reportingContext, action, metrics)); } @Test @@ -272,15 +267,12 @@ public void testInvalidActionTypeWarn(){ final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext,action, metrics); - Assertions.assertTrue(true); - } catch (UnsupportedOperationException ex) { - Assertions.fail(); - } + + assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics)); + final String warnMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); - Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); + assertTrue(StringUtils.isNotEmpty(warnMessage)); + assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); } @Test @@ -305,15 +297,11 @@ public void testInvalidActionTypeIgnore(){ final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext,action, metrics); - Assertions.assertTrue(true); - } catch (UnsupportedOperationException ex) { - Assertions.fail(); - } + assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics)); + final String debugMessage = mockComponentLog.getDebugMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); - Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); + assertTrue(StringUtils.isNotEmpty(debugMessage)); + assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); } @Test @@ -336,12 +324,7 @@ public void testValidActionType(){ final Action action = new Action(); action.setType("ALERT"); action.setAttributes(attributes); - try { - alertHandler.execute(reportingContext,action, metrics); - Assertions.assertTrue(true); - } catch (UnsupportedOperationException ex) { - Assertions.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 a27dfe85bd3b..b5505ed8a2e6 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 @@ -23,7 +23,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.hamcrest.MatcherAssert; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -31,6 +30,10 @@ import java.util.Map; import static org.hamcrest.core.IsInstanceOf.instanceOf; +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 { @@ -73,8 +76,8 @@ public void testMvelExpression(){ action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getDebugMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertTrue(logMessage.startsWith(expectedMessage)); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -93,8 +96,8 @@ public void testSpelExpression(){ action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getDebugMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertTrue(logMessage.startsWith(expectedMessage)); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -113,8 +116,8 @@ public void testInvalidType() { action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertTrue(logMessage.startsWith(expectedMessage)); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -131,8 +134,8 @@ public void testNoCommandProvided() { action.setAttributes(attributes); expressionHandler.execute(action, metrics); String logMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertTrue(logMessage.startsWith(expectedMessage)); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertTrue(logMessage.startsWith(expectedMessage)); } @Test @@ -149,12 +152,9 @@ public void testInvalidActionTypeException() { final Action action = new Action(); action.setType("FAKE"); - action.setAttributes(attributes); try { - expressionHandler.execute(action, metrics); - Assertions.fail(); - } catch (UnsupportedOperationException ex) { - Assertions.assertTrue(true); - } + action.setAttributes(attributes); + + assertThrows(UnsupportedOperationException.class, () -> expressionHandler.execute(action, metrics)); } @Test @@ -171,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) { - Assertions.fail(); - } + action.setAttributes(attributes); - final String warnMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); - Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); + 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 @@ -197,15 +194,13 @@ public void testInvalidActionTypeIgnore() { final Action action = new Action(); action.setType("FAKE"); - action.setAttributes(attributes); try { - expressionHandler.execute(action, metrics); - } catch (UnsupportedOperationException ex) { - Assertions.fail(); - } + action.setAttributes(attributes); + + assertDoesNotThrow(() -> expressionHandler.execute(action, metrics)); final String debugMessage = mockComponentLog.getDebugMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); - Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); + assertTrue(StringUtils.isNotEmpty(debugMessage)); + assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); } @Test @@ -222,12 +217,7 @@ public void testValidActionType() { final Action action = new Action(); action.setType("EXPRESSION"); action.setAttributes(attributes); - try { - expressionHandler.execute(action, metrics); - Assertions.assertTrue(true); - } catch (UnsupportedOperationException ex) { - Assertions.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 0e62a58b3c98..77745eef71c5 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 @@ -23,7 +23,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.hamcrest.MatcherAssert; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -31,6 +30,10 @@ import java.util.Map; import static org.hamcrest.core.IsInstanceOf.instanceOf; +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 { @@ -78,8 +81,8 @@ public void testWarningLogged() { action.setAttributes(attributes); logHandler.execute(action, metrics); String logMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertEquals(expectedMessage, logMessage); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertEquals(expectedMessage, logMessage); } @Test @@ -101,8 +104,8 @@ public void testNoLogAttributesProvided() { action.setAttributes(attributes); logHandler.execute(action, metrics); String logMessage = mockComponentLog.getInfoMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertEquals(expectedMessage, logMessage); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertEquals(expectedMessage, logMessage); } @@ -127,8 +130,8 @@ public void testInvalidLogLevelProvided() { action.setAttributes(attributes); logHandler.execute(action, metrics); String logMessage = mockComponentLog.getInfoMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertEquals(expectedMessage, logMessage); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertEquals(expectedMessage, logMessage); } @@ -156,12 +159,7 @@ public void testInvalidActionTypeException() { final Action action = new Action(); action.setType("FAKE"); action.setAttributes(attributes); - try { - logHandler.execute(action, metrics); - Assertions.fail(); - } catch (UnsupportedOperationException ex) { - Assertions.assertTrue(true); - } + assertThrows(UnsupportedOperationException.class, () -> logHandler.execute(action, metrics)); } @Test @@ -188,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) { - Assertions.fail(); - } + assertDoesNotThrow(() -> logHandler.execute(action, metrics)); final String warnMessage = mockComponentLog.getWarnMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(warnMessage)); - Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); + assertTrue(StringUtils.isNotEmpty(warnMessage)); + assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage); } @Test @@ -223,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) { - Assertions.fail(); - } + + assertDoesNotThrow(() -> logHandler.execute(action, metrics)); final String debugMessage = mockComponentLog.getDebugMessage(); - Assertions.assertTrue(StringUtils.isNotEmpty(debugMessage)); - Assertions.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); + assertTrue(StringUtils.isNotEmpty(debugMessage)); + assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage); } @Test @@ -257,12 +248,8 @@ public void testValidActionType() { final Action action = new Action(); action.setType("LOG"); action.setAttributes(attributes); - try { - logHandler.execute(action, metrics); - Assertions.assertTrue(true); - } catch (UnsupportedOperationException ex) { - Assertions.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 30a573af1fee..3c7c2922de79 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 @@ -31,7 +31,6 @@ import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; import org.hamcrest.MatcherAssert; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,6 +43,9 @@ import java.util.Map; import static org.hamcrest.core.IsInstanceOf.instanceOf; +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; @@ -91,13 +93,13 @@ public void testRecordSendViaSink() throws InitializationException, IOException recordSinkHandler.execute(action, metrics); String logMessage = mockComponentLog.getDebugMessage(); List> rows = recordSinkService.getRows(); - Assertions.assertTrue(StringUtils.isNotEmpty(logMessage)); - Assertions.assertTrue(logMessage.startsWith(expectedMessage)); - Assertions.assertFalse(rows.isEmpty()); + assertTrue(StringUtils.isNotEmpty(logMessage)); + assertTrue(logMessage.startsWith(expectedMessage)); + assertFalse(rows.isEmpty()); Map record = rows.get(0); - Assertions.assertEquals("90", (record.get("cpu"))); - Assertions.assertEquals("1000000", (record.get("jvmHeap"))); - Assertions.assertEquals(bigDecimalValue, (record.get("custom"))); + assertEquals("90", (record.get("cpu"))); + assertEquals("1000000", (record.get("jvmHeap"))); + assertEquals(bigDecimalValue, (record.get("custom"))); } private static class MockRecordSinkHandler extends RecordSinkHandler { 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 fc001a263faf..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,17 +18,13 @@ 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.jupiter.api.BeforeAll import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test -import org.junit.jupiter.api.condition.EnabledIfSystemProperty import org.slf4j.Logger import org.slf4j.LoggerFactory -import java.util.concurrent.TimeUnit - import static org.junit.jupiter.api.Assertions.assertNotNull class ExecuteScriptGroovyTest extends BaseScriptTest { @@ -142,59 +138,6 @@ class ExecuteScriptGroovyTest extends BaseScriptTest { } } - @EnabledIfSystemProperty( - named = "nifi.test.unstable", - matches = "true", - disabledReason = "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/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 d5a26f91f5e8..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 @@ -64,7 +64,7 @@ public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptFile() t * * @throws Exception Any error encountered while testing */ - @org.junit.jupiter.api.Test + @Test public void testNoIncomingFlowFile() throws Exception { runner.setValidateExpressionUsage(false); runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Clojure"); 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 b511ccd71eb9..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 @@ -29,7 +29,6 @@ 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.junit.jupiter.api.Assertions.fail; public class TestExecuteGroovy extends BaseScriptTest { @@ -279,13 +278,10 @@ public void testScriptException() { 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/TestInvokeGroovy.java b/nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/processors/script/TestInvokeGroovy.java index ed69e6a1a8ce..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 @@ -53,7 +53,7 @@ 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. * */ - @org.junit.jupiter.api.Test + @Test public void testReadFlowFileContentAndStoreInFlowFileAttribute() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy"); @@ -106,7 +106,7 @@ public void testScriptDefinedAttribute() { * stores the value in an attribute of the outgoing flowfile. * */ - @org.junit.jupiter.api.Test + @Test public void testScriptDefinedRelationship() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); 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 ea2d65e12561..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 @@ -51,7 +51,7 @@ public void setup() throws Exception { * * @Any error encountered while testing */ - @org.junit.jupiter.api.Test + @Test public void testReadFlowFileContentAndStoreInFlowFileAttribute() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js"); @@ -73,7 +73,7 @@ public void testReadFlowFileContentAndStoreInFlowFileAttribute() { * * @Any error encountered while testing */ - @org.junit.jupiter.api.Test + @Test public void testScriptDefinedAttribute() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); @@ -108,7 +108,7 @@ public void testScriptDefinedAttribute() { * * @Any error encountered while testing */ - @org.junit.jupiter.api.Test + @Test public void testScriptDefinedRelationship() { InvokeScriptedProcessor processor = new InvokeScriptedProcessor(); MockProcessContext context = new MockProcessContext(processor); @@ -159,7 +159,7 @@ public void testInvokeScriptCausesException() { * * @Any error encountered while testing */ - @org.junit.jupiter.api.Test + @Test public void testScriptRoutesToFailure() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString( @@ -179,7 +179,7 @@ public void testScriptRoutesToFailure() { * * @Any error encountered while testing */ - @org.junit.jupiter.api.Test + @Test public void testEmptyScript() { runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript"); runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, ""); 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 dc43c059f91b..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 @@ -72,7 +72,7 @@ public void setup() { attrs.put("message", "Time to backpressure < 5 mins"); } - @org.junit.jupiter.api.Test + @Test public void testActions() throws InitializationException { actionHandler = initTask("src/test/resources/groovy/test_action_handler.groovy"); List actions = Arrays.asList(new Action("LOG", attrs), new Action("ALERT", attrs)); @@ -97,7 +97,7 @@ public void testActionHandlerNotPropertyContextActionHandler() throws Initializa assertEquals(42, facts.get("testFact")); } - @org.junit.jupiter.api.Test + @Test public void testPropertyContextActionHandler() throws InitializationException { actionHandler = initTask("src/test/resources/groovy/test_propertycontext_action_handler.groovy"); mockScriptedBulletinRepository = new MockScriptedBulletinRepository(); From 09e502d191ce44f7f9952d8717e3cec4e039f787 Mon Sep 17 00:00:00 2001 From: Mike Thomsen Date: Sat, 4 Sep 2021 08:12:58 -0400 Subject: [PATCH 7/7] Changed MatcherAssert.* to static imports. --- .../java/org/apache/nifi/rules/handlers/TestAlertHandler.java | 4 ++-- .../org/apache/nifi/rules/handlers/TestExpressionHandler.java | 4 ++-- .../java/org/apache/nifi/rules/handlers/TestLogHandler.java | 4 ++-- .../org/apache/nifi/rules/handlers/TestRecordSinkHandler.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) 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 8bf499c0dd67..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,7 +31,6 @@ import org.apache.nifi.util.MockBulletinRepository; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mockito; @@ -41,6 +40,7 @@ import java.util.List; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -78,7 +78,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(alertHandler); - MatcherAssert.assertThat(alertHandler, instanceOf(AlertHandler.class)); + assertThat(alertHandler, instanceOf(AlertHandler.class)); } @Test 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 b5505ed8a2e6..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,13 +22,13 @@ import org.apache.nifi.rules.Action; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -56,7 +56,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(expressionHandler); - MatcherAssert.assertThat(expressionHandler, instanceOf(ExpressionHandler.class)); + assertThat(expressionHandler, instanceOf(ExpressionHandler.class)); } @Test 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 77745eef71c5..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 @@ -22,13 +22,13 @@ import org.apache.nifi.rules.Action; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.util.HashMap; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -57,7 +57,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(logHandler); - MatcherAssert.assertThat(logHandler, instanceOf(LogHandler.class)); + assertThat(logHandler, instanceOf(LogHandler.class)); } @Test 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 3c7c2922de79..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,7 +30,6 @@ import org.apache.nifi.serialization.record.RecordSet; import org.apache.nifi.util.TestRunner; import org.apache.nifi.util.TestRunners; -import org.hamcrest.MatcherAssert; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,6 +41,7 @@ import java.util.List; import java.util.Map; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.core.IsInstanceOf.instanceOf; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; @@ -72,7 +72,7 @@ public void setup() throws InitializationException { @Test public void testValidService() { runner.assertValid(recordSinkHandler); - MatcherAssert.assertThat(recordSinkHandler, instanceOf(RecordSinkHandler.class)); + assertThat(recordSinkHandler, instanceOf(RecordSinkHandler.class)); } @Test