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

    https://github.com/apache/incubator-metron/pull/136#discussion_r64777528
  
    --- Diff: 
metron-platform/metron-common/src/test/java/org/apache/metron/common/field/transformation/RemoveTransformationTest.java
 ---
    @@ -0,0 +1,100 @@
    +/**
    + * 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.metron.common.field.transformation;
    +
    +import com.google.common.collect.Iterables;
    +import org.adrianwalker.multilinestring.Multiline;
    +import org.apache.hadoop.hbase.util.Bytes;
    +import org.apache.metron.common.configuration.FieldTransformer;
    +import org.apache.metron.common.configuration.SensorParserConfig;
    +import org.json.simple.JSONObject;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.util.HashMap;
    +
    +public class RemoveTransformationTest {
    +  /**
    +   {
    +    "fieldTransformations" : [
    +          {
    +            "input" : "field1"
    +          , "transformation" : "REMOVE"
    +          }
    +                      ]
    +   }
    +   */
    +  @Multiline
    +  public static String removeUnconditionalConfig;
    +
    +  @Test
    +  public void testUnconditionalRemove() throws Exception{
    +    SensorParserConfig c = 
SensorParserConfig.fromBytes(Bytes.toBytes(removeUnconditionalConfig));
    +    FieldTransformer handler = 
Iterables.getFirst(c.getFieldTransformations(), null);
    +    JSONObject input = new JSONObject(new HashMap<String, Object>() {{
    +      put("field1", "foo");
    +    }});
    +    handler.transformAndUpdate(input, new HashMap<>());
    +    Assert.assertFalse(input.containsKey("field1"));
    +  }
    +
    +  /**
    +   {
    +    "fieldTransformations" : [
    +          {
    +            "input" : "field1"
    +          , "transformation" : "REMOVE"
    +          , "config" : {
    +              "condition" : "exists(field2) and field2 == 'foo'"
    +                       }
    +          }
    +                      ]
    +   }
    +   */
    +  @Multiline
    +  public static String removeConditionalConfig;
    +  @Test
    +  public void testConditionalRemove() throws Exception {
    +    SensorParserConfig c = 
SensorParserConfig.fromBytes(Bytes.toBytes(removeConditionalConfig));
    +    FieldTransformer handler = 
Iterables.getFirst(c.getFieldTransformations(), null);
    +    {
    +      JSONObject input = new JSONObject(new HashMap<String, Object>() {{
    +        put("field1", "foo");
    +      }});
    +      handler.transformAndUpdate(input, new HashMap<>());
    +      Assert.assertTrue(input.containsKey("field1"));
    +    }
    +    {
    +      JSONObject input = new JSONObject(new HashMap<String, Object>() {{
    +        put("field1", "foo");
    +        put("field2", "bar");
    +      }});
    +      handler.transformAndUpdate(input, new HashMap<>());
    +      Assert.assertTrue(input.containsKey("field1"));
    --- End diff --
    
    I misunderstood the test.  Since field2 exists and its value is 'foo', then 
the code should not remove 'field1'.  And this is what you've asserted.  So 
looks good, but quick comments for those of us who are less bright would be 
awesome.


---
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