Java tutorial
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.sysunite.weaver.nifi; import com.weaverplatform.sdk.Entity; import com.weaverplatform.sdk.Weaver; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; 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 javax.validation.constraints.Null; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.util.List; import static org.junit.Assert.*; public class CreateValuePropertyTest { private TestRunner testRunner; public Weaver weaver; @Before public void init() { testRunner = TestRunners.newTestRunner(CreateValueProperty.class); weaver = new Weaver(); weaver.connect("http://localhost:9487"); } @Test public void testProcessor() { } @Test public void testOnTrigger() { /********* TEST OUTPUTS ********/ /******* * * * /Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/bin/java -ea -Xmx1G -Djava.net.preferIPv4Stack=true -Didea.launcher.port=7535 "-Didea.launcher.bin.path=/Applications/IntelliJ IDEA 14.app/Contents/bin" -Dfile.encoding=UTF-8 -classpath "/Applications/IntelliJ IDEA 14.app/Contents/lib/idea_rt.jar:/Applications/IntelliJ IDEA 14.app/Contents/plugins/junit/lib/junit-rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/ant-javafx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/dt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/javafx-mx.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/jconsole.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/packager.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/sa-jdi.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/lib/tools.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/charsets.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/deploy.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/javaws.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jce.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jfr.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jfxswt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/jsse.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/management-agent.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/plugin.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/resources.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/rt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/cldrdata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/dnsns.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/jaccess.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/jfxrt.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/localedata.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/nashorn.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/sunec.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/sunjce_provider.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/sunpkcs11.jar:/Library/Java/JavaVirtualMachines/jdk1.8.0_60.jdk/Contents/Home/jre/lib/ext/zipfs.jar:/Users/jonathansmit/Documents/nifiproj/weaver-createvalueproperty/nifi-weaver-createvalueproperty-processors/target/test-classes:/Users/jonathansmit/Documents/nifiproj/weaver-createvalueproperty/nifi-weaver-createvalueproperty-processors/target/classes:/Users/jonathansmit/.m2/repository/org/apache/nifi/nifi-api/0.6.0/nifi-api-0.6.0.jar:/Users/jonathansmit/.m2/repository/org/apache/nifi/nifi-processor-utils/0.6.0/nifi-processor-utils-0.6.0.jar:/Users/jonathansmit/.m2/repository/org/apache/nifi/nifi-utils/0.6.0/nifi-utils-0.6.0.jar:/Users/jonathansmit/.m2/repository/org/apache/nifi/nifi-security-utils/0.6.0/nifi-security-utils-0.6.0.jar:/Users/jonathansmit/.m2/repository/org/apache/commons/commons-lang3/3.4/commons-lang3-3.4.jar:/Users/jonathansmit/.m2/repository/commons-io/commons-io/2.4/commons-io-2.4.jar:/Users/jonathansmit/.m2/repository/org/apache/nifi/nifi-mock/0.6.0/nifi-mock-0.6.0.jar:/Users/jonathansmit/.m2/repository/org/apache/nifi/nifi-expression-language/0.6.0/nifi-expression-language-0.6.0.jar:/Users/jonathansmit/.m2/repository/org/antlr/antlr-runtime/3.5.2/antlr-runtime-3.5.2.jar:/Users/jonathansmit/.m2/repository/org/apache/nifi/nifi-data-provenance-utils/0.6.0/nifi-data-provenance-utils-0.6.0.jar:/Users/jonathansmit/.m2/repository/org/slf4j/slf4j-simple/1.7.12/slf4j-simple-1.7.12.jar:/Users/jonathansmit/.m2/repository/org/slf4j/slf4j-api/1.7.12/slf4j-api-1.7.12.jar:/Users/jonathansmit/.m2/repository/junit/junit/4.11/junit-4.11.jar:/Users/jonathansmit/.m2/repository/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar:/Users/jonathansmit/.m2/repository/com/jcabi/jcabi-xml/0.17.2/jcabi-xml-0.17.2.jar:/Users/jonathansmit/.m2/repository/com/jcabi/jcabi-log/0.17/jcabi-log-0.17.jar:/Users/jonathansmit/.m2/repository/com/jcabi/jcabi-aspects/0.22/jcabi-aspects-0.22.jar:/Users/jonathansmit/.m2/repository/org/aspectj/aspectjrt/1.8.4/aspectjrt-1.8.4.jar:/Users/jonathansmit/.m2/repository/javax/validation/validation-api/1.1.0.Final/validation-api-1.1.0.Final.jar:/Users/jonathansmit/.m2/repository/com/jcabi/jcabi-immutable/1.4/jcabi-immutable-1.4.jar:/Users/jonathansmit/.m2/repository/com/weaverplatform/sdk-java/1.0/sdk-java-1.0.jar:/Users/jonathansmit/.m2/repository/org/apache/httpcomponents/httpclient/4.4.1/httpclient-4.4.1.jar:/Users/jonathansmit/.m2/repository/org/apache/httpcomponents/httpcore/4.4.1/httpcore-4.4.1.jar:/Users/jonathansmit/.m2/repository/commons-logging/commons-logging/1.2/commons-logging-1.2.jar:/Users/jonathansmit/.m2/repository/commons-codec/commons-codec/1.10/commons-codec-1.10.jar:/Users/jonathansmit/.m2/repository/com/google/code/gson/gson/2.6.2/gson-2.6.2.jar:/Users/jonathansmit/.m2/repository/org/mockito/mockito-core/1.10.19/mockito-core-1.10.19.jar:/Users/jonathansmit/.m2/repository/org/objenesis/objenesis/2.1/objenesis-2.1.jar:/Users/jonathansmit/.m2/repository/org/codehaus/groovy/groovy-all/2.4.5/groovy-all-2.4.5.jar" com.intellij.rt.execution.application.AppMain com.intellij.rt.execution.junit.JUnitStarter -ideVersion5 com.sysunite.weaver.nifi.CreateValuePropertyTest,testOnTrigger contact! RootNode: FunctionalPhysicalObject RootNode (xpath): /FunctionalPhysicalObject RootNode-Attribute: id RootNode-Attribute (xpath): /FunctionalPhysicalObject/@id RootNode-Attribute (value): 816ee370-4274-e211-a3a8-b8ac6f902f00 ChildNode: BeginOfLife ChildNode (xpath): /FunctionalPhysicalObject/BeginOfLife ChildNode-Attribute: value Child-Attribute (xpath): /FunctionalPhysicalObject/BeginOfLife/@value Child-Attribute (value): 2013-12-21 Error, bad response ..linkEntity (local): done! ..linkEntity (remote): done! Error, bad response ..linkEntity (local): done! Error, bad response ..linkEntity (remote): done! aantal gevonden: 1 * * Aan de kant van weaver worden speciale acties niet uitgevoerd voor * EntityType.VALUE_PROPERTY, OBJECT_PROPERTY, COLLECTION, OBJECT; * * * * */ try { String file = "slagboom.xml"; byte[] contents = FileUtils .readFileToByteArray(new File(getClass().getClassLoader().getResource(file).getFile())); InputStream in = new ByteArrayInputStream(contents); InputStream cont = new ByteArrayInputStream(IOUtils.toByteArray(in)); // Generate a test runner to mock a processor in a flow TestRunner runner = TestRunners.newTestRunner(new CreateValueProperty()); // Add properites runner.setProperty(CreateValueProperty.PROP_NODE, "FunctionalPhysicalObject"); runner.setProperty(CreateValueProperty.PROP_NODE_ATTRIBUTE, "id"); runner.setProperty(CreateValueProperty.PROP_CHILDNODE, "BeginOfLife"); runner.setProperty(CreateValueProperty.PROP_CHILDNODE_ATTRIBUTE, "value"); // Add the content to the runner runner.enqueue(cont); // Run the enqueued content, it also takes an int = number of contents queued runner.run(); // All results were processed with out failure //runner.assertQueueEmpty(); // If you need to read or do aditional tests on results you can access the content List<MockFlowFile> results = runner.getFlowFilesForRelationship(CreateValueProperty.MY_RELATIONSHIP); //assertTrue("1 match", results.size() == 1); System.out.println("aantal gevonden: " + results.size()); MockFlowFile result = results.get(0); String resultValue = new String(runner.getContentAsByteArray(result)); //check weaver String checkValue = weaver.get("816ee370-4274-e211-a3a8-b8ac6f902f00").toString(); assertEquals(checkValue, resultValue); //System.out.println("Match: " + IOUtils.toString(runner.getContentAsByteArray(result))); } catch (IOException e) { System.out.println("FOUT!!"); System.out.println(e.getStackTrace()); } catch (NullPointerException e) { System.out.println("weaver connection error (weaver-get)"); } } }