You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@metron.apache.org by le...@apache.org on 2017/06/07 14:20:50 UTC
[4/4] metron git commit: METRON-962 Configuration Based Unit Tests
and Add integration tests (justinleet via leet) closes apache/metron#612
METRON-962 Configuration Based Unit Tests and Add integration tests (justinleet via leet) closes apache/metron#612
Project: http://git-wip-us.apache.org/repos/asf/metron/repo
Commit: http://git-wip-us.apache.org/repos/asf/metron/commit/5b72da7b
Tree: http://git-wip-us.apache.org/repos/asf/metron/tree/5b72da7b
Diff: http://git-wip-us.apache.org/repos/asf/metron/diff/5b72da7b
Branch: refs/heads/master
Commit: 5b72da7be0521fc16e887dd4a1c958ceaeaa6510
Parents: 605a3cc
Author: justinleet <ju...@gmail.com>
Authored: Wed Jun 7 10:19:56 2017 -0400
Committer: YOUR NAME as In Apache <YO...@apache.org>
Committed: Wed Jun 7 10:19:56 2017 -0400
----------------------------------------------------------------------
.../common/cli/ConfigurationsUtilsTest.java | 2 +-
.../configuration/ConfigurationsTest.java | 2 +-
.../SensorEnrichmentConfigTest.java | 2 +-
.../metron/enrichment/bolt/SplitBoltTest.java | 2 +-
.../bolt/ThreatIntelJoinBoltTest.java | 2 +-
.../bolt/ThreatIntelSplitterBoltTest.java | 3 +-
.../metron/parsers/asa/GrokAsaParser.java | 285 -----------------
.../parsers/fireeye/BasicFireEyeParser.java | 2 +-
.../metron/parsers/AbstractConfigTest.java | 300 ------------------
.../parsers/AbstractParserConfigTest.java | 92 ++++++
.../metron/parsers/AbstractSchemaTest.java | 204 ------------
.../metron/parsers/AbstractTestContext.java | 190 ------------
.../apache/metron/parsers/GrokParserTest.java | 2 +-
.../metron/parsers/MessageParserTest.java | 2 +-
.../metron/parsers/asa/GrokAsaParserTest.java | 169 ----------
.../metron/parsers/bro/BasicBroParserTest.java | 62 ++--
.../metron/parsers/bro/BroParserTest.java | 164 ----------
.../metron/parsers/cef/CEFParserTest.java | 95 +++---
.../parsers/fireeye/BasicFireEyeParserTest.java | 157 ++--------
.../integration/ParserIntegrationTest.java | 2 +-
.../metron/parsers/ise/BasicIseParserTest.java | 176 ++---------
.../parsers/lancope/BasicLancopeParserTest.java | 148 ++-------
.../BasicPaloAltoFirewallParserTest.java | 164 ++--------
.../sourcefire/BasicSourcefireParserTest.java | 164 ++--------
.../resources/config/GrokAsaParserTest.config | 20 --
.../resources/logData/FireEyeParserTest.txt | 8 +
.../test/resources/logData/IseParserTest.txt | 308 +++++++++++++++++++
.../resources/logData/LancopeParserTest.txt | 1 +
.../logData/PaloAltoFirewallParserTest.txt | 2 +
.../resources/logData/SourcefireParserTest.txt | 3 +
.../apache/metron/pcap/utils/PcapUtilsTest.java | 2 +-
31 files changed, 648 insertions(+), 2087 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
index 0645619..0c72183 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/cli/ConfigurationsUtilsTest.java
@@ -17,12 +17,12 @@
*/
package org.apache.metron.common.cli;
-import junit.framework.Assert;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.test.TestingServer;
import org.apache.metron.TestConstants;
import org.apache.metron.common.configuration.ConfigurationsUtils;
import org.apache.metron.common.utils.JSONUtils;
+import org.junit.Assert;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
index 4720929..992f0a7 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/ConfigurationsTest.java
@@ -17,10 +17,10 @@
*/
package org.apache.metron.common.configuration;
-import junit.framework.Assert;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.junit.Test;
+import org.junit.Assert;
import java.io.IOException;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
index 305182b..5a77b4f 100644
--- a/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
+++ b/metron-platform/metron-common/src/test/java/org/apache/metron/common/configuration/SensorEnrichmentConfigTest.java
@@ -17,12 +17,12 @@
*/
package org.apache.metron.common.configuration;
-import junit.framework.Assert;
import nl.jqno.equalsverifier.EqualsVerifier;
import nl.jqno.equalsverifier.Warning;
import org.apache.commons.io.IOUtils;
import org.apache.metron.TestConstants;
import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
+import org.junit.Assert;
import org.junit.Test;
import java.io.BufferedReader;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/SplitBoltTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/SplitBoltTest.java b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/SplitBoltTest.java
index d0ca475..41d34de 100644
--- a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/SplitBoltTest.java
+++ b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/SplitBoltTest.java
@@ -22,10 +22,10 @@ import org.apache.storm.topology.OutputFieldsDeclarer;
import org.apache.storm.tuple.Tuple;
import org.apache.storm.tuple.Values;
import com.google.common.collect.ImmutableList;
-import junit.framework.Assert;
import org.apache.metron.common.configuration.ConfigurationType;
import org.apache.metron.test.bolt.BaseEnrichmentBoltTest;
import org.json.simple.JSONObject;
+import org.junit.Assert;
import org.junit.Test;
import java.util.HashMap;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBoltTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBoltTest.java b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBoltTest.java
index 0f3cc8c..04617ff 100644
--- a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBoltTest.java
+++ b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelJoinBoltTest.java
@@ -18,7 +18,6 @@
package org.apache.metron.enrichment.bolt;
import com.fasterxml.jackson.databind.JsonMappingException;
-import junit.framework.Assert;
import org.adrianwalker.multilinestring.Multiline;
import org.apache.metron.common.configuration.enrichment.SensorEnrichmentConfig;
import org.apache.metron.common.configuration.enrichment.threatintel.ThreatTriageConfig;
@@ -31,6 +30,7 @@ import org.apache.storm.tuple.Tuple;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelSplitterBoltTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelSplitterBoltTest.java b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelSplitterBoltTest.java
index 6898c89..4feba2e 100644
--- a/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelSplitterBoltTest.java
+++ b/metron-platform/metron-enrichment/src/test/java/org/apache/metron/enrichment/bolt/ThreatIntelSplitterBoltTest.java
@@ -17,14 +17,13 @@
*/
package org.apache.metron.enrichment.bolt;
-import junit.framework.Assert;
import org.apache.metron.test.bolt.BaseEnrichmentBoltTest;
+import org.junit.Assert;
import org.junit.Test;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.HashMap;
-import java.util.List;
import java.util.Map;
public class ThreatIntelSplitterBoltTest extends BaseEnrichmentBoltTest {
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/asa/GrokAsaParser.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/asa/GrokAsaParser.java b/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/asa/GrokAsaParser.java
deleted file mode 100644
index 4f1c8b0..0000000
--- a/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/asa/GrokAsaParser.java
+++ /dev/null
@@ -1,285 +0,0 @@
-/**
- * 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.asa;
-
-import oi.thekraken.grok.api.Grok;
-import oi.thekraken.grok.api.Match;
-import oi.thekraken.grok.api.exception.GrokException;
-import org.apache.commons.io.IOUtils;
-import org.apache.metron.parsers.BasicParser;
-import org.json.simple.JSONObject;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.text.ParseException;
-import java.text.SimpleDateFormat;
-import java.util.*;
-
-public class GrokAsaParser extends BasicParser {
-
- private static final long serialVersionUID = 945353287115350798L;
- private transient Grok grok;
- Map<String, String> patternMap;
- private transient Map<String, Grok> grokMap;
- private transient InputStream pattern_url;
-
- public static final String PREFIX = "stream2file";
- public static final String SUFFIX = ".tmp";
-
- public static File stream2file(InputStream in) throws IOException {
- final File tempFile = File.createTempFile(PREFIX, SUFFIX);
- tempFile.deleteOnExit();
- try (FileOutputStream out = new FileOutputStream(tempFile)) {
- IOUtils.copy(in, out);
- }
- return tempFile;
- }
-
- public GrokAsaParser() throws Exception {
- // pattern_url = Resources.getResource("patterns/asa");
-
- pattern_url = getClass().getClassLoader().getResourceAsStream(
- "src/main/patterns/asa");
-
- File file = stream2file(pattern_url);
- grok = Grok.create(file.getPath());
-
- patternMap = getPatternMap();
- grokMap = getGrokMap();
-
- grok.compile("%{CISCO_TAGGED_SYSLOG}");
- }
-
- public GrokAsaParser(String filepath) throws Exception {
-
- grok = Grok.create(filepath);
- // grok.getNamedRegexCollection().put("ciscotag","CISCOFW302013_302014_302015_302016");
- grok.compile("%{CISCO_TAGGED_SYSLOG}");
-
- }
-
- public GrokAsaParser(String filepath, String pattern) throws Exception {
-
- grok = Grok.create(filepath);
- grok.compile("%{" + pattern + "}");
- }
-
- private Map<String, Object> getMap(String pattern, String text)
- throws GrokException {
-
- Grok g = grokMap.get(pattern);
- if (g != null) {
- Match gm = g.match(text);
- gm.captures();
- return gm.toMap();
- } else {
- return new HashMap<String, Object>();
- }
-
- }
-
- private Map<String, Grok> getGrokMap() throws GrokException, IOException {
- Map<String, Grok> map = new HashMap<String, Grok>();
-
- for (Map.Entry<String, String> entry : patternMap.entrySet()) {
- File file = stream2file(pattern_url);
- Grok grok = Grok.create(file.getPath());
- grok.compile("%{" + entry.getValue() + "}");
-
- map.put(entry.getValue(), grok);
-
- }
-
- return map;
- }
-
- private Map<String, String> getPatternMap() {
- Map<String, String> map = new HashMap<String, String>();
-
- map.put("ASA-2-106001", "CISCOFW106001");
- map.put("ASA-2-106006", "CISCOFW106006_106007_106010");
- map.put("ASA-2-106007", "CISCOFW106006_106007_106010");
- map.put("ASA-2-106010", "CISCOFW106006_106007_106010");
- map.put("ASA-3-106014", "CISCOFW106014");
- map.put("ASA-6-106015", "CISCOFW106015");
- map.put("ASA-1-106021", "CISCOFW106021");
- map.put("ASA-4-106023", "CISCOFW106023");
- map.put("ASA-5-106100", "CISCOFW106100");
- map.put("ASA-6-110002", "CISCOFW110002");
- map.put("ASA-6-302010", "CISCOFW302010");
- map.put("ASA-6-302013", "CISCOFW302013_302014_302015_302016");
- map.put("ASA-6-302014", "CISCOFW302013_302014_302015_302016");
- map.put("ASA-6-302015", "CISCOFW302013_302014_302015_302016");
- map.put("ASA-6-302016", "CISCOFW302013_302014_302015_302016");
- map.put("ASA-6-302020", "CISCOFW302020_302021");
- map.put("ASA-6-302021", "CISCOFW302020_302021");
- map.put("ASA-6-305011", "CISCOFW305011");
- map.put("ASA-3-313001", "CISCOFW313001_313004_313008");
- map.put("ASA-3-313004", "CISCOFW313001_313004_313008");
- map.put("ASA-3-313008", "CISCOFW313001_313004_313008");
- map.put("ASA-4-313005", "CISCOFW313005");
- map.put("ASA-4-402117", "CISCOFW402117");
- map.put("ASA-4-402119", "CISCOFW402119");
- map.put("ASA-4-419001", "CISCOFW419001");
- map.put("ASA-4-419002", "CISCOFW419002");
- map.put("ASA-4-500004", "CISCOFW500004");
- map.put("ASA-6-602303", "CISCOFW602303_602304");
- map.put("ASA-6-602304", "CISCOFW602303_602304");
- map.put("ASA-7-710001", "CISCOFW710001_710002_710003_710005_710006");
- map.put("ASA-7-710002", "CISCOFW710001_710002_710003_710005_710006");
- map.put("ASA-7-710003", "CISCOFW710001_710002_710003_710005_710006");
- map.put("ASA-7-710005", "CISCOFW710001_710002_710003_710005_710006");
- map.put("ASA-7-710006", "CISCOFW710001_710002_710003_710005_710006");
- map.put("ASA-6-713172", "CISCOFW713172");
- map.put("ASA-4-733100", "CISCOFW733100");
- map.put("ASA-6-305012", "CISCOFW305012");
- map.put("ASA-7-609001", "CISCOFW609001");
- map.put("ASA-7-609002", "CISCOFW609002");
-
- return map;
- }
-
- public static Long convertToEpoch(String m, String d, String ts,
- boolean adjust_timezone) throws ParseException {
- d = d.trim();
-
- if (d.length() <= 2)
- d = "0" + d;
-
- Date date = new SimpleDateFormat("MMM", Locale.ENGLISH).parse(m);
- Calendar cal = Calendar.getInstance();
- cal.setTime(date);
- String month = String.valueOf(cal.get(Calendar.MONTH));
- int year = Calendar.getInstance().get(Calendar.YEAR);
-
- if (month.length() <= 2)
- month = "0" + month;
-
- String coglomerated_ts = year + "-" + month + "-" + d + " " + ts;
-
- System.out.println(coglomerated_ts);
-
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-
- if (adjust_timezone)
- sdf.setTimeZone(TimeZone.getTimeZone("GMT"));
-
- date = sdf.parse(coglomerated_ts);
- long timeInMillisSinceEpoch = date.getTime();
-
- return timeInMillisSinceEpoch;
- }
-
- @Override
- public void configure(Map<String, Object> parserConfig) {
-
- }
-
- @Override
- public void init() {
- // pattern_url = Resources.getResource("patterns/asa");
-
- pattern_url = getClass().getClassLoader().getResourceAsStream(
- "src/main/patterns/asa");
-
- File file = null;
- try {
- file = stream2file(pattern_url);
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- try {
- grok = Grok.create(file.getPath());
- } catch (GrokException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- patternMap = getPatternMap();
- try {
- grokMap = getGrokMap();
- } catch (GrokException | IOException e1) {
- // TODO Auto-generated catch block
- e1.printStackTrace();
- }
-
- try {
- grok.compile("%{CISCO_TAGGED_SYSLOG}");
- } catch (GrokException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public List<JSONObject> parse(byte[] raw_message) {
-
- String toParse = "";
- JSONObject toReturn;
- List<JSONObject> messages = new ArrayList<>();
- try {
-
- toParse = new String(raw_message, "UTF-8");
-
- System.out.println("Received message: " + toParse);
-
- Match gm = grok.match(toParse);
- gm.captures();
-
- toReturn = new JSONObject();
-
- toReturn.putAll(gm.toMap());
-
- String str = toReturn.get("ciscotag").toString();
- String pattern = patternMap.get(str);
-
- Map<String, Object> response = getMap(pattern, toParse);
-
- toReturn.putAll(response);
-
- //System.out.println("*******I MAPPED: " + toReturn);
- long timestamp = convertToEpoch(toReturn.get("MONTH").toString(), toReturn
- .get("MONTHDAY").toString(),
- toReturn.get("TIME").toString(),
- true);
- toReturn.put("timestamp", timestamp);
-
- toReturn.remove("MONTHDAY");
- toReturn.remove("TIME");
- toReturn.remove("MINUTE");
- toReturn.remove("HOUR");
- toReturn.remove("YEAR");
- toReturn.remove("SECOND");
-
- toReturn.put("ip_src_addr", toReturn.remove("IPORHOST"));
- toReturn.put("original_string", toParse);
- messages.add(toReturn);
- return messages;
-
- } catch (Exception e) {
- e.printStackTrace();
- return null;
- }
-
- }
-
-
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/fireeye/BasicFireEyeParser.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/fireeye/BasicFireEyeParser.java b/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/fireeye/BasicFireEyeParser.java
index 498248a..839b8f9 100644
--- a/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/fireeye/BasicFireEyeParser.java
+++ b/metron-platform/metron-parsers/src/main/java/org/apache/metron/parsers/fireeye/BasicFireEyeParser.java
@@ -185,7 +185,7 @@ public class BasicFireEyeParser extends BasicParser {
if (ip_dst_port != null)
toReturn.put("ip_dst_port", ip_dst_port);
- System.out.println(toReturn);
+// System.out.println(toReturn);
return toReturn;
}
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractConfigTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractConfigTest.java
deleted file mode 100644
index 26ce051..0000000
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractConfigTest.java
+++ /dev/null
@@ -1,300 +0,0 @@
-/**
- * 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;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Map;
-
-import org.apache.commons.configuration.Configuration;
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.PropertiesConfiguration;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.github.fge.jackson.JsonLoader;
-import com.github.fge.jsonschema.core.report.ProcessingReport;
-import com.github.fge.jsonschema.main.JsonSchemaFactory;
-import com.github.fge.jsonschema.main.JsonValidator;
-
-/**
- * <ul>
- * <li>Title: </li>
- * <li>Description: The class <code>AbstractConfigTest</code> is
- * an abstract base class for implementing JUnit tests that need to use
- * config to connect to ZooKeeper and HBase. The <code>setup</code> method will attempt to
- * load a properties from a file, located in src/test/resources,
- * with the same name as the class.</li>
- * <li>Created: Oct 10, 2014</li>
- * </ul>
- * @version $Revision: 1.1 $
- */
-public class AbstractConfigTest extends AbstractTestContext {
- /**
- * The configPath.
- */
- protected String configPath=null;
-
- /**
- * The configName.
- */
- protected String configName=null;
-
- /**
- * The config.
- */
- private Configuration config=null;
-
- /**
- * The settings.
- */
- Map<String, String> settings=null;
-
- /**
- * The schemaJsonString.
- */
- private String schemaJsonString = null;
- /**
- * Any Object for mavenMode
- * @parameter
- * expression="${mode}"
- * default-value="local"
- */
- private Object mode="local";
-
- /**
- * Constructs a new <code>AbstractConfigTest</code> instance.
- * @throws Exception
- */
- public AbstractConfigTest() throws Exception {
- super.setUp();
- }
-
- /**
- * Constructs a new <code>AbstractTestContext</code> instance.
- * @param name the name of the test case.
- */
- public AbstractConfigTest(String name) {
- super(name);
- }
-
- /*
- * (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp(String configName) throws Exception {
- super.setUp();
- this.setConfigPath("src/test/resources/config/"+getClass().getSimpleName()+".config");
- try {
- this.setConfig(new PropertiesConfiguration(this.getConfigPath()));
-
- Map configOptions= SettingsLoader.getConfigOptions((PropertiesConfiguration)this.config, configName+"=");
- this.setSettings(SettingsLoader.getConfigOptions((PropertiesConfiguration)this.config, configName + "."));
- this.getSettings().put(configName, (String) configOptions.get(configName));
- } catch (ConfigurationException e) {
- e.printStackTrace();
- throw new Exception("Config not found !!"+e);
- }
- }
-
- /*
- * (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
-
- }
-
-
- /**
- * validateJsonData
- * @param jsonSchema
- * @param jsonData
- * @return
- * @throws Exception
- */
-
- protected boolean validateJsonData(final String jsonSchema, final String jsonData)
- throws Exception {
-
- final JsonNode d = JsonLoader.fromString(jsonData);
- final JsonNode s = JsonLoader.fromString(jsonSchema);
-
- final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
- JsonValidator v = factory.getValidator();
-
- ProcessingReport report = v.validate(s, d);
- System.out.println(report);
-
- return report.toString().contains("success");
- }
-
- protected String readSchemaFromFile(URL schema_url) throws Exception {
- BufferedReader br = new BufferedReader(new FileReader(
- schema_url.getFile()));
- String line;
- StringBuilder sb = new StringBuilder();
- while ((line = br.readLine()) != null) {
- System.out.println(line);
- sb.append(line);
- }
- br.close();
-
- String schema_string = sb.toString().replaceAll("\n", "");
- schema_string = schema_string.replaceAll(" ", "");
-
- System.out.println("Read in schema: " + schema_string);
-
- return schema_string;
- }
-
- protected String[] readTestDataFromFile(String test_data_url) throws Exception {
- BufferedReader br = new BufferedReader(new FileReader(
- new File(test_data_url)));
- ArrayList<String> inputDataLines = new ArrayList<String>();
-
- String line;
- while ((line = br.readLine()) != null) {
- System.out.println(line);
- inputDataLines.add(line.toString().replaceAll("\n", ""));
- }
- br.close();
- String[] inputData = new String[inputDataLines.size()];
- inputData = inputDataLines.toArray(inputData);
-
- return inputData;
- }
- /**
- * Skip Tests
- */
- @Override
- public boolean skipTests(Object mode){
- if(mode.toString().equals("local")){
- return true;
- }else {
- return false;
- }
- }
-
- /**
- * Returns the mode.
- * @return the mode.
- */
-
- @Override
- public Object getMode() {
- return mode;
- }
-
- /**
- * Sets the mode.
- * @param mode the mode.
- */
-
- @Override
- public void setMode(Object mode) {
-
- this.mode = mode;
- }
-
-
- /**
- * @param schemaJsonString
- */
- public void setSchemaJsonString(String schemaJsonString) {
- this.schemaJsonString=schemaJsonString;
- }
-
-
- /**
- * @return
- */
- public String getSchemaJsonString() {
- return this.schemaJsonString;
- }
-
- /**
- * Returns the configPath.
- * @return the configPath.
- */
- public String getConfigPath() {
- return configPath;
- }
-
- /**
- * Sets the configPath.
- * @param configPath the configPath.
- */
- public void setConfigPath(String configPath) {
- this.configPath = configPath;
- }
- /**
- * Returns the config.
- * @return the config.
- */
-
- public Configuration getConfig() {
- return config;
- }
-
- /**
- * Sets the config.
- * @param config the config.
- */
-
- public void setConfig(Configuration config) {
-
- this.config = config;
- }
- /**
- * Returns the settings.
- * @return the settings.
- */
-
- public Map<String, String> getSettings() {
- return settings;
- }
-
- /**
- * Sets the settings.
- * @param settings the settings.
- */
-
- public void setSettings(Map<String, String> settings) {
- this.settings = settings;
- }
- /**
- * Returns the configName.
- * @return the configName.
- */
- public String getConfigName() {
- return configName;
- }
-
- /**
- * Sets the configName.
- * @param configName the configName.
- */
- public void setConfigName(String configName) {
- this.configName = configName;
- }
-}
-
-
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractParserConfigTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractParserConfigTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractParserConfigTest.java
new file mode 100644
index 0000000..dd43cc3
--- /dev/null
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractParserConfigTest.java
@@ -0,0 +1,92 @@
+/**
+ * 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;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.github.fge.jackson.JsonLoader;
+import com.github.fge.jsonschema.core.exceptions.ProcessingException;
+import com.github.fge.jsonschema.core.report.ProcessingReport;
+import com.github.fge.jsonschema.main.JsonSchemaFactory;
+import com.github.fge.jsonschema.main.JsonValidator;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+
+public class AbstractParserConfigTest {
+
+ protected static BasicParser parser = null;
+ protected static String[] inputStrings;
+ private String schemaJsonString = null;
+
+ protected boolean validateJsonData(final String jsonSchema, final String jsonData)
+ throws IOException, ProcessingException {
+
+ final JsonNode d = JsonLoader.fromString(jsonData);
+ final JsonNode s = JsonLoader.fromString(jsonSchema);
+
+ final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
+ JsonValidator v = factory.getValidator();
+
+ ProcessingReport report = v.validate(s, d);
+
+ return report.toString().contains("success");
+ }
+
+ protected String readSchemaFromFile(URL schema_url) throws Exception {
+ BufferedReader br = new BufferedReader(new FileReader(
+ schema_url.getFile()));
+ String line;
+ StringBuilder sb = new StringBuilder();
+ while ((line = br.readLine()) != null) {
+ sb.append(line);
+ }
+ br.close();
+
+ String schema_string = sb.toString().replaceAll("\n", "");
+ schema_string = schema_string.replaceAll(" ", "");
+
+ return schema_string;
+ }
+
+ protected String[] readTestDataFromFile(String test_data_url) throws Exception {
+ BufferedReader br = new BufferedReader(new FileReader(new File(test_data_url)));
+ ArrayList<String> inputDataLines = new ArrayList<>();
+
+ String line;
+ while ((line = br.readLine()) != null) {
+ inputDataLines.add(line.replaceAll("\n", ""));
+ }
+ br.close();
+ String[] inputData = new String[inputDataLines.size()];
+ inputData = inputDataLines.toArray(inputData);
+
+ return inputData;
+ }
+
+ public void setSchemaJsonString(String schemaJsonString) {
+ this.schemaJsonString = schemaJsonString;
+ }
+
+
+ public String getSchemaJsonString() {
+ return this.schemaJsonString;
+ }
+}
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractSchemaTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractSchemaTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractSchemaTest.java
deleted file mode 100644
index b1cc597..0000000
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractSchemaTest.java
+++ /dev/null
@@ -1,204 +0,0 @@
-/**
- * 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;
-import java.io.BufferedReader;
-import java.io.FileReader;
-import java.net.URL;
-
-import com.fasterxml.jackson.databind.JsonNode;
-import com.github.fge.jackson.JsonLoader;
-import com.github.fge.jsonschema.core.report.ProcessingReport;
-import com.github.fge.jsonschema.main.JsonSchemaFactory;
-import com.github.fge.jsonschema.main.JsonValidator;
-
- /**
- * <ul>
- * <li>Title: </li>
- * <li>Description: The class <code>AbstractSchemaTest</code> is
- * an abstract base class for implementing JUnit tests that need to load a
- * Json Schema. The <code>setup</code> method will attempt to
- * load a properties from a file, located in src/test/resources,
- * with the same name as the class.</li>
- * <li>Created: Aug 7, 2014</li>
- * </ul>
- * @version $Revision: 1.1 $
- */
-public class AbstractSchemaTest extends AbstractConfigTest{
-
-
- /**
- * The schemaJsonString.
- */
- private String schemaJsonString = null;
- /**
- * Any Object for mavenMode
- * @parameter
- * expression="${mode}"
- * default-value="local"
- */
- private Object mode="local";
-
- /**
- * Constructs a new <code>AbstractTestContext</code> instance.
- * @throws Exception
- */
- public AbstractSchemaTest() throws Exception {
- super.setUp();
- }
-
- /**
- * Constructs a new <code>AbstractTestContext</code> instance.
- * @param name the name of the test case.
- */
- public AbstractSchemaTest(String name) {
- super(name);
- try{
- if(System.getProperty("mode")!=null){
- setMode(System.getProperty("mode") );
- }else
- {
- setMode("local");
- }
- }catch(Exception ex){
- setMode("local");
- }
- }
-
- /*
- * (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- protected void setUp() throws Exception {
- super.setUp();
-
- }
-
- /*
- * (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- @Override
- protected void tearDown() throws Exception {
-
- }
-
-
- /**
- * validateJsonData
- * @param jsonSchema
- * @param jsonData
- * @return
- * @throws Exception
- */
-
- @Override
- protected boolean validateJsonData(final String jsonSchema, final String jsonData)
- throws Exception {
-
- final JsonNode d = JsonLoader.fromString(jsonData);
- final JsonNode s = JsonLoader.fromString(jsonSchema);
-
- final JsonSchemaFactory factory = JsonSchemaFactory.byDefault();
- JsonValidator v = factory.getValidator();
-
- ProcessingReport report = v.validate(s, d);
- System.out.println(report);
-
- return report.toString().contains("success");
- }
-
- @Override
- protected String readSchemaFromFile(URL schema_url) throws Exception {
- BufferedReader br = new BufferedReader(new FileReader(
- schema_url.getFile()));
- String line;
- StringBuilder sb = new StringBuilder();
- while ((line = br.readLine()) != null) {
- System.out.println(line);
- sb.append(line);
- }
- br.close();
-
- String schema_string = sb.toString().replaceAll("\n", "");
- schema_string = schema_string.replaceAll(" ", "");
-
- System.out.println("Read in schema: " + schema_string);
-
- return schema_string;
-
- }
-
- /**
- * Skip Tests
- */
- @Override
- public boolean skipTests(Object mode){
- if(mode.toString().equals("local")){
- return true;
- }else {
- return false;
- }
- }
-
- /**
- * Returns the mode.
- * @return the mode.
- */
-
- @Override
- public Object getMode() {
- return mode;
- }
-
- /**
- * Sets the mode.
- * @param mode the mode.
- */
-
- @Override
- public void setMode(Object mode) {
-
- this.mode = mode;
- }
-
-
- /**
-
- * @param schemaJsonString
- */
-
- @Override
- public void setSchemaJsonString(String schemaJsonString) {
- this.schemaJsonString=schemaJsonString;
- }
-
-
- /**
-
- * @return
- */
-
- @Override
- public String getSchemaJsonString() {
- return this.schemaJsonString;
- }
-
-}
-
-
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractTestContext.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractTestContext.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractTestContext.java
deleted file mode 100644
index 134b896..0000000
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/AbstractTestContext.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * 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;
-import org.junit.After;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
- /**
- * <ul>
- * <li>Title: </li>
- * <li>Description: The class <code>AbstractTestContext</code> is
- * an abstract base class for implementing JUnit tests that need to load a
- * test properties. The <code>setup</code> method will attempt to
- * load a properties from a file, located in src/test/resources,
- * with the same name as the class.</li>
- * <li>Created: Aug 7, 2014</li>
- * </ul>
- * @version $Revision: 1.1 $
- */
-public class AbstractTestContext {
- /**
- * The testProps.
- */
- protected File testPropFile=null;
-
- /**
- * The properties loaded for test.
- */
- protected Properties testProperties=new Properties();
-
- /**
- * Any Object for mavenMode
- * @parameter
- * expression="${mode}"
- * default-value="global"
- */
- private Object mode="local";
-
- /**
- * Constructs a new <code>AbstractTestContext</code> instance.
- */
- public AbstractTestContext() {
- super();
- }
-
- /**
- * Constructs a new <code>AbstractTestContext</code> instance.
- * @param name the name of the test case.
- */
- public AbstractTestContext(String name) {
- try{
- if(System.getProperty("mode")!=null){
- setMode(System.getProperty("mode") );
- }else
- {
- setMode("local");
- }
- }catch(Exception ex){
- setMode("local");
- }
- }
-
- /*
- * (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- protected void setUp() throws Exception {
- InputStream input=null;
- File directory = new File("src/test/resources");
- if (!directory.isDirectory()) {
- return;
- }
- File file = new File(directory, getClass().getSimpleName() + ".properties");
- if (!file.canRead()) {
- return;
- }
- setTestPropFile(file);
- try{
- input=new FileInputStream(file);
- testProperties.load(input);
- }catch(IOException ex){
- ex.printStackTrace();
- throw new Exception("failed to load properties");
- }
-
-
- }
-
- /*
- * (non-Javadoc)
- * @see junit.framework.TestCase#tearDown()
- */
- @After
- protected void tearDown() throws Exception {
-
- }
-
- /**
- * Returns the testProperties.
- * @return the testProperties.
- */
-
- public Properties getTestProperties() {
- return testProperties;
- }
-
- /**
- * Sets the testProperties.
- * @param testProperties the testProperties.
- */
-
- public void setTestProperties(Properties testProperties) {
-
- this.testProperties = testProperties;
- }
- /**
- * Returns the testPropFile.
- * @return the testPropFile.
- */
-
- public File getTestPropFile() {
- return testPropFile;
- }
-
- /**
- * Sets the testPropFile.
- * @param testPropFile the testPropFile.
- */
-
- public void setTestPropFile(File testPropFile) {
-
- this.testPropFile = testPropFile;
- }
-
- /**
- * Skip Tests
- */
- public boolean skipTests(Object mode){
- if(mode.toString().equals("local")){
- return true;
- }else {
- return false;
- }
- }
-
- /**
- * Returns the mode.
- * @return the mode.
- */
-
- public Object getMode() {
- return mode;
- }
-
- /**
- * Sets the mode.
- * @param mode the mode.
- */
-
- public void setMode(Object mode) {
-
- this.mode = mode;
- }
-
- protected void assertNotNull() {}
- protected void assertNotNull(Object o) {}
-
- }
-
-
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/GrokParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/GrokParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/GrokParserTest.java
index 9590d34..1a50dea 100644
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/GrokParserTest.java
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/GrokParserTest.java
@@ -19,10 +19,10 @@ package org.apache.metron.parsers;
import com.google.common.collect.MapDifference;
import com.google.common.collect.Maps;
-import junit.framework.Assert;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
+import org.junit.Assert;
import org.junit.Test;
import java.io.IOException;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/MessageParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/MessageParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/MessageParserTest.java
index 1d2af78..9769baa 100644
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/MessageParserTest.java
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/MessageParserTest.java
@@ -18,8 +18,8 @@
package org.apache.metron.parsers;
-import junit.framework.Assert;
import org.apache.metron.parsers.interfaces.MessageParser;
+import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/asa/GrokAsaParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/asa/GrokAsaParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/asa/GrokAsaParserTest.java
deleted file mode 100644
index 9ed0b54..0000000
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/asa/GrokAsaParserTest.java
+++ /dev/null
@@ -1,169 +0,0 @@
-/**
- * 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.asa;
-
-import java.util.Iterator;
-import java.util.Map;
-
-import org.apache.metron.parsers.sourcefire.BasicSourcefireParser;
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-
-import org.apache.metron.parsers.AbstractConfigTest;
-import org.junit.Assert;
-
-
-/**
- * <ul>
- * <li>Title: </li>
- * <li>Description: </li>
- * <li>Created: Feb 17, 2015 by: </li>
- * </ul>
- * @author $Author: $
- * @version $Revision: 1.1 $
- */
-public class GrokAsaParserTest extends AbstractConfigTest{
- /**
- * The grokAsaStrings.
- */
- private static String[] grokAsaStrings=null;
-
- /**
- * The grokAsaParser.
- */
-
- private GrokAsaParser grokAsaParser=null;
-
- /**
- * Constructs a new <code>GrokAsaParserTest</code> instance.
- * @throws Exception
- */
-
- public GrokAsaParserTest() throws Exception {
- super();
-
- }
- /**
- * @throws java.lang.Exception
- */
- public static void setUpBeforeClass() throws Exception {
- }
-
- /**
- * @throws java.lang.Exception
- */
- public static void tearDownAfterClass() throws Exception {
- setGrokAsaStrings(null);
- }
-
- /*
- * (non-Javadoc)
- * @see junit.framework.TestCase#setUp()
- */
- @Override
- public void setUp() throws Exception {
- super.setUp("org.apache.metron.parsers.asa.GrokAsaParserTest");
- setGrokAsaStrings(super.readTestDataFromFile(this.getConfig().getString("logFile")));
- grokAsaParser = new GrokAsaParser();
- }
-
- /**
- *
- *
- * @throws java.lang.Exception
- */
- @Override
- public void tearDown() throws Exception {
- grokAsaParser = null;
- }
-
- /**
- * Test method for {@link BasicSourcefireParser#parse(byte[])}.
- */
- @SuppressWarnings({ "rawtypes" })
- public void testParse() {
-
- for (String grokAsaString : getGrokAsaStrings()) {
- JSONObject parsed = grokAsaParser.parse(grokAsaString.getBytes()).get(0);
- Assert.assertNotNull(parsed);
-
- System.out.println(parsed);
- JSONParser parser = new JSONParser();
-
- Map json=null;
- try {
- json = (Map) parser.parse(parsed.toJSONString());
- } catch (ParseException e) {
- e.printStackTrace();
- }
- //Ensure JSON returned is not null/empty
- Assert.assertNotNull(json);
-
- Iterator iter = json.entrySet().iterator();
-
-
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- Assert.assertNotNull(entry);
-
- String key = (String) entry.getKey();
- Assert.assertNotNull(key);
-
- String value = (String) json.get("CISCO_TAGGED_SYSLOG").toString();
- Assert.assertNotNull(value);
- }
- }
- }
-
- /**
- * Returns GrokAsa Input String
- */
- public static String[] getGrokAsaStrings() {
- return grokAsaStrings;
- }
-
-
- /**
- * Sets GrokAsa Input String
- */
- public static void setGrokAsaStrings(String[] strings) {
- GrokAsaParserTest.grokAsaStrings = strings;
- }
-
- /**
- * Returns the grokAsaParser.
- * @return the grokAsaParser.
- */
-
- public GrokAsaParser getGrokAsaParser() {
- return grokAsaParser;
- }
-
-
- /**
- * Sets the grokAsaParser.
- * @param grokAsaParser the grokAsaParser.
- */
-
- public void setGrokAsaParser(GrokAsaParser grokAsaParser) {
-
- this.grokAsaParser = grokAsaParser;
- }
-
- }
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BasicBroParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BasicBroParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BasicBroParserTest.java
index 7aefe88..7b09746 100644
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BasicBroParserTest.java
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BasicBroParserTest.java
@@ -17,7 +17,6 @@
*/
package org.apache.metron.parsers.bro;
-import junit.framework.TestCase;
import org.apache.commons.lang3.tuple.Pair;
import org.apache.log4j.Level;
import org.apache.metron.test.utils.UnitTestHelper;
@@ -25,32 +24,32 @@ import org.json.simple.JSONArray;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
+import org.junit.AfterClass;
import org.junit.Assert;
import java.util.Map;
+import org.junit.BeforeClass;
+import org.junit.Test;
-public class BasicBroParserTest extends TestCase {
+public class BasicBroParserTest {
+ private BasicBroParser broParser = new BasicBroParser();
+ private JSONParser jsonParser = new JSONParser();
- /**
- * The parser.
- */
- private BasicBroParser broParser = null;
- private JSONParser jsonParser = null;
+ @BeforeClass
+ public static void setup() {
+ UnitTestHelper.setLog4jLevel(BasicBroParser.class, Level.FATAL);
+ }
- /**
- * Constructs a new <code>BasicBroParserTest</code> instance.
- *
- * @throws Exception
- */
- public BasicBroParserTest() throws Exception {
- broParser = new BasicBroParser();
- jsonParser = new JSONParser();
+ @AfterClass
+ public static void teardown() {
+ UnitTestHelper.setLog4jLevel(BasicBroParser.class, Level.ERROR);
}
/**
* This test is included as a gut-check about our formatting expectations using the Java JDK
* https://docs.oracle.com/javase/tutorial/i18n/format/decimalFormat.html
*/
+ @Test
public void testDecimalFormatAssumptions() {
Pair[] pairs = {
Pair.of(12345678d, "12345678.0"),
@@ -63,10 +62,11 @@ public class BasicBroParserTest extends TestCase {
Pair.of(12345678.111111d, "12345678.111111")
};
for (Pair pair : pairs) {
- assertEquals("Format did not match", pair.getRight(), BasicBroParser.DECIMAL_FORMAT.get().format(pair.getLeft()));
+ Assert.assertEquals("Format did not match", pair.getRight(), BasicBroParser.DECIMAL_FORMAT.get().format(pair.getLeft()));
}
}
+ @Test
public void testUnwrappedBroMessage() throws ParseException {
String rawMessage = "{\"timestamp\":1449511228.474,\"uid\":\"CFgSLp4HgsGqXnNjZi\",\"source_ip\":\"104.130.172.191\",\"source_port\":33893,\"dest_ip\":\"69.20.0.164\",\"dest_port\":53,\"proto\":\"udp\",\"trans_id\":3514,\"rcode\":3,\"rcode_name\":\"NXDOMAIN\",\"AA\":false,\"TC\":false,\"RD\":false,\"RA\":false,\"Z\":0,\"rejected\":false,\"sensor\":\"cloudbro\",\"type\":\"dns\"}";
@@ -92,6 +92,7 @@ public class BasicBroParserTest extends TestCase {
}
@SuppressWarnings("rawtypes")
+ @Test
public void testHttpBroMessage() throws ParseException {
String rawMessage = "{\"http\":{\"ts\":1402307733.473,\"uid\":\"CTo78A11g7CYbbOHvj\",\"id.orig_h\":\"192.249.113.37\",\"id.orig_p\":58808,\"id.resp_h\":\"72.163.4.161\",\"id.resp_p\":80,\"trans_depth\":1,\"method\":\"GET\",\"host\":\"www.cisco.com\",\"uri\":\"/\",\"user_agent\":\"curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\",\"request_body_len\":0,\"response_body_len\":25523,\"status_code\":200,\"status_msg\":\"OK\",\"tags\":[],\"resp_fuids\":[\"FJDyMC15lxUn5ngPfd\"],\"resp_mime_types\":[\"text/html\"]}}";
@@ -121,6 +122,7 @@ public class BasicBroParserTest extends TestCase {
* more compactly as 123.0
*/
@SuppressWarnings("rawtypes")
+ @Test
public void testHttpBroMessageWithZeroDecimalTruncation() throws ParseException {
{
String rawMessage = "{\"http\": {\"ts\":1467657279,\"uid\":\"CMYLzP3PKiwZAgBa51\",\"id.orig_h\":\"192.168.138.158\",\"id.orig_p\":49206,\"id.resp_h\":\"95.163.121.204\"," +
@@ -177,6 +179,7 @@ public class BasicBroParserTest extends TestCase {
}
@SuppressWarnings("rawtypes")
+ @Test
public void testHttpDecimalBroMessage() throws ParseException {
String rawMessage = "{\"http\":{\"ts\":1457149494.166991,\"uid\":\"CTo78A11g7CYbbOHvj\",\"id.orig_h\":\"192.249.113.37\",\"id.orig_p\":58808,\"id.resp_h\":\"72.163.4.161\",\"id.resp_p\":80,\"trans_depth\":1,\"method\":\"GET\",\"host\":\"www.cisco.com\",\"uri\":\"/\",\"user_agent\":\"curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\",\"request_body_len\":0,\"response_body_len\":25523,\"status_code\":200,\"status_msg\":\"OK\",\"tags\":[],\"resp_fuids\":[\"FJDyMC15lxUn5ngPfd\"],\"resp_mime_types\":[\"text/html\"]}}";
Map rawMessageMap = (Map) jsonParser.parse(rawMessage);
@@ -201,6 +204,7 @@ public class BasicBroParserTest extends TestCase {
@SuppressWarnings("rawtypes")
+ @Test
public void testDnsBroMessage() throws ParseException {
String rawMessage = "{\"dns\":{\"ts\":1402308259.609,\"uid\":\"CuJT272SKaJSuqO0Ia\",\"id.orig_h\":\"10.122.196.204\",\"id.orig_p\":33976,\"id.resp_h\":\"144.254.71.184\",\"id.resp_p\":53,\"proto\":\"udp\",\"trans_id\":62418,\"query\":\"www.cisco.com\",\"qclass\":1,\"qclass_name\":\"C_INTERNET\",\"qtype\":28,\"qtype_name\":\"AAAA\",\"rcode\":0,\"rcode_name\":\"NOERROR\",\"AA\":true,\"TC\":false,\"RD\":true,\"RA\":true,\"Z\":0,\"answers\":[\"www.cisco.com.akadns.net\",\"origin-www.cisco.com\",\"2001:420:1201:2::a\"],\"TTLs\":[3600.0,289.0,14.0],\"rejected\":false}}";
@@ -223,6 +227,7 @@ public class BasicBroParserTest extends TestCase {
}
@SuppressWarnings("rawtypes")
+ @Test
public void testFilesBroMessage() throws ParseException {
String rawMessage = "{\"files\":{\"analyzers\": [\"X509\",\"MD5\",\"SHA1\"],\"conn_uids\":[\"C4tygJ3qxJBEJEBCeh\"],\"depth\": 0,\"duration\": 0.0,\"fuid\":\"FZEBC33VySG0nHSoO9\",\"is_orig\": false,\"local_orig\": false,\"md5\": \"eba37166385e3ef42464ed9752e99f1b\",\"missing_bytes\": 0,\"overflow_bytes\": 0,\"rx_hosts\": [\"10.220.15.205\"],\"seen_bytes\": 1136,\"sha1\": \"73e42686657aece354fbf685712361658f2f4357\",\"source\": \"SSL\",\"timedout\": false,\"ts\": 1425845251.334,\"tx_hosts\": [\"68.171.237.7\"]}}";
@@ -244,6 +249,7 @@ public class BasicBroParserTest extends TestCase {
}
@SuppressWarnings("rawtypes")
+ @Test
public void testProtocolKeyCleanedUp() throws ParseException {
String rawMessage = "{\"ht*tp\":{\"ts\":1402307733.473,\"uid\":\"CTo78A11g7CYbbOHvj\",\"id.orig_h\":\"192.249.113.37\",\"id.orig_p\":58808,\"id.resp_h\":\"72.163.4.161\",\"id.resp_p\":80,\"trans_depth\":1,\"method\":\"GET\",\"host\":\"www.cisco.com\",\"uri\":\"/\",\"user_agent\":\"curl/7.22.0 (x86_64-pc-linux-gnu) libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3\",\"request_body_len\":0,\"response_body_len\":25523,\"status_code\":200,\"status_msg\":\"OK\",\"tags\":[],\"resp_fuids\":[\"FJDyMC15lxUn5ngPfd\"],\"resp_mime_types\":[\"text/html\"]}}";
@@ -259,23 +265,13 @@ public class BasicBroParserTest extends TestCase {
Assert.assertTrue(broJson.get("original_string").toString().startsWith("HTTP"));
}
- public void testBadMessage() throws ParseException{
- UnitTestHelper.setLog4jLevel(BasicBroParser.class, Level.FATAL);
- try {
- broParser.parse("{ \"foo\" : \"bar\"}".getBytes());
- Assert.fail("Should have marked this as a bad message.");
- }
- catch(IllegalStateException ise) {
-
- }
- //non json
- try {
- broParser.parse("foo bar".getBytes());
- Assert.fail("Should have marked this as a bad message.");
- }
- catch(IllegalStateException ise) {
+ @Test(expected=IllegalStateException.class)
+ public void testBadMessage() throws ParseException {
+ broParser.parse("{ \"foo\" : \"bar\"}".getBytes());
+ }
- }
- UnitTestHelper.setLog4jLevel(BasicBroParser.class, Level.ERROR);
+ @Test(expected=IllegalStateException.class)
+ public void testBadMessageNonJson() {
+ broParser.parse("foo bar".getBytes());
}
}
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BroParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BroParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BroParserTest.java
deleted file mode 100644
index 8d81e14..0000000
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/bro/BroParserTest.java
+++ /dev/null
@@ -1,164 +0,0 @@
-/**
- * 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.bro;
-
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-import org.json.simple.JSONObject;
-import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-
-import org.apache.metron.parsers.AbstractConfigTest;
-import org.junit.Assert;
-
-/**
- * <ul>
- * <li>Title: Test For BroParser</li>
- * <li>Description: </li>
- * <li>Created: July 8, 2014</li>
- * </ul>
- * @version $Revision: 1.0 $
- */
-
- /**
- * <ul>
- * <li>Title: </li>
- * <li>Description: </li>
- * <li>Created: Feb 20, 2015 </li>
- * </ul>
- * @author $Author: $
- * @version $Revision: 1.1 $
- */
-public class BroParserTest extends AbstractConfigTest {
-
-
- /**
- * The inputStrings.
- */
- private static String[] inputStrings;
-
- /**
- * The parser.
- */
- private BasicBroParser parser=null;
-
- /**
- * Constructs a new <code>BroParserTest</code> instance.
- * @throws Exception
- */
- public BroParserTest() throws Exception {
- super();
- }
-
-
- /**
- * @throws java.lang.Exception
- */
- public static void setUpBeforeClass() throws Exception {
- }
-
- /**
- * @throws java.lang.Exception
- */
- public static void tearDownAfterClass() throws Exception {
- }
-
- /**
- * @throws java.lang.Exception
- */
- @Override
- public void setUp() throws Exception {
- super.setUp("org.apache.metron.parsers.bro.BroParserTest");
- setInputStrings(super.readTestDataFromFile(this.getConfig().getString("logFile")));
- parser = new BasicBroParser();
- }
-
- /**
- * @throws ParseException
- * Tests for Parse Method
- * Parses Static json String and checks if any spl chars are present in parsed string.
- */
- @SuppressWarnings({ "unused", "rawtypes" })
- public void testParse() throws ParseException {
-
- for (String inputString : getInputStrings()) {
- JSONObject cleanJson = parser.parse(inputString.getBytes()).get(0);
- Assert.assertNotNull(cleanJson);
- System.out.println(cleanJson);
-
- Pattern p = Pattern.compile("[^\\._a-z0-9 ]",
- Pattern.CASE_INSENSITIVE);
-
- JSONParser parser = new JSONParser();
-
- Map json = (Map) cleanJson;
- Map output = new HashMap();
- Iterator iter = json.entrySet().iterator();
-
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- String key = (String) entry.getKey();
-
- Matcher m = p.matcher(key);
- boolean b = m.find();
- // Test False
- Assert.assertFalse(b);
- }
- }
-
- }
-
- /**
- * Returns Input String
- */
- public static String[] getInputStrings() {
- return inputStrings;
- }
-
- /**
- * Sets SourceFire Input String
- */
- public static void setInputStrings(String[] strings) {
- BroParserTest.inputStrings = strings;
- }
-
- /**
- * Returns the parser.
- * @return the parser.
- */
-
- public BasicBroParser getParser() {
- return parser;
- }
-
-
- /**
- * Sets the parser.
- * @param parser the parser.
- */
-
- public void setParser(BasicBroParser parser) {
-
- this.parser = parser;
- }
-}
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/cef/CEFParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/cef/CEFParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/cef/CEFParserTest.java
index 88509dd..a1fe2e8 100644
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/cef/CEFParserTest.java
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/cef/CEFParserTest.java
@@ -31,6 +31,7 @@ import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import com.fasterxml.jackson.core.JsonProcessingException;
@@ -42,14 +43,12 @@ import com.github.fge.jsonschema.main.JsonSchemaFactory;
import com.github.fge.jsonschema.main.JsonValidator;
import com.google.common.io.Resources;
-import junit.framework.TestCase;
-
-public class CEFParserTest extends TestCase {
+public class CEFParserTest {
private static final Charset UTF_8 = Charset.forName("utf-8");
private CEFParser parser;
- @Override
+ @Before
public void setUp() {
parser = new CEFParser();
parser.init();
@@ -58,48 +57,52 @@ public class CEFParserTest extends TestCase {
@Test
public void testInvalid() {
List<JSONObject> obj = parse("test test test nonsense\n");
- assertEquals(0, obj.size());
+ Assert.assertEquals(0, obj.size());
}
@Test
public void testEscaping() {
for (JSONObject obj : parse(
"Sep 19 08:26:10 host CEF:0|security|threatmanager|1.0|100|detected a \\ in packet|10|src=10.0.0.1 act=blocked a \\ dst=1.1.1.1")) {
- assertEquals("10.0.0.1", obj.get("ip_src_addr"));
- assertEquals("blocked a \\", obj.get("deviceAction"));
- assertEquals("1.1.1.1", obj.get("ip_dst_addr"));
+ Assert.assertEquals("10.0.0.1", obj.get("ip_src_addr"));
+ Assert.assertEquals("blocked a \\", obj.get("deviceAction"));
+ Assert.assertEquals("1.1.1.1", obj.get("ip_dst_addr"));
}
}
+ @Test
public void testBasicHeader() {
for (JSONObject obj : parse(
"CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232")) {
- assertEquals("Security", obj.get("DeviceVendor"));
- assertEquals("threatmanager", obj.get("DeviceProduct"));
- assertEquals("1.0", obj.get("DeviceVersion"));
- assertEquals("100", obj.get("DeviceEvent"));
- assertEquals("worm successfully stopped", obj.get("Name"));
- assertEquals(10, obj.get("Severity"));
+ Assert.assertEquals("Security", obj.get("DeviceVendor"));
+ Assert.assertEquals("threatmanager", obj.get("DeviceProduct"));
+ Assert.assertEquals("1.0", obj.get("DeviceVersion"));
+ Assert.assertEquals("100", obj.get("DeviceEvent"));
+ Assert.assertEquals("worm successfully stopped", obj.get("Name"));
+ Assert.assertEquals(10, obj.get("Severity"));
}
}
+ @Test
public void testBasicExtensions() {
for (JSONObject obj : parse(
"CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232")) {
- assertEquals("10.0.0.1", obj.get("ip_src_addr"));
- assertEquals("2.1.2.2", obj.get("ip_dst_addr"));
- assertEquals(1232, obj.get("ip_src_port"));
+ Assert.assertEquals("10.0.0.1", obj.get("ip_src_addr"));
+ Assert.assertEquals("2.1.2.2", obj.get("ip_dst_addr"));
+ Assert.assertEquals(1232, obj.get("ip_src_port"));
}
}
+ @Test
public void testCustomLabelWithSpace() {
for (JSONObject obj : parse(
"CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232 custom=Text with space customLabel=Label with space")) {
- assertEquals(true, obj.containsKey("Label with space"));
- assertEquals("Text with space", obj.get("Label with space"));
+ Assert.assertEquals(true, obj.containsKey("Label with space"));
+ Assert.assertEquals("Text with space", obj.get("Label with space"));
}
}
+ @Test
public void testTimestampPriority() throws java.text.ParseException {
long correctTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz").parse("2016-05-01T09:29:11.356-0400")
.getTime();
@@ -108,33 +111,34 @@ public class CEFParserTest extends TestCase {
for (JSONObject obj : parse(
"CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 rt=May 1 2016 09:29:11.356 -0400 dst=2.1.2.2 spt=1232")) {
- assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
- assertEquals(correctTime, obj.get("timestamp"));
+ Assert.assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
+ Assert.assertEquals(correctTime, obj.get("timestamp"));
}
for (JSONObject obj : parse(
"2016-06-01T09:29:11.356-04:00 host CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 rt=May 1 2016 09:29:11.356 -0400 dst=2.1.2.2 spt=1232")) {
- assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
- assertEquals(correctTime, obj.get("timestamp"));
+ Assert.assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
+ Assert.assertEquals(correctTime, obj.get("timestamp"));
}
for (JSONObject obj : parse(
"2016-05-01T09:29:11.356-04:00 host CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232")) {
- assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
- assertEquals(correctTime, obj.get("timestamp"));
+ Assert.assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
+ Assert.assertEquals(correctTime, obj.get("timestamp"));
}
for (JSONObject obj : parse(
"CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 dst=2.1.2.2 spt=1232")) {
- assertNotNull(obj.get("timestamp"));
+ Assert.assertNotNull(obj.get("timestamp"));
}
}
+ @Test
public void testRtValueAsEpochTimestamp() throws java.text.ParseException {
long correctTime = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSz").parse("2016-05-01T09:29:11.356-0400")
.getTime();
for (JSONObject obj : parse("CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 rt="
+ String.valueOf(correctTime) + " dst=2.1.2.2 spt=1232")) {
- assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
- assertEquals(correctTime, obj.get("timestamp"));
+ Assert.assertEquals(new Date(correctTime), new Date((long) obj.get("timestamp")));
+ Assert.assertEquals(correctTime, obj.get("timestamp"));
}
}
@@ -142,11 +146,12 @@ public class CEFParserTest extends TestCase {
SimpleDateFormat sdf = new SimpleDateFormat("MMM dd HH:mm:ss.SSS");
for (JSONObject obj : parse("CEF:0|Security|threatmanager|1.0|100|worm successfully stopped|10|src=10.0.0.1 rt="
+ sdf.format(input.getTime()) + " dst=2.1.2.2 spt=1232")) {
- assertEquals(expected.getTimeInMillis(), obj.get("timestamp"));
- assertEquals(expected.getTime(), new Date((long) obj.get("timestamp")));
+ Assert.assertEquals(expected.getTimeInMillis(), obj.get("timestamp"));
+ Assert.assertEquals(expected.getTime(), new Date((long) obj.get("timestamp")));
}
}
+ @Test
public void testMissingYearFromDate() throws java.text.ParseException {
Calendar current = Calendar.getInstance();
Calendar correct = Calendar.getInstance();
@@ -156,6 +161,7 @@ public class CEFParserTest extends TestCase {
runMissingYear(correct, current);
}
+ @Test
public void testFourDayFutureBecomesPast() {
Calendar current = Calendar.getInstance();
Calendar correct = Calendar.getInstance();
@@ -168,17 +174,20 @@ public class CEFParserTest extends TestCase {
runMissingYear(correct, current);
}
+ @Test
public void testCEFParserAdallom() throws Exception {
runTest("adallom", Resources.readLines(Resources.getResource(getClass(), "adallom.cef"), UTF_8),
Resources.toString(Resources.getResource(getClass(), "adallom.schema"), UTF_8));
}
+ @Test
public void testCEFParserCyberArk() throws Exception {
runTest("cyberark", Resources.readLines(Resources.getResource(getClass(), "cyberark.cef"), UTF_8),
Resources.toString(Resources.getResource(getClass(), "cyberark.schema"), UTF_8),
Resources.toString(Resources.getResource(getClass(), "cyberark.json"), UTF_8));
}
+ @Test
public void testCEFParserWAF() throws Exception {
URL waf_url = Resources.getResource(getClass(), "waf.cef");
runTest("waf", Resources.readLines(waf_url, UTF_8),
@@ -199,11 +208,10 @@ public class CEFParserTest extends TestCase {
private void runTest(String name, List<String> lines, String schema, String targetJson) throws Exception {
for (String inputString : lines) {
JSONObject parsed = parse(inputString).get(0);
- assertNotNull(parsed);
- assertNotNull(parsed.get("timestamp"));
- assertTrue((long) parsed.get("timestamp") > 0);
+ Assert.assertNotNull(parsed);
+ Assert.assertNotNull(parsed.get("timestamp"));
+ Assert.assertTrue((long) parsed.get("timestamp") > 0);
- System.out.println(parsed);
JSONParser parser = new JSONParser();
Map<?, ?> json = null;
@@ -249,14 +257,14 @@ public class CEFParserTest extends TestCase {
List<JSONObject> parse = parse(sample);
JSONObject obj = parse.get(0);
- assertEquals("TestVendor", obj.get("DeviceVendor"));
- assertEquals(1423441663000L, obj.get("timestamp"));
- assertEquals("9223372036854775807", obj.get("Test Long"));
- assertEquals(obj.get("Test FP Number"), String.valueOf(1.234F));
- assertEquals("00:00:0c:07:ac:00", obj.get("smac"));
- assertEquals("2001:cdba::3257:9652", obj.get("Test IPv6"));
- assertEquals("test test test chocolate", obj.get("Test String"));
- assertEquals("123.123.123.123", obj.get("destinationTranslatedAddress"));
+ Assert.assertEquals("TestVendor", obj.get("DeviceVendor"));
+ Assert.assertEquals(1423441663000L, obj.get("timestamp"));
+ Assert.assertEquals("9223372036854775807", obj.get("Test Long"));
+ Assert.assertEquals(obj.get("Test FP Number"), String.valueOf(1.234F));
+ Assert.assertEquals("00:00:0c:07:ac:00", obj.get("smac"));
+ Assert.assertEquals("2001:cdba::3257:9652", obj.get("Test IPv6"));
+ Assert.assertEquals("test test test chocolate", obj.get("Test String"));
+ Assert.assertEquals("123.123.123.123", obj.get("destinationTranslatedAddress"));
JsonNode inner = new ObjectMapper().readTree((String) obj.get("JSON payload"));
Assert.assertEquals("chocolate!", inner.get("test_test_test").asText());
@@ -270,14 +278,13 @@ public class CEFParserTest extends TestCase {
JsonValidator v = factory.getValidator();
ProcessingReport report = v.validate(s, d);
- System.out.println(report);
return report.toString().contains("success");
}
private List<JSONObject> parse(String string) {
List<JSONObject> parse = parser.parse(string.getBytes(Charset.forName("utf-8")));
- assertNotNull(parse);
+ Assert.assertNotNull(parse);
return parse;
}
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/fireeye/BasicFireEyeParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/fireeye/BasicFireEyeParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/fireeye/BasicFireEyeParserTest.java
index 0368b5e..69a6dbd 100644
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/fireeye/BasicFireEyeParserTest.java
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/fireeye/BasicFireEyeParserTest.java
@@ -17,147 +17,44 @@
*/
package org.apache.metron.parsers.fireeye;
-
-
-import java.util.Iterator;
import java.util.Map;
-
+import java.util.Map.Entry;
+import org.apache.metron.parsers.AbstractParserConfigTest;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.json.simple.parser.ParseException;
-
-import org.apache.metron.parsers.AbstractConfigTest;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
-/**
- * <ul>
- * <li>Title: Test For SourceFireParser</li>
- * <li>Description: </li>
- * <li>Created: July 8, 2014</li>
- * </ul>
- * @version $Revision: 1.0 $
- */
-public class BasicFireEyeParserTest extends AbstractConfigTest
-{
- /**
- * The inputStrings.
- */
- private static String[] inputStrings;
-
- /**
- * The parser.
- */
- private BasicFireEyeParser parser=null;
-
-
- /**
- * Constructs a new <code>BasicFireEyeParserTest</code> instance.
- * @throws Exception
- */
- public BasicFireEyeParserTest() throws Exception {
- super();
- }
-
+public class BasicFireEyeParserTest extends AbstractParserConfigTest {
- /**
- * @throws java.lang.Exception
- */
- public static void setUpBeforeClass() throws Exception {
- }
+ @Before
+ public void setUp() throws Exception {
+ inputStrings = super.readTestDataFromFile("src/test/resources/logData/FireEyeParserTest.txt");
+ parser = new BasicFireEyeParser();
+ }
- /**
- * @throws java.lang.Exception
- */
- public static void tearDownAfterClass() throws Exception {
- }
+ @SuppressWarnings({"rawtypes"})
+ @Test
+ public void testParse() throws ParseException {
+ for (String inputString : inputStrings) {
+ JSONObject parsed = parser.parse(inputString.getBytes()).get(0);
+ Assert.assertNotNull(parsed);
- /**
- * @throws java.lang.Exception
- */
- @Override
- public void setUp() throws Exception {
- super.setUp("org.apache.metron.parsers.fireeye.BasicFireEyeParserTest");
- setInputStrings(super.readTestDataFromFile(this.getConfig().getString("logFile")));
- parser = new BasicFireEyeParser();
- }
+ JSONParser parser = new JSONParser();
- /**
- *
- *
- * @throws java.lang.Exception
- */
- @Override
- public void tearDown() throws Exception {
- parser = null;
- setInputStrings(null);
- }
+ Map json = (Map) parser.parse(parsed.toJSONString());
- /**
- * Test method for
- *
- *
- *
- *
- *
- * {@link BasicFireEyeParser#parse(byte[])}.
- */
- @SuppressWarnings({ "rawtypes"})
- public void testParse() {
- for (String inputString : getInputStrings()) {
- JSONObject parsed = parser.parse(inputString.getBytes()).get(0);
- Assert.assertNotNull(parsed);
-
- JSONParser parser = new JSONParser();
+ Assert.assertNotNull(json);
+ Assert.assertFalse(json.isEmpty());
- Map json=null;
- try {
- json = (Map) parser.parse(parsed.toJSONString());
- } catch (ParseException e) {
- e.printStackTrace();
- }
- Iterator iter = json.entrySet().iterator();
-
- Assert.assertNotNull(json);
- Assert.assertFalse(json.isEmpty());
-
-
- while (iter.hasNext()) {
- Map.Entry entry = (Map.Entry) iter.next();
- String key = (String) entry.getKey();
- String value = (String) json.get(key).toString();
- Assert.assertNotNull(value);
- }
- }
- }
-
- /**
- * Returns Input String
- */
- public static String[] getInputStrings() {
- return inputStrings;
- }
-
- /**
- * Sets SourceFire Input String
- */
- public static void setInputStrings(String[] strings) {
- BasicFireEyeParserTest.inputStrings = strings;
- }
-
- /**
- * Returns the parser.
- * @return the parser.
- */
- public BasicFireEyeParser getParser() {
- return parser;
+ for (Object o : json.entrySet()) {
+ Entry entry = (Entry) o;
+ String key = (String) entry.getKey();
+ String value = json.get(key).toString();
+ Assert.assertNotNull(value);
+ }
}
-
- /**
- * Sets the parser.
- * @param parser the parser.
- */
- public void setParser(BasicFireEyeParser parser) {
-
- this.parser = parser;
- }
+ }
}
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/integration/ParserIntegrationTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/integration/ParserIntegrationTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/integration/ParserIntegrationTest.java
index fe6475d..b20445e 100644
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/integration/ParserIntegrationTest.java
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/integration/ParserIntegrationTest.java
@@ -18,7 +18,6 @@
package org.apache.metron.parsers.integration;
import com.google.common.base.Function;
-import junit.framework.Assert;
import org.apache.metron.TestConstants;
import org.apache.metron.common.Constants;
import org.apache.metron.enrichment.integration.components.ConfigUploadComponent;
@@ -31,6 +30,7 @@ import org.apache.metron.integration.utils.TestUtils;
import org.apache.metron.parsers.integration.components.ParserTopologyComponent;
import org.apache.metron.test.TestDataType;
import org.apache.metron.test.utils.SampleDataUtils;
+import org.junit.Assert;
import org.junit.Test;
import javax.annotation.Nullable;
http://git-wip-us.apache.org/repos/asf/metron/blob/5b72da7b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/ise/BasicIseParserTest.java
----------------------------------------------------------------------
diff --git a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/ise/BasicIseParserTest.java b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/ise/BasicIseParserTest.java
index c448c70..050a2d2 100644
--- a/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/ise/BasicIseParserTest.java
+++ b/metron-platform/metron-parsers/src/test/java/org/apache/metron/parsers/ise/BasicIseParserTest.java
@@ -17,156 +17,40 @@
*/
package org.apache.metron.parsers.ise;
+import com.github.fge.jsonschema.core.exceptions.ProcessingException;
import java.io.IOException;
import java.net.URL;
import java.util.Map;
-
+import org.apache.metron.parsers.AbstractParserConfigTest;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
-import org.json.simple.parser.ParseException;
-
-import org.apache.metron.parsers.AbstractSchemaTest;
import org.junit.Assert;
-
-
-/**
- * <ul>
- * <li>Title: Basic ISE Parser</li>
- * <li>Description: Junit Test Case for BasicISE Parser</li>
- * <li>Created: AUG 25, 2014</li>
- * </ul>
- *
- * @version $Revision: 1.1 $
- */
-
-public class BasicIseParserTest extends AbstractSchemaTest {
- /**
- * The inputStrings.
- */
- private static String[] inputStrings;
-
- /**
- * The parser.
- */
- private static BasicIseParser parser = null;
-
-
- /**
- * Constructs a new <code>BasicIseParserTest</code> instance.
- *
- * @param name
- */
-
- public BasicIseParserTest(String name) {
- super(name);
- }
-
- /**
- *
- * @throws java.lang.Exception
- */
- protected static void setUpBeforeClass() throws Exception {
- }
-
- /**
- *
- * @throws java.lang.Exception
- */
- protected static void tearDownAfterClass() throws Exception {
- }
-
- /*
- * (non-Javadoc)
- *
- * @see junit.framework.TestCase#setUp()
- */
-
- @Override
- protected void setUp() throws Exception {
- super.setUp("org.apache.metron.parsers.lancope.BasicLancopeParserTest");
- setInputStrings(super.readTestDataFromFile(this.getConfig().getString("logFile")));
- BasicIseParserTest.setIseParser(new BasicIseParser());
-
- URL schema_url = getClass().getClassLoader().getResource(
- "TestSchemas/IseSchema.json");
- super.setSchemaJsonString(super.readSchemaFromFile(schema_url));
- }
-
- /*
- * (non-Javadoc)
- *
- * @see junit.framework.TestCase#tearDown()
- */
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- /**
- * Test method for
- * {@link BasicIseParser#parse(byte[])}.
- *
- * @throws IOException
- * @throws Exception
- */
- public void testParse() throws ParseException, IOException, Exception {
- for (String inputString : getInputStrings()) {
- JSONObject parsed = parser.parse(inputString.getBytes()).get(0);
- assertNotNull(parsed);
-
- System.out.println(parsed);
- JSONParser parser = new JSONParser();
-
- Map<?, ?> json=null;
- try {
- json = (Map<?, ?>) parser.parse(parsed.toJSONString());
- Assert.assertEquals(true, validateJsonData(super.getSchemaJsonString(), json.toString()));
- } catch (ParseException e) {
- e.printStackTrace();
- }
- }
- }
-
- /**
- * Returns the iseParser.
- *
- * @return the iseParser.
- */
-
- public BasicIseParser getIseParser() {
- return parser;
- }
-
- /**
- * Sets the iseParser.
- *
- * @param parser
- */
-
-
- public static void setIseParser(BasicIseParser parser) {
-
- BasicIseParserTest.parser = parser;
- }
- /**
- * Returns the inputStrings.
- * @return the inputStrings.
- */
-
- public static String[] getInputStrings() {
- return inputStrings;
- }
-
- /**
- * Sets the inputStrings.
- * @param inputStrings the inputStrings.
- */
-
- public static void setInputStrings(String[] inputStrings) {
- BasicIseParserTest.inputStrings = inputStrings;
- }
-
-
-
+import org.junit.Before;
+import org.junit.Test;
+
+public class BasicIseParserTest extends AbstractParserConfigTest {
+
+ @Before
+ public void setUp() throws Exception {
+ inputStrings = super.readTestDataFromFile("src/test/resources/logData/IseParserTest.txt");
+ parser = new BasicIseParser();
+
+ URL schema_url = getClass().getClassLoader().getResource(
+ "TestSchemas/IseSchema.json");
+ super.setSchemaJsonString(super.readSchemaFromFile(schema_url));
+ }
+
+ @Test
+ public void testParse()
+ throws org.json.simple.parser.ParseException, IOException, ProcessingException {
+ for (String inputString : inputStrings) {
+ JSONObject parsed = parser.parse(inputString.getBytes()).get(0);
+ Assert.assertNotNull(parsed);
+
+ JSONParser parser = new JSONParser();
+
+ Map<?, ?> json = (Map<?, ?>) parser.parse(parsed.toJSONString());
+ Assert.assertTrue(validateJsonData(getSchemaJsonString(), json.toString()));
+ }
+ }
}