mirror of https://github.com/apache/nifi.git
NIFI-9944 Configured maven-dependency-plugin for JavaScript test JAR
Signed-off-by: Matthew Burgess <mattyb149@apache.org> This closes #5997
This commit is contained in:
parent
4b66299cf6
commit
8b08795e18
|
@ -163,6 +163,32 @@
|
||||||
</excludes>
|
</excludes>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-dependency-plugin</artifactId>
|
||||||
|
<version>3.3.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy</id>
|
||||||
|
<phase>process-test-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<artifactItems>
|
||||||
|
<artifactItem>
|
||||||
|
<groupId>org.apache.commons</groupId>
|
||||||
|
<artifactId>commons-math3</artifactId>
|
||||||
|
<version>3.6.1</version>
|
||||||
|
<type>jar</type>
|
||||||
|
<overWrite>true</overWrite>
|
||||||
|
<outputDirectory>${project.build.testOutputDirectory}/jar</outputDirectory>
|
||||||
|
</artifactItem>
|
||||||
|
</artifactItems>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
||||||
|
|
|
@ -20,9 +20,6 @@ import org.apache.nifi.components.PropertyDescriptor;
|
||||||
import org.apache.nifi.processor.Relationship;
|
import org.apache.nifi.processor.Relationship;
|
||||||
import org.apache.nifi.script.ScriptingComponentUtils;
|
import org.apache.nifi.script.ScriptingComponentUtils;
|
||||||
import org.apache.nifi.util.MockFlowFile;
|
import org.apache.nifi.util.MockFlowFile;
|
||||||
import org.apache.nifi.util.MockProcessContext;
|
|
||||||
import org.apache.nifi.util.MockProcessorInitializationContext;
|
|
||||||
import org.apache.nifi.util.MockValidationContext;
|
|
||||||
import org.apache.nifi.util.TestRunner;
|
import org.apache.nifi.util.TestRunner;
|
||||||
import org.apache.nifi.util.TestRunners;
|
import org.apache.nifi.util.TestRunners;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
@ -30,8 +27,13 @@ import org.junit.jupiter.api.Test;
|
||||||
import org.junit.jupiter.api.condition.DisabledForJreRange;
|
import org.junit.jupiter.api.condition.DisabledForJreRange;
|
||||||
import org.junit.jupiter.api.condition.JRE;
|
import org.junit.jupiter.api.condition.JRE;
|
||||||
|
|
||||||
|
import java.net.URI;
|
||||||
|
import java.net.URISyntaxException;
|
||||||
|
import java.net.URL;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||||
|
@ -56,9 +58,7 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testReadFlowFileContentAndStoreInFlowFileAttribute() {
|
public void testReadFlowFileContentAndStoreInFlowFileAttribute() {
|
||||||
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
setScriptProperties();
|
||||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js");
|
|
||||||
runner.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jar");
|
|
||||||
|
|
||||||
runner.assertValid();
|
runner.assertValid();
|
||||||
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
|
runner.enqueue("test content".getBytes(StandardCharsets.UTF_8));
|
||||||
|
@ -78,20 +78,10 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testScriptDefinedAttribute() {
|
public void testScriptDefinedAttribute() {
|
||||||
InvokeScriptedProcessor processor = new InvokeScriptedProcessor();
|
setScriptProperties();
|
||||||
MockProcessContext context = new MockProcessContext(processor);
|
runner.assertValid();
|
||||||
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
|
|
||||||
|
|
||||||
processor.initialize(initContext);
|
List<PropertyDescriptor> descriptors = runner.getProcessor().getPropertyDescriptors();
|
||||||
|
|
||||||
context.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
|
||||||
context.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js");
|
|
||||||
context.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jar");
|
|
||||||
// State Manger is unused, and a null reference is specified
|
|
||||||
processor.customValidate(new MockValidationContext(context));
|
|
||||||
processor.setup(context);
|
|
||||||
|
|
||||||
List<PropertyDescriptor> descriptors = processor.getSupportedPropertyDescriptors();
|
|
||||||
assertNotNull(descriptors);
|
assertNotNull(descriptors);
|
||||||
assertTrue(descriptors.size() > 0);
|
assertTrue(descriptors.size() > 0);
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
@ -113,21 +103,10 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testScriptDefinedRelationshipWithExternalJar() {
|
public void testScriptDefinedRelationshipWithExternalJar() {
|
||||||
InvokeScriptedProcessor processor = new InvokeScriptedProcessor();
|
setScriptProperties();
|
||||||
MockProcessContext context = new MockProcessContext(processor);
|
runner.assertValid();
|
||||||
MockProcessorInitializationContext initContext = new MockProcessorInitializationContext(processor, context);
|
|
||||||
|
|
||||||
processor.initialize(initContext);
|
Set<Relationship> relationships = runner.getProcessor().getRelationships();
|
||||||
|
|
||||||
context.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
|
||||||
context.setProperty(ScriptingComponentUtils.SCRIPT_FILE, "target/test/resources/javascript/test_reader.js");
|
|
||||||
context.setProperty(ScriptingComponentUtils.MODULES, "target/test/resources/jar");
|
|
||||||
|
|
||||||
// State Manger is unused, and a null reference is specified
|
|
||||||
processor.customValidate(new MockValidationContext(context));
|
|
||||||
processor.setup(context);
|
|
||||||
|
|
||||||
Set<Relationship> relationships = processor.getRelationships();
|
|
||||||
assertNotNull(relationships);
|
assertNotNull(relationships);
|
||||||
assertTrue(relationships.size() > 0);
|
assertTrue(relationships.size() > 0);
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
|
@ -188,4 +167,21 @@ public class TestInvokeJavascript extends BaseScriptTest {
|
||||||
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, "");
|
runner.setProperty(ScriptingComponentUtils.SCRIPT_BODY, "");
|
||||||
runner.assertNotValid();
|
runner.assertNotValid();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setScriptProperties() {
|
||||||
|
runner.setProperty(scriptingComponent.getScriptingComponentHelper().SCRIPT_ENGINE, "ECMAScript");
|
||||||
|
runner.setProperty(ScriptingComponentUtils.SCRIPT_FILE, getResource("/javascript/test_reader.js"));
|
||||||
|
runner.setProperty(ScriptingComponentUtils.MODULES, getResource("/jar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getResource(final String resourcePath) {
|
||||||
|
final URL resourceUrl = Objects.requireNonNull(TestInvokeJavascript.class.getResource(resourcePath), resourcePath);
|
||||||
|
final URI resourceUri;
|
||||||
|
try {
|
||||||
|
resourceUri = resourceUrl.toURI();
|
||||||
|
} catch (final URISyntaxException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
return Paths.get(resourceUri).toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue