mirror of
https://github.com/apache/nifi.git
synced 2025-02-06 01:58:32 +00:00
NIFI-9148 Refactored nifi-scripting-bundle to use JUnit 5.
NIFI-9147 Refactored nifi-rules-action-handler-bundle to use JUnit 5. NIFI-9146 Refactored nifi-riemann-bundle to use JUnit 5. NIFI-9144 Refactored nifi-registry-bundle to use JUnit 5. This closes #5360 Signed-off-by: David Handermann <exceptionfactory@apache.org>
This commit is contained in:
parent
20804ff2b1
commit
d702506f0d
@ -16,15 +16,6 @@
|
||||
*/
|
||||
package org.apache.nifi.schemaregistry.services;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.nifi.components.PropertyDescriptor;
|
||||
import org.apache.nifi.components.PropertyValue;
|
||||
import org.apache.nifi.components.ValidationContext;
|
||||
@ -33,8 +24,17 @@ import org.apache.nifi.controller.ConfigurationContext;
|
||||
import org.apache.nifi.schema.access.SchemaNotFoundException;
|
||||
import org.apache.nifi.serialization.record.RecordSchema;
|
||||
import org.apache.nifi.serialization.record.SchemaIdentifier;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TestAvroSchemaRegistry {
|
||||
|
||||
@ -63,16 +63,11 @@ public class TestAvroSchemaRegistry {
|
||||
SchemaIdentifier schemaIdentifier = SchemaIdentifier.builder().name(schemaName).build();
|
||||
RecordSchema locatedSchema = delegate.retrieveSchema(schemaIdentifier);
|
||||
assertEquals(fooSchemaText, locatedSchema.getSchemaText().get());
|
||||
try {
|
||||
delegate.retrieveSchema(SchemaIdentifier.builder().name("barSchema").build());
|
||||
Assert.fail("Expected a SchemaNotFoundException to be thrown but it was not");
|
||||
} catch (final SchemaNotFoundException expected) {
|
||||
}
|
||||
|
||||
assertThrows(SchemaNotFoundException.class, () -> delegate.retrieveSchema(SchemaIdentifier.builder().name("barSchema").build()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() throws Exception {
|
||||
public void validateStrictAndNonStrictSchemaRegistrationFromDynamicProperties() {
|
||||
String schemaName = "fooSchema";
|
||||
ConfigurationContext configContext = mock(ConfigurationContext.class);
|
||||
Map<PropertyDescriptor, String> properties = new HashMap<>();
|
||||
|
@ -23,10 +23,8 @@ import org.apache.nifi.processor.exception.ProcessException;
|
||||
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.Map;
|
||||
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.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
public class TestPutRiemann {
|
||||
@Rule
|
||||
public final ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
// Holds incoming events to Riemann
|
||||
private Queue<Proto.Event> eventStream = new LinkedList<Proto.Event>();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void clearEventStream() {
|
||||
eventStream.clear();
|
||||
}
|
||||
@ -174,8 +170,7 @@ public class TestPutRiemann {
|
||||
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 class TestPutRiemann {
|
||||
flowFile.putAttributes(attributes);
|
||||
runner.enqueue(flowFile);
|
||||
try {
|
||||
runner.run();
|
||||
assertThrows(AssertionError.class, () -> runner.run());
|
||||
} catch (ProcessException e) {
|
||||
runner.assertQueueNotEmpty();
|
||||
throw e;
|
||||
|
@ -23,14 +23,15 @@ import org.apache.nifi.reporting.InitializationException;
|
||||
import org.apache.nifi.rules.Action;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.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 class TestActionHandlerLookup {
|
||||
assert logHandler.getExecuteContextCalled();
|
||||
}
|
||||
|
||||
@Test(expected = ProcessException.class)
|
||||
@Test
|
||||
public void testLookupInvalidActionType() {
|
||||
final Map<String, String> attributes = new HashMap<>();
|
||||
final Map<String, Object> metrics = new HashMap<>();
|
||||
@ -103,7 +104,7 @@ public class TestActionHandlerLookup {
|
||||
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 {
|
||||
|
@ -31,8 +31,8 @@ import org.apache.nifi.rules.Action;
|
||||
import org.apache.nifi.util.MockBulletinRepository;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -40,13 +40,13 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
||||
public class TestAlertHandler {
|
||||
@ -57,7 +57,7 @@ public class TestAlertHandler {
|
||||
private AlertHandler alertHandler;
|
||||
private MockAlertBulletinRepository mockAlertBulletinRepository;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws InitializationException {
|
||||
runner = TestRunners.newTestRunner(TestProcessor.class);
|
||||
mockComponentLog = new MockComponentLog();
|
||||
@ -95,12 +95,7 @@ public class TestAlertHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("ALERT");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
alertHandler.execute(action, metrics);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertThrows(UnsupportedOperationException.class, () -> alertHandler.execute(action, metrics));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -247,11 +242,7 @@ public class TestAlertHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
alertHandler.execute(reportingContext, action, metrics);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
}
|
||||
assertThrows(UnsupportedOperationException.class, () -> alertHandler.execute(reportingContext, action, metrics));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -276,12 +267,9 @@ public class TestAlertHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
alertHandler.execute(reportingContext,action, metrics);
|
||||
assertTrue(true);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
|
||||
assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics));
|
||||
|
||||
final String warnMessage = mockComponentLog.getWarnMessage();
|
||||
assertTrue(StringUtils.isNotEmpty(warnMessage));
|
||||
assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage);
|
||||
@ -309,12 +297,8 @@ public class TestAlertHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
alertHandler.execute(reportingContext,action, metrics);
|
||||
assertTrue(true);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics));
|
||||
|
||||
final String debugMessage = mockComponentLog.getDebugMessage();
|
||||
assertTrue(StringUtils.isNotEmpty(debugMessage));
|
||||
assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage);
|
||||
@ -340,12 +324,7 @@ public class TestAlertHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("ALERT");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
alertHandler.execute(reportingContext,action, metrics);
|
||||
assertTrue(true);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
assertDoesNotThrow(() -> alertHandler.execute(reportingContext,action, metrics));
|
||||
}
|
||||
|
||||
private static class MockAlertHandler extends AlertHandler {
|
||||
|
@ -22,17 +22,18 @@ import org.apache.nifi.reporting.InitializationException;
|
||||
import org.apache.nifi.rules.Action;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestExpressionHandler {
|
||||
|
||||
@ -40,7 +41,7 @@ public class TestExpressionHandler {
|
||||
private MockComponentLog mockComponentLog;
|
||||
private ExpressionHandler expressionHandler;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws InitializationException {
|
||||
runner = TestRunners.newTestRunner(TestProcessor.class);
|
||||
mockComponentLog = new MockComponentLog();
|
||||
@ -151,12 +152,9 @@ public class TestExpressionHandler {
|
||||
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes); try {
|
||||
expressionHandler.execute(action, metrics);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
assertTrue(true);
|
||||
}
|
||||
action.setAttributes(attributes);
|
||||
|
||||
assertThrows(UnsupportedOperationException.class, () -> expressionHandler.execute(action, metrics));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -173,16 +171,13 @@ public class TestExpressionHandler {
|
||||
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes); try {
|
||||
expressionHandler.execute(action, metrics);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
action.setAttributes(attributes);
|
||||
|
||||
assertDoesNotThrow(() -> expressionHandler.execute(action, metrics));
|
||||
|
||||
final String warnMessage = mockComponentLog.getWarnMessage();
|
||||
assertTrue(StringUtils.isNotEmpty(warnMessage));
|
||||
assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -199,11 +194,9 @@ public class TestExpressionHandler {
|
||||
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes); try {
|
||||
expressionHandler.execute(action, metrics);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
action.setAttributes(attributes);
|
||||
|
||||
assertDoesNotThrow(() -> expressionHandler.execute(action, metrics));
|
||||
|
||||
final String debugMessage = mockComponentLog.getDebugMessage();
|
||||
assertTrue(StringUtils.isNotEmpty(debugMessage));
|
||||
@ -224,12 +217,7 @@ public class TestExpressionHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("EXPRESSION");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
expressionHandler.execute(action, metrics);
|
||||
assertTrue(true);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
assertDoesNotThrow(() -> expressionHandler.execute(action, metrics));
|
||||
}
|
||||
|
||||
|
||||
|
@ -16,24 +16,24 @@
|
||||
*/
|
||||
package org.apache.nifi.rules.handlers;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.nifi.logging.ComponentLog;
|
||||
import org.apache.nifi.reporting.InitializationException;
|
||||
import org.apache.nifi.rules.Action;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestLogHandler {
|
||||
|
||||
@ -41,7 +41,7 @@ public class TestLogHandler {
|
||||
MockComponentLog mockComponentLog;
|
||||
LogHandler logHandler;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws InitializationException {
|
||||
runner = TestRunners.newTestRunner(TestProcessor.class);
|
||||
mockComponentLog = new MockComponentLog();
|
||||
@ -159,12 +159,7 @@ public class TestLogHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
logHandler.execute(action, metrics);
|
||||
fail();
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
assertTrue(true);
|
||||
}
|
||||
assertThrows(UnsupportedOperationException.class, () -> logHandler.execute(action, metrics));
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -191,15 +186,11 @@ public class TestLogHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
logHandler.execute(action, metrics);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
assertDoesNotThrow(() -> logHandler.execute(action, metrics));
|
||||
|
||||
final String warnMessage = mockComponentLog.getWarnMessage();
|
||||
assertTrue(StringUtils.isNotEmpty(warnMessage));
|
||||
TestCase.assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage);
|
||||
assertEquals("This Action Handler does not support actions with the provided type: FAKE",warnMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -226,15 +217,12 @@ public class TestLogHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("FAKE");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
logHandler.execute(action, metrics);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
|
||||
assertDoesNotThrow(() -> logHandler.execute(action, metrics));
|
||||
|
||||
final String debugMessage = mockComponentLog.getDebugMessage();
|
||||
assertTrue(StringUtils.isNotEmpty(debugMessage));
|
||||
TestCase.assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage);
|
||||
assertEquals("This Action Handler does not support actions with the provided type: FAKE",debugMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -260,12 +248,8 @@ public class TestLogHandler {
|
||||
final Action action = new Action();
|
||||
action.setType("LOG");
|
||||
action.setAttributes(attributes);
|
||||
try {
|
||||
logHandler.execute(action, metrics);
|
||||
assertTrue(true);
|
||||
} catch (UnsupportedOperationException ex) {
|
||||
fail();
|
||||
}
|
||||
|
||||
assertDoesNotThrow(() -> logHandler.execute(action, metrics));
|
||||
}
|
||||
|
||||
private static class MockLogHandler extends LogHandler {
|
||||
|
@ -30,8 +30,8 @@ import org.apache.nifi.serialization.record.RecordSchema;
|
||||
import org.apache.nifi.serialization.record.RecordSet;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
@ -41,11 +41,11 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static junit.framework.TestCase.assertTrue;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.core.IsInstanceOf.instanceOf;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestRecordSinkHandler {
|
||||
private TestRunner runner;
|
||||
@ -53,7 +53,7 @@ public class TestRecordSinkHandler {
|
||||
private RecordSinkHandler recordSinkHandler;
|
||||
private MockRecordSinkService recordSinkService;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws InitializationException {
|
||||
runner = TestRunners.newTestRunner(TestProcessor.class);
|
||||
mockComponentLog = new MockComponentLog();
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -18,34 +18,26 @@ package org.apache.nifi.processors.script
|
||||
|
||||
import org.apache.nifi.script.ScriptingComponentUtils
|
||||
import org.apache.nifi.util.MockFlowFile
|
||||
import org.apache.nifi.util.StopWatch
|
||||
import org.apache.nifi.util.TestRunners
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.junit.runners.JUnit4
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.slf4j.Logger
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import java.util.concurrent.TimeUnit
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull
|
||||
|
||||
import static org.junit.Assert.assertNotNull
|
||||
|
||||
@RunWith(JUnit4.class)
|
||||
class ExecuteScriptGroovyTest extends BaseScriptTest {
|
||||
private static final Logger logger = LoggerFactory.getLogger(ExecuteScriptGroovyTest.class)
|
||||
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
static void setUpOnce() throws Exception {
|
||||
logger.metaClass.methodMissing = { String name, args ->
|
||||
logger.info("[${name?.toUpperCase()}] ${(args as List).join(" ")}")
|
||||
}
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
void setUp() throws Exception {
|
||||
super.setupExecuteScript()
|
||||
|
||||
@ -55,10 +47,6 @@ class ExecuteScriptGroovyTest extends BaseScriptTest {
|
||||
runner.setProperty(ScriptingComponentUtils.MODULES, TEST_RESOURCE_LOCATION + "groovy")
|
||||
}
|
||||
|
||||
@After
|
||||
void tearDown() throws Exception {
|
||||
}
|
||||
|
||||
private void setupPooledExecuteScript(int poolSize = 2) {
|
||||
final ExecuteScript executeScript = new ExecuteScript()
|
||||
// Need to do something to initialize the properties, like retrieve the list of properties
|
||||
@ -150,56 +138,6 @@ class ExecuteScriptGroovyTest extends BaseScriptTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("This test fails intermittently when the serial execution happens faster than pooled")
|
||||
@Test
|
||||
void testPooledExecutionShouldBeFaster() throws Exception {
|
||||
// Arrange
|
||||
final int ITERATIONS = 1000
|
||||
final int POOL_SIZE = 4
|
||||
|
||||
// Act
|
||||
// Run serially and capture the timing
|
||||
final StopWatch stopWatch = new StopWatch(true)
|
||||
runner.run(ITERATIONS)
|
||||
stopWatch.stop()
|
||||
final long serialExecutionTime = stopWatch.getDuration(TimeUnit.MILLISECONDS)
|
||||
logger.info("Serial execution time for ${ITERATIONS} executions: ${serialExecutionTime} ms")
|
||||
|
||||
// Assert (1)
|
||||
runner.assertAllFlowFilesTransferred(ExecuteScript.REL_SUCCESS, ITERATIONS)
|
||||
final List<MockFlowFile> 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<MockFlowFile> 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 {
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -20,14 +20,14 @@ import org.apache.commons.io.FileUtils;
|
||||
import org.apache.nifi.script.ScriptingComponentHelper;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
|
||||
/**
|
||||
* An abstract class with common methods, variables, etc. used by scripting processor unit tests
|
||||
@ -44,7 +44,7 @@ public abstract class BaseScriptTest {
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@BeforeClass
|
||||
@BeforeAll
|
||||
public static void setupBeforeClass() throws Exception {
|
||||
FileUtils.copyDirectory(new File("src/test/resources"), new File("target/test/resources"));
|
||||
}
|
||||
|
@ -18,15 +18,14 @@ package org.apache.nifi.processors.script;
|
||||
|
||||
import org.apache.nifi.script.ScriptingComponentUtils;
|
||||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
public class TestExecuteClojure extends BaseScriptTest {
|
||||
|
||||
@ -34,7 +33,7 @@ public class TestExecuteClojure extends BaseScriptTest {
|
||||
+ "female,miss,marlene,shaw\n"
|
||||
+ "male,mr,todd,graham";
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupExecuteScript();
|
||||
}
|
||||
|
@ -19,17 +19,16 @@ package org.apache.nifi.processors.script;
|
||||
import org.apache.nifi.script.ScriptingComponentUtils;
|
||||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.MockProcessContext;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestExecuteGroovy extends BaseScriptTest {
|
||||
|
||||
@ -37,7 +36,7 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
+ "female,miss,marlene,shaw\n"
|
||||
+ "male,mr,todd,graham";
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupExecuteScript();
|
||||
}
|
||||
@ -85,10 +84,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script file that creates and transfers a new flow file.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testInvalidConfiguration() throws Exception {
|
||||
public void testInvalidConfiguration() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION);
|
||||
@ -100,10 +98,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script file that creates and transfers a new flow file.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testCreateNewFlowFileWithScriptFile() throws Exception {
|
||||
public void testCreateNewFlowFileWithScriptFile() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "groovy/test_onTrigger_newFlowFile.groovy");
|
||||
@ -123,10 +120,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script file that creates and transfers a new flow file.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testCreateNewFlowFileWithNoInputFile() throws Exception {
|
||||
public void testCreateNewFlowFileWithNoInputFile() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY,
|
||||
@ -144,10 +140,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script file that creates and transfers a new flow file.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testDynamicProperties() throws Exception {
|
||||
public void testDynamicProperties() {
|
||||
runner.setValidateExpressionUsage(true);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION + "groovy/test_dynamicProperties.groovy");
|
||||
@ -168,10 +163,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script file that changes the content of the incoming flowfile.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testChangeFlowFileWithScriptFile() throws Exception {
|
||||
public void testChangeFlowFileWithScriptFile() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_onTrigger_changeContent.groovy");
|
||||
@ -192,10 +186,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script that has provides the body of an onTrigger() function.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBody() throws Exception {
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBody() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
@ -216,10 +209,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
* Tests a script that has provides the body of an onTrigger() function, where the ExecuteScript processor does
|
||||
* not specify a modules path
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBodyNoModules() throws Exception {
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttributeWithScriptBodyNoModules() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
@ -237,10 +229,9 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script that does not transfer or remove the original flow file, thereby causing an error during commit.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing. Expecting
|
||||
*/
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testScriptNoTransfer() throws Exception {
|
||||
@Test
|
||||
public void testScriptNoTransfer() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
@ -249,17 +240,15 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
|
||||
runner.assertValid();
|
||||
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
|
||||
runner.run();
|
||||
|
||||
assertThrows(AssertionError.class, () -> runner.run());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a script that uses a dynamic property to set a FlowFile attribute.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testReadFlowFileContentAndStoreInFlowFileCustomAttribute() throws Exception {
|
||||
public void testReadFlowFileContentAndStoreInFlowFileCustomAttribute() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
@ -280,23 +269,19 @@ public class TestExecuteGroovy extends BaseScriptTest {
|
||||
* Tests a script that throws an Exception within. The expected result is that the flow file is rolled back
|
||||
* and penalized. Besides we check that we yielded the processor.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testScriptException() throws Exception {
|
||||
public void testScriptException() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(TEST_RESOURCE_LOCATION + "groovy/testScriptException.groovy"));
|
||||
|
||||
runner.assertValid();
|
||||
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
|
||||
try {
|
||||
runner.run();
|
||||
fail();
|
||||
} catch (AssertionError e) {
|
||||
runner.assertPenalizeCount(1); // penalized
|
||||
runner.assertQueueNotEmpty(); // flow file back in the input queue
|
||||
assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled()); // processor yielded
|
||||
}
|
||||
|
||||
assertThrows(AssertionError.class, () -> runner.run());
|
||||
runner.assertPenalizeCount(1); // penalized
|
||||
runner.assertQueueNotEmpty(); // flow file back in the input queue
|
||||
assertTrue(((MockProcessContext) runner.getProcessContext()).isYieldCalled());
|
||||
}
|
||||
}
|
||||
|
@ -20,28 +20,24 @@ 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.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class TestExecuteJRuby extends BaseScriptTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupExecuteScript();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests a script that has provides the body of an onTrigger() function.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception {
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ruby");
|
||||
|
@ -20,16 +20,15 @@ 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.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class TestExecuteJavascript extends BaseScriptTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupExecuteScript();
|
||||
}
|
||||
@ -37,10 +36,9 @@ public class TestExecuteJavascript extends BaseScriptTest {
|
||||
/**
|
||||
* 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");
|
||||
|
@ -18,19 +18,21 @@ package org.apache.nifi.processors.script;
|
||||
|
||||
import org.apache.nifi.script.ScriptingComponentUtils;
|
||||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.condition.EnabledIfSystemProperty;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
/**
|
||||
* Unit tests for ExecuteScript with Jython.
|
||||
*/
|
||||
public class TestExecuteJython extends BaseScriptTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupExecuteScript();
|
||||
}
|
||||
@ -62,10 +64,9 @@ public class TestExecuteJython extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script that does not transfer or remove the original flow file, thereby causing an error during commit.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing. Expecting
|
||||
*/
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testScriptNoTransfer() throws Exception {
|
||||
@Test
|
||||
public void testScriptNoTransfer() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY,
|
||||
@ -73,12 +74,12 @@ public class TestExecuteJython extends BaseScriptTest {
|
||||
|
||||
runner.assertValid();
|
||||
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
|
||||
runner.run();
|
||||
assertThrows(AssertionError.class, () -> runner.run());
|
||||
}
|
||||
|
||||
@Ignore("This is more of an integration test, can be run before and after changes to ExecuteScript to measure performance improvements")
|
||||
@EnabledIfSystemProperty(named = "nifi.test.performance", matches = "true")
|
||||
@Test
|
||||
public void testPerformance() throws Exception {
|
||||
public void testPerformance() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY,
|
||||
|
@ -20,28 +20,25 @@ 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.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class TestExecuteLua extends BaseScriptTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupExecuteScript();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests a script that has provides the body of an onTrigger() function.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception {
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new ExecuteScript());
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "lua");
|
||||
@ -56,5 +53,4 @@ public class TestExecuteLua extends BaseScriptTest {
|
||||
final List<MockFlowFile> result = runner.getFlowFilesForRelationship(ExecuteScript.REL_SUCCESS);
|
||||
result.get(0).assertAttributeEquals("from-content", "test content");
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -30,22 +30,21 @@ import org.apache.nifi.util.MockValidationContext;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.apache.nifi.util.security.MessageDigestUtils;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestInvokeGroovy extends BaseScriptTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupInvokeScriptProcessor();
|
||||
}
|
||||
@ -53,10 +52,9 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script that has a Groovy Processor that that reads the first line of text from the flowfiles content and stores the value in an attribute of the outgoing flowfile.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception {
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() {
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy");
|
||||
@ -74,10 +72,9 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||
* Tests a script that has a Groovy Processor that that reads the first line of text from the flowfiles content and
|
||||
* stores the value in an attribute of the outgoing flowfile.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testScriptDefinedAttribute() throws Exception {
|
||||
public void testScriptDefinedAttribute() {
|
||||
InvokeScriptedProcessor processor = new InvokeScriptedProcessor();
|
||||
MockProcessContext context = new MockProcessContext(processor);
|
||||
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
|
||||
@ -108,10 +105,9 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||
* Tests a script that has a Groovy Processor that that reads the first line of text from the flowfiles content and
|
||||
* stores the value in an attribute of the outgoing flowfile.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testScriptDefinedRelationship() throws Exception {
|
||||
public void testScriptDefinedRelationship() {
|
||||
InvokeScriptedProcessor processor = new InvokeScriptedProcessor();
|
||||
MockProcessContext context = new MockProcessContext(processor);
|
||||
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
|
||||
@ -141,10 +137,9 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||
* Tests a script that throws a ProcessException within. The expected result is that the exception will be
|
||||
* propagated
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testInvokeScriptCausesException() throws Exception {
|
||||
@Test
|
||||
public void testInvokeScriptCausesException() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
@ -152,17 +147,15 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||
);
|
||||
runner.assertValid();
|
||||
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
|
||||
runner.run();
|
||||
|
||||
assertThrows(AssertionError.class, () -> runner.run());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a script that routes the FlowFile to failure.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testScriptRoutesToFailure() throws Exception {
|
||||
public void testScriptRoutesToFailure() {
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
TEST_RESOURCE_LOCATION + "groovy/testScriptRoutesToFailure.groovy")
|
||||
@ -177,7 +170,7 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidationResultsReset() throws Exception {
|
||||
public void testValidationResultsReset() {
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "Groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/groovy/test_reader.groovy");
|
||||
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/groovy");
|
||||
@ -190,10 +183,9 @@ public class TestInvokeGroovy extends BaseScriptTest {
|
||||
/**
|
||||
* 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"));
|
||||
|
@ -25,20 +25,21 @@ import org.apache.nifi.util.MockProcessorInitializationContext;
|
||||
import org.apache.nifi.util.MockValidationContext;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
public class TestInvokeJavascript extends BaseScriptTest {
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupInvokeScriptProcessor();
|
||||
}
|
||||
@ -48,10 +49,10 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||
* and stores the value in an attribute of the outgoing flowfile.
|
||||
* Confirms that the scripted processor transfers the incoming flowfile with an attribute added.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
* @Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() throws Exception {
|
||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() {
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js");
|
||||
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/javascript");
|
||||
@ -70,10 +71,10 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||
* stores the value in an attribute of the outgoing flowfile.
|
||||
* Confirms that the scripted processor can return property descriptors defined in it.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
* @Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testScriptDefinedAttribute() throws Exception {
|
||||
public void testScriptDefinedAttribute() {
|
||||
InvokeScriptedProcessor processor = new InvokeScriptedProcessor();
|
||||
MockProcessContext context = new MockProcessContext(processor);
|
||||
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
|
||||
@ -105,10 +106,10 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||
* stores the value in an attribute of the outgoing flowfile.
|
||||
* Confirms that the scripted processor can return relationships defined in it.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
* @Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testScriptDefinedRelationship() throws Exception {
|
||||
public void testScriptDefinedRelationship() {
|
||||
InvokeScriptedProcessor processor = new InvokeScriptedProcessor();
|
||||
MockProcessContext context = new MockProcessContext(processor);
|
||||
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
|
||||
@ -140,10 +141,9 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||
* Tests a script that throws a ProcessException within.
|
||||
* The expected result is that the exception will be propagated.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test(expected = AssertionError.class)
|
||||
public void testInvokeScriptCausesException() throws Exception {
|
||||
@Test
|
||||
public void testInvokeScriptCausesException() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
@ -151,17 +151,16 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||
);
|
||||
runner.assertValid();
|
||||
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
|
||||
runner.run();
|
||||
|
||||
assertThrows(AssertionError.class, () -> runner.run());
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests a script that routes the FlowFile to failure.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
* @Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testScriptRoutesToFailure() throws Exception {
|
||||
public void testScriptRoutesToFailure() {
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, getFileContentsAsString(
|
||||
TEST_RESOURCE_LOCATION + "javascript/testScriptRoutesToFailure.js")
|
||||
@ -178,10 +177,10 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||
/**
|
||||
* Tests an empty script with Nashorn (which throws an NPE if it is loaded), this test verifies an empty script is not attempted to be loaded.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
* @Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testEmptyScript() throws Exception {
|
||||
public void testEmptyScript() {
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, "");
|
||||
runner.assertNotValid();
|
||||
|
@ -23,8 +23,8 @@ import org.apache.nifi.util.MockProcessContext;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Collection;
|
||||
@ -39,7 +39,7 @@ public class TestInvokeJython extends BaseScriptTest {
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() throws Exception {
|
||||
super.setupInvokeScriptProcessor();
|
||||
}
|
||||
@ -47,10 +47,9 @@ public class TestInvokeJython extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script that has a Jython processor that is always invalid.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testAlwaysInvalid() throws Exception {
|
||||
public void testAlwaysInvalid() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
|
||||
@ -64,10 +63,9 @@ public class TestInvokeJython extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script that has a Jython processor that begins invalid then is fixed.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testInvalidThenFixed() throws Exception {
|
||||
public void testInvalidThenFixed() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
|
||||
@ -94,10 +92,9 @@ public class TestInvokeJython extends BaseScriptTest {
|
||||
* This may seem contrived but it verifies that the Jython processors properties are being considered and are able to be set and validated. It verifies the processor is able to access the property
|
||||
* values and flowfile attribute values during onTrigger. Lastly, it verifies the processor is able to route the flowfile to a relationship it specified.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testUpdateAttributeFromProcessorPropertyAndFlowFileAttribute() throws Exception {
|
||||
public void testUpdateAttributeFromProcessorPropertyAndFlowFileAttribute() {
|
||||
final TestRunner runner = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
|
||||
@ -124,10 +121,9 @@ public class TestInvokeJython extends BaseScriptTest {
|
||||
/**
|
||||
* 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 class TestInvokeJython extends BaseScriptTest {
|
||||
/**
|
||||
* Tests compression and decompression using two different InvokeScriptedProcessor processor instances. A string is compressed and decompressed and compared.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testCompressor() throws Exception {
|
||||
public void testCompressor() {
|
||||
final TestRunner one = TestRunners.newTestRunner(new InvokeScriptedProcessor());
|
||||
one.setValidateExpressionUsage(false);
|
||||
one.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
|
||||
@ -185,10 +180,9 @@ public class TestInvokeJython extends BaseScriptTest {
|
||||
/**
|
||||
* Tests a script file that creates and transfers a new flow file.
|
||||
*
|
||||
* @throws Exception Any error encountered while testing
|
||||
*/
|
||||
@Test
|
||||
public void testInvalidConfiguration() throws Exception {
|
||||
public void testInvalidConfiguration() {
|
||||
runner.setValidateExpressionUsage(false);
|
||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "python");
|
||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, TEST_RESOURCE_LOCATION);
|
||||
|
@ -30,7 +30,7 @@ import org.apache.nifi.serialization.record.RecordSchema;
|
||||
import org.apache.nifi.util.MockFlowFile;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
@ -39,10 +39,10 @@ import java.util.List;
|
||||
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 {
|
||||
|
||||
|
@ -36,7 +36,7 @@ import org.apache.nifi.serialization.record.RecordSchema;
|
||||
import org.apache.nifi.serialization.record.RecordSet;
|
||||
import org.apache.nifi.util.TestRunner;
|
||||
import org.apache.nifi.util.TestRunners;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
@ -44,8 +44,7 @@ import java.util.HashMap;
|
||||
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 class ScriptedRecordSinkTest {
|
||||
}
|
||||
|
||||
public static class MockScriptedRecordSink extends ScriptedRecordSink implements AccessibleScriptingComponentHelper {
|
||||
|
||||
@Override
|
||||
public ScriptingComponentHelper getScriptingComponentHelper() {
|
||||
return this.scriptingComponentHelper;
|
||||
|
@ -28,8 +28,8 @@ import org.apache.nifi.script.ScriptingComponentUtils;
|
||||
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<String, Object> facts = new HashMap<>();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
facts.put("predictedQueuedCount", 60);
|
||||
facts.put("predictedTimeToBytesBackpressureMillis", 299999);
|
||||
|
@ -34,8 +34,8 @@ import org.apache.nifi.serialization.record.MockRecordWriter;
|
||||
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<String, Object> facts = new HashMap<>();
|
||||
private Map<String, String> attrs = new HashMap<>();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
facts.put("predictedQueuedCount", 60);
|
||||
facts.put("predictedTimeToBytesBackpressureMillis", 299999);
|
||||
|
Loading…
x
Reference in New Issue
Block a user