[jira] [Commented] (NIFI-1214) Mock Framework should allow order-independent assumptions on FlowFiles

2016-07-20 Thread Toivo Adams (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1214?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15385585#comment-15385585
 ] 

Toivo Adams commented on NIFI-1214:
---

I will try to solve on the weekend. 

> Mock Framework should allow order-independent assumptions on FlowFiles
> --
>
> Key: NIFI-1214
> URL: https://issues.apache.org/jira/browse/NIFI-1214
> Project: Apache NiFi
>  Issue Type: Improvement
>  Components: Tools and Build
>Reporter: Mark Payne
>Assignee: Toivo Adams
> Fix For: 1.0.0
>
>
> A common pattern in unit testing is to iterate over all FlowFiles that are 
> output to a Relationship and verify that each FlowFile matches one criteria 
> or another and that all criteria are met. For example, the following code 
> snippet from TestRouteText  verifies that two FlowFiles were output and that 
> Criteria A was met by one of them and Criteria B was met by the other:
> {code}
> final List list = 
> runner.getFlowFilesForRelationship("o");
> boolean found1 = false;
> boolean found2 = false;
> for (final MockFlowFile mff : list) {
> if (mff.getAttribute(RouteText.GROUP_ATTRIBUTE_KEY).equals("1")) {
> mff.assertContentEquals("1,hello\n1,good-bye");
> found1 = true;
> } else {
> mff.assertAttributeEquals(RouteText.GROUP_ATTRIBUTE_KEY, "2");
> mff.assertContentEquals("2,world\n");
> found2 = true;
> }
> }
> assertTrue(found1);
> assertTrue(found2);
> {code}
> This is very verbose, and error-prone. It could be done much more concisely 
> if we have a method like:
> {code}
> TestRunner.assertAllConditionsMet( Relationship relationship, 
> FlowFileVerifier... verifier );
> {code}
> Where FlowFileVerifier is able to verify some condition on a FlowFile. This 
> method would then be responsible for ensuring that each FlowFile that was 
> routed to 'relationship' meets one of the criteria specified by a verifier, 
> and that all of the verifiers were met. For example:
> {code}
> runner.assertAllConditionsMet( "o", 
> { mff -> mff.isAttributeEqual(RouteText.GROUP_ATTRIBUTE_KEY, "1") && 
> mff.isContentEqual("1,hello\n1,good-bye") },
> { mff -> mff.isAttributeEqual(RouteText.GROUP_ATTRIBUTE_KEY, "2") && 
> mff.isContentEqual("2,world\n") }
> );
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)


[jira] [Commented] (NIFI-1214) Mock Framework should allow order-independent assumptions on FlowFiles

2016-07-19 Thread Joseph Percivall (JIRA)

[ 
https://issues.apache.org/jira/browse/NIFI-1214?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel=15384938#comment-15384938
 ] 

Joseph Percivall commented on NIFI-1214:


Hey [~Toivo Adams], I see the PR has conflicts with master. Can you resolve 
them or can we punt this to 1.1?

> Mock Framework should allow order-independent assumptions on FlowFiles
> --
>
> Key: NIFI-1214
> URL: https://issues.apache.org/jira/browse/NIFI-1214
> Project: Apache NiFi
>  Issue Type: Improvement
>  Components: Tools and Build
>Reporter: Mark Payne
>Assignee: Toivo Adams
> Fix For: 1.0.0
>
>
> A common pattern in unit testing is to iterate over all FlowFiles that are 
> output to a Relationship and verify that each FlowFile matches one criteria 
> or another and that all criteria are met. For example, the following code 
> snippet from TestRouteText  verifies that two FlowFiles were output and that 
> Criteria A was met by one of them and Criteria B was met by the other:
> {code}
> final List list = 
> runner.getFlowFilesForRelationship("o");
> boolean found1 = false;
> boolean found2 = false;
> for (final MockFlowFile mff : list) {
> if (mff.getAttribute(RouteText.GROUP_ATTRIBUTE_KEY).equals("1")) {
> mff.assertContentEquals("1,hello\n1,good-bye");
> found1 = true;
> } else {
> mff.assertAttributeEquals(RouteText.GROUP_ATTRIBUTE_KEY, "2");
> mff.assertContentEquals("2,world\n");
> found2 = true;
> }
> }
> assertTrue(found1);
> assertTrue(found2);
> {code}
> This is very verbose, and error-prone. It could be done much more concisely 
> if we have a method like:
> {code}
> TestRunner.assertAllConditionsMet( Relationship relationship, 
> FlowFileVerifier... verifier );
> {code}
> Where FlowFileVerifier is able to verify some condition on a FlowFile. This 
> method would then be responsible for ensuring that each FlowFile that was 
> routed to 'relationship' meets one of the criteria specified by a verifier, 
> and that all of the verifiers were met. For example:
> {code}
> runner.assertAllConditionsMet( "o", 
> { mff -> mff.isAttributeEqual(RouteText.GROUP_ATTRIBUTE_KEY, "1") && 
> mff.isContentEqual("1,hello\n1,good-bye") },
> { mff -> mff.isAttributeEqual(RouteText.GROUP_ATTRIBUTE_KEY, "2") && 
> mff.isContentEqual("2,world\n") }
> );
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)