[ 
https://issues.apache.org/jira/browse/METRON-434?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15506818#comment-15506818
 ] 

ASF GitHub Bot commented on METRON-434:
---------------------------------------

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

    https://github.com/apache/incubator-metron/pull/261#discussion_r79632896
  
    --- Diff: 
metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/json/JSONMapParserTest.java
 ---
    @@ -0,0 +1,112 @@
    +/**
    + * 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.parsers.json;
    +
    +import com.google.common.collect.ImmutableMap;
    +import org.adrianwalker.multilinestring.Multiline;
    +import org.json.simple.JSONObject;
    +import org.junit.Assert;
    +import org.junit.Test;
    +
    +import java.util.List;
    +import java.util.Map;
    +
    +public class JSONMapParserTest {
    +
    +  /**
    +   {
    +     "foo" : "bar"
    +    ,"blah" : "blah"
    +    ,"number" : 2.0
    +   }
    +   */
    +   @Multiline
    +   static String happyPathJSON;
    +
    +  @Test
    +  public void testHappyPath() {
    +    JSONMapParser parser = new JSONMapParser();
    +    List<JSONObject> output = parser.parse(happyPathJSON.getBytes());
    +    Assert.assertEquals(output.size(), 1);
    +    //don't forget the timestamp field!
    +    Assert.assertEquals(output.get(0).size(), 5);
    +    JSONObject message = output.get(0);
    +    Assert.assertEquals("bar", message.get("foo"));
    +    Assert.assertEquals("blah", message.get("blah"));
    +    Assert.assertNotNull(message.get("timestamp"));
    +    Assert.assertTrue(message.get("timestamp") instanceof Number);
    +    Assert.assertNotNull(message.get("number"));
    +    Assert.assertTrue(message.get("number") instanceof Number);
    +  }
    +
    +  /**
    +   {
    +    "collection" : { "blah" : 7, "blah2" : "foo" }
    +   }
    +   */
    +   @Multiline
    +   static String collectionHandlingJSON;
    +
    +  @Test
    +  public void testCollectionHandlingDrop() {
    +    JSONMapParser parser = new JSONMapParser();
    +    List<JSONObject> output = 
parser.parse(collectionHandlingJSON.getBytes());
    +    Assert.assertEquals(output.size(), 1);
    +    //don't forget the timestamp field!
    +    Assert.assertEquals(output.get(0).size(), 2);
    +    JSONObject message = output.get(0);
    +    Assert.assertNotNull(message.get("timestamp"));
    +    Assert.assertTrue(message.get("timestamp") instanceof Number);
    +  }
    +
    +  @Test(expected=IllegalStateException.class)
    +  public void testCollectionHandlingError() {
    +    JSONMapParser parser = new JSONMapParser();
    +    parser.configure(ImmutableMap.of("mapStrategy", "ERROR"));
    +    List<JSONObject> output = 
parser.parse(collectionHandlingJSON.getBytes());
    +  }
    +
    +
    +  @Test
    +  public void testCollectionHandlingAllow() {
    +    JSONMapParser parser = new JSONMapParser();
    +    parser.configure(ImmutableMap.of("mapStrategy", "ALLOW"));
    --- End diff --
    
    Agreed


> JSON Parser
> -----------
>
>                 Key: METRON-434
>                 URL: https://issues.apache.org/jira/browse/METRON-434
>             Project: Metron
>          Issue Type: New Feature
>    Affects Versions: 0.2.1BETA
>            Reporter: Casey Stella
>            Assignee: Casey Stella
>   Original Estimate: 48h
>  Remaining Estimate: 48h
>
> Create a parser which will take a JSON map in.  
> Inner maps should be handled pluggably by:
> * doing nothing
> * unfolding maps (e.g. `{ "foo" : { "bar" : 7 } }` is transformed into 
> `{"foo.bar" : 7 }`
> * Throwing an exception
> * Dropping the inner map.



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

Reply via email to