[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-07 Thread peter-gergely-horvath
Github user peter-gergely-horvath commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200807442
  
--- Diff: 
nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/test/util/FileUtils.java
 ---
@@ -0,0 +1,84 @@
+/*
+ * 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 org.apache.nifi.test.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.*;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+
+public final class FileUtils {
+
+
+private static final String MAC_DS_STORE_NAME = ".DS_Store";
--- End diff --

I think this is probably fine: if you look at the code usages, it is used 
to avoid symlinking a Mac system directory; it should not have any side effect 
on other systems.


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-07 Thread peter-gergely-horvath
Github user peter-gergely-horvath commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200807310
  
--- Diff: nifi-docs/src/main/asciidoc/developer-guide.adoc ---
@@ -2296,6 +2296,32 @@ threads that should be used to run the Processor can
 be set via the `setThreadCount(int)` method.
 
 
+=== Experimental NiFi Flow test harness
+
+NiFi now has an experimental feature for full end-to-end testing of flows. 
This allows us
+to take a NiFi flow, install it to a test NiFi instance, run it and make 
Java unit test
+like asserts regarding its behaviour.
+
+The class `org.apache.nifi.test.TestNiFiInstance` is a thin wrapper that 
allows us
+to manipulate a NiFi installation and deploy a flow with some adjustments
+to its configuration, including changing processor properties and 
replacing processor
+classes with mocks.
+
+In order to add the necessary classes to your project,
+you can use the Maven dependency:
+
+[source]
+
+
+   org.apache.nifi
+   nifi-test
+   ${nifi version}
+
+
+
+For further documentation, please consult the JavaDoc of
+`org.apache.nifi.test.TestNiFiInstance`. For samples, please take a look at

+link:https://github.com/apache/nifi/tree/master/nifi-test/src/test/java/org/apache/test/samples[samples
 on GitHub^].
--- End diff --

The idea is that users should be able to write test cases in Java for NiFi 
flows: these code samples linked there would demonstrate creating a test case 
like that.


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-07 Thread peter-gergely-horvath
Github user peter-gergely-horvath commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200807326
  
--- Diff: 
nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/test/SimpleNiFiFlowDefinitionEditor.java
 ---
@@ -0,0 +1,144 @@
+/*
+ * 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 org.apache.nifi.test;
+
+import org.apache.nifi.test.api.FlowFileEditorCallback;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+import java.util.LinkedList;
+
+
+/**
+ * 
+ * A facility to describe simple, common changes to a NiFi flow before it 
is installed to the test
+ * NiFi instance. Intended to be used by
+ * {@link 
TestNiFiInstance.Builder#modifyFlowXmlBeforeInstalling(FlowFileEditorCallback)}
+ * 
+ *
+ * 
+ * The desired edits can be configured via the {@link Builder} object 
returned by the {@link #builder()}
+ * method. Once fully configured, the {@link Builder#build()} emits a 
{@code FlowFileEditorCallback}
+ * object that can be passed to
+ * {@link 
TestNiFiInstance.Builder#modifyFlowXmlBeforeInstalling(FlowFileEditorCallback)}.
+ * 
+ *
+ * 
+ * CAUTION: THIS IS AN EXPERIMENTAL API: EXPECT CHANGES!
+ * Efforts will be made to retain backwards API compatibility, but
+ * no guarantee is given.
+ * 
+ *
+ * @see 
TestNiFiInstance.Builder#modifyFlowXmlBeforeInstalling(FlowFileEditorCallback)
+ *
+ * @author Peter G. Horvath
--- End diff --

I'll fix in my fork and create a new pull request later on.


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-07 Thread peter-gergely-horvath
Github user peter-gergely-horvath commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200807322
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java
 ---
@@ -57,6 +57,9 @@
  * @param extensionMapping extension mapping
  */
 public static void generate(final NiFiProperties properties, final 
ExtensionMapping extensionMapping) {
+
--- End diff --

yes, indeed, this somehow slipped in: I'll fix in my fork and create a new 
pull request later on.


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-07 Thread peter-gergely-horvath
Github user peter-gergely-horvath commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200807286
  
--- Diff: nifi-test/pom.xml ---
@@ -0,0 +1,145 @@
+http://maven.apache.org/POM/4.0.0; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+
+nifi
+org.apache.nifi
+1.8.0-SNAPSHOT
+
+
+4.0.0
+
+com.thinkbiganalytics
+nifi-test
--- End diff --

It makes sense. I'll fix in my fork and create a new pull request later on.


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-07 Thread peter-gergely-horvath
Github user peter-gergely-horvath commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200807283
  
--- Diff: nifi-test/pom.xml ---
@@ -0,0 +1,145 @@
+http://maven.apache.org/POM/4.0.0; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+
+nifi
+org.apache.nifi
+1.8.0-SNAPSHOT
+
+
+4.0.0
+
--- End diff --

Yes, this was incorrect: I'll fix in my fork and create a new pull request 
later on.


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-06 Thread joewitt
Github user joewitt commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200799818
  
--- Diff: 
nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/test/util/FileUtils.java
 ---
@@ -0,0 +1,84 @@
+/*
+ * 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 org.apache.nifi.test.util;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.file.*;
+import java.nio.file.attribute.BasicFileAttributes;
+import java.util.Arrays;
+
+public final class FileUtils {
+
+
+private static final String MAC_DS_STORE_NAME = ".DS_Store";
--- End diff --

the osx specific nature of this is concerning


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-06 Thread joewitt
Github user joewitt commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200799793
  
--- Diff: 
nifi-toolkit/nifi-toolkit-tls/src/main/java/org/apache/nifi/test/SimpleNiFiFlowDefinitionEditor.java
 ---
@@ -0,0 +1,144 @@
+/*
+ * 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 org.apache.nifi.test;
+
+import org.apache.nifi.test.api.FlowFileEditorCallback;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+import java.util.LinkedList;
+
+
+/**
+ * 
+ * A facility to describe simple, common changes to a NiFi flow before it 
is installed to the test
+ * NiFi instance. Intended to be used by
+ * {@link 
TestNiFiInstance.Builder#modifyFlowXmlBeforeInstalling(FlowFileEditorCallback)}
+ * 
+ *
+ * 
+ * The desired edits can be configured via the {@link Builder} object 
returned by the {@link #builder()}
+ * method. Once fully configured, the {@link Builder#build()} emits a 
{@code FlowFileEditorCallback}
+ * object that can be passed to
+ * {@link 
TestNiFiInstance.Builder#modifyFlowXmlBeforeInstalling(FlowFileEditorCallback)}.
+ * 
+ *
+ * 
+ * CAUTION: THIS IS AN EXPERIMENTAL API: EXPECT CHANGES!
+ * Efforts will be made to retain backwards API compatibility, but
+ * no guarantee is given.
+ * 
+ *
+ * @see 
TestNiFiInstance.Builder#modifyFlowXmlBeforeInstalling(FlowFileEditorCallback)
+ *
+ * @author Peter G. Horvath
--- End diff --

please remove all author tags from all javadocs


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-06 Thread joewitt
Github user joewitt commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200799695
  
--- Diff: nifi-docs/src/main/asciidoc/developer-guide.adoc ---
@@ -2296,6 +2296,32 @@ threads that should be used to run the Processor can
 be set via the `setThreadCount(int)` method.
 
 
+=== Experimental NiFi Flow test harness
+
+NiFi now has an experimental feature for full end-to-end testing of flows. 
This allows us
+to take a NiFi flow, install it to a test NiFi instance, run it and make 
Java unit test
+like asserts regarding its behaviour.
+
+The class `org.apache.nifi.test.TestNiFiInstance` is a thin wrapper that 
allows us
+to manipulate a NiFi installation and deploy a flow with some adjustments
+to its configuration, including changing processor properties and 
replacing processor
+classes with mocks.
+
+In order to add the necessary classes to your project,
+you can use the Maven dependency:
+
+[source]
+
+
+   org.apache.nifi
+   nifi-test
+   ${nifi version}
+
+
+
+For further documentation, please consult the JavaDoc of
+`org.apache.nifi.test.TestNiFiInstance`. For samples, please take a look at

+link:https://github.com/apache/nifi/tree/master/nifi-test/src/test/java/org/apache/test/samples[samples
 on GitHub^].
--- End diff --

what is this link really meant to be?


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-06 Thread joewitt
Github user joewitt commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200799698
  
--- Diff: 
nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/main/java/org/apache/nifi/documentation/DocGenerator.java
 ---
@@ -57,6 +57,9 @@
  * @param extensionMapping extension mapping
  */
 public static void generate(final NiFiProperties properties, final 
ExtensionMapping extensionMapping) {
+
--- End diff --

these extra lines should be removed


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-06 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200798916
  
--- Diff: nifi-test/pom.xml ---
@@ -0,0 +1,145 @@
+http://maven.apache.org/POM/4.0.0; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+
+nifi
+org.apache.nifi
+1.8.0-SNAPSHOT
+
+
+4.0.0
+
+com.thinkbiganalytics
+nifi-test
--- End diff --

+1


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-06 Thread MikeThomsen
Github user MikeThomsen commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200798895
  
--- Diff: nifi-test/pom.xml ---
@@ -0,0 +1,145 @@
+http://maven.apache.org/POM/4.0.0; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+
+nifi
+org.apache.nifi
+1.8.0-SNAPSHOT
+
+
+4.0.0
+
--- End diff --

Agreed. AFAIK, things like this need to be refactored, where possible, to 
`org.apache.nifi.*`


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-05 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200353847
  
--- Diff: nifi-test/pom.xml ---
@@ -0,0 +1,145 @@
+http://maven.apache.org/POM/4.0.0; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+
+nifi
+org.apache.nifi
+1.8.0-SNAPSHOT
+
+
+4.0.0
+
+com.thinkbiganalytics
+nifi-test
--- End diff --

nifi-test seems too generic for this.  why not nifi-test-harness ?


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-05 Thread ottobackwards
Github user ottobackwards commented on a diff in the pull request:

https://github.com/apache/nifi/pull/2843#discussion_r200353601
  
--- Diff: nifi-test/pom.xml ---
@@ -0,0 +1,145 @@
+http://maven.apache.org/POM/4.0.0; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance;
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd;>
+
+nifi
+org.apache.nifi
+1.8.0-SNAPSHOT
+
+
+4.0.0
+
--- End diff --

I don't think this should be thingbiganalytics


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-05 Thread peter-gergely-horvath
Github user peter-gergely-horvath closed the pull request at:

https://github.com/apache/nifi/pull/2843


---


[GitHub] nifi pull request #2843: NIFI-5318 Implement NiFi test harness: initial comm...

2018-07-04 Thread peter-gergely-horvath
GitHub user peter-gergely-horvath opened a pull request:

https://github.com/apache/nifi/pull/2843

NIFI-5318 Implement NiFi test harness: initial commit of nifi-test

Thank you for submitting a contribution to Apache NiFi.

In order to streamline the review of the contribution we ask you
to ensure the following steps have been taken:

### For all changes:
- [x] Is there a JIRA ticket associated with this PR? Is it referenced 
 in the commit message?

- [x] Does your PR title start with NIFI- where  is the JIRA number 
you are trying to resolve? Pay particular attention to the hyphen "-" character.

- [x] Has your PR been rebased against the latest commit within the target 
branch (typically master)?

- [ x Is your initial contribution a single, squashed commit?

### For code changes:
- [ ] Have you ensured that the full suite of tests is executed via mvn 
-Pcontrib-check clean install at the root nifi folder?
At the moment, the build fails with unit test failures unrelated to this 
commit:
```
[INFO] Running org.apache.nifi.csv.TestCSVValidators
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 
0.018 s - in org.apache.nifi.csv.TestCSVValidators
[INFO] Running org.apache.nifi.csv.TestJacksonCSVRecordReader
[ERROR] Tests run: 11, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 
0.033 s <<< FAILURE! - in org.apache.nifi.csv.TestJacksonCSVRecordReader
[ERROR] testUTF8(org.apache.nifi.csv.TestJacksonCSVRecordReader)  Time 
elapsed: 0.002 s  <<< FAILURE!
org.junit.ComparisonFailure: expected:<[黃凱揚]> but was:<[???]>
at 
org.apache.nifi.csv.TestJacksonCSVRecordReader.testUTF8(TestJacksonCSVRecordReader.java:81)

[INFO] Running org.apache.nifi.csv.TestCSVHeaderSchemaStrategy
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 
0.004 s - in org.apache.nifi.csv.TestCSVHeaderSchemaStrategy
[INFO] Running org.apache.nifi.csv.TestCSVRecordReader
[INFO] Tests run: 21, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 
0.015 s - in org.apache.nifi.csv.TestCSVRecordReader
[INFO] Running org.apache.nifi.csv.TestWriteCSVResult
[INFO] Tests run: 7, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 
0.004 s - in org.apache.nifi.csv.TestWriteCSVResult
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   TestJacksonCSVRecordReader.testUTF8:81 expected:<[黃凱揚]> but 
was:<[???]>
[ERROR]   TestXMLReader.testAttributePrefix:133 expected:<... ATTR_ID=P3, 
NAME=Am[é]lie Bonfils, AGE=74}...> but was:<... ATTR_ID=P3, NAME=Am[?]lie 
Bonfils, AGE=74}...>
[ERROR]   TestXMLReader.testContentField:156 
expected:<...apRecord[{CONTENT=Am[é]lie Bonfils, ATTR=at...> but 
was:<...apRecord[{CONTENT=Am[?]lie Bonfils, ATTR=at...>
[INFO] 
[ERROR] Tests run: 221, Failures: 3, Errors: 0, Skipped: 2
[INFO] 
[INFO] 

```

- [ ] Have you written or updated unit tests to verify your changes?
- [ ] If adding new dependencies to the code, are these dependencies 
licensed in a way that is compatible for inclusion under [ASF 
2.0](http://www.apache.org/legal/resolved.html#category-a)? 
- [ ] If applicable, have you updated the LICENSE file, including the main 
LICENSE file under nifi-assembly?
- [ ] If applicable, have you updated the NOTICE file, including the main 
NOTICE file found under nifi-assembly?
- [ ] If adding new Properties, have you added .displayName in addition to 
.name (programmatic access) for each of the new properties?

### For documentation related changes:
- [ ] Have you ensured that format looks appropriate for the output in 
which it is rendered?

### Note:
Please ensure that once the PR is submitted, you check travis-ci for build 
issues and submit an update to your PR as soon as possible.


You can merge this pull request into a Git repository by running:

$ git pull https://github.com/peter-gergely-horvath/nifi master

Alternatively you can review and apply these changes as the patch at:

https://github.com/apache/nifi/pull/2843.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

This closes #2843


commit 02e338e3b2c53c6a0af8f83f44378b4a242e0ec1
Author: Peter G. Horvath 
Date:   2018-07-04T18:44:06Z

NIFI-5318 Implement NiFi test harness: initial commit of nifi-test




---