Github user markap14 commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1108#discussion_r83229335
  
    --- Diff: 
nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestGrokParser.java
 ---
    @@ -0,0 +1,104 @@
    +/*
    + * 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.processors.standard;
    +
    +
    +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 java.io.IOException;
    +import java.nio.file.Path;
    +import java.nio.file.Paths;
    +
    +/**
    + * Created by snamsi on 05/10/16.
    + */
    +public class TestGrokParser {
    +
    +    private TestRunner testRunner;
    +    final static Path GROK_LOG_INPUT = 
Paths.get("src/test/resources/TestGrokParser/apache.log");
    +    final static Path GROK_TEXT_INPUT = 
Paths.get("src/test/resources/TestGrokParser/simple_text.log");
    +
    +
    +    @Before
    +    public void init() {
    +        testRunner = TestRunners.newTestRunner(GrokParser.class);
    +    }
    +
    +    @Test
    +    public void testGrokParserWithMatchedContent() throws IOException {
    +
    +
    +        testRunner.setProperty(GrokParser.GROK_EXPRESSION, 
"%{COMMONAPACHELOG}");
    +        testRunner.setProperty(GrokParser.GROK_PATTERN_FILE, 
"src/test/resources/TestGrokParser/patterns");
    +        testRunner.enqueue(GROK_LOG_INPUT);
    +        testRunner.run();
    +        testRunner.assertAllFlowFilesTransferred(GrokParser.REL_MATCH);
    +        final MockFlowFile matched = 
testRunner.getFlowFilesForRelationship(GrokParser.REL_MATCH).get(0);
    +
    +        matched.assertAttributeEquals("verb","GET");
    +        matched.assertAttributeEquals("response","401");
    +        matched.assertAttributeEquals("bytes","12846");
    +        matched.assertAttributeEquals("clientip","64.242.88.10");
    +        matched.assertAttributeEquals("auth","-");
    +        matched.assertAttributeEquals("timestamp","07/Mar/2004:16:05:49 
-0800");
    +        
matched.assertAttributeEquals("request","/twiki/bin/edit/Main/Double_bounce_sender?topicparent=Main.ConfigurationVariables");
    +        matched.assertAttributeEquals("httpversion","1.1");
    +
    +    }
    +
    +    @Test
    +    public void testGrokParserWithUnMatchedContent() throws IOException {
    +
    +
    +        testRunner.setProperty(GrokParser.GROK_EXPRESSION, "%{ADDRESS}");
    +        testRunner.setProperty(GrokParser.GROK_PATTERN_FILE, 
"src/test/resources/TestGrokParser/patterns");
    +        testRunner.enqueue(GROK_TEXT_INPUT);
    +        testRunner.run();
    +        testRunner.assertAllFlowFilesTransferred(GrokParser.REL_NO_MATCH);
    +        final MockFlowFile notMatched = 
testRunner.getFlowFilesForRelationship(GrokParser.REL_NO_MATCH).get(0);
    +        notMatched.assertContentEquals(GROK_TEXT_INPUT);
    +
    +    }
    +
    +    @Test(expected = java.lang.AssertionError.class)
    --- End diff --
    
    Rather than expected an AssertionError, we should avoid calling 
testRunner.run() and instead just use testRunner.assertNotValid()


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to