So you want to contribute a parser to Apache Metron. First off, on behalf of the community, thank you very much! Now that you have implemented a parser by writing a java class which implements org.apache.metron.parsers.interfaces.MessageParser what are the testing expectations for a new parser?
It is expected that a new parser have two tests:
The JUnit Test should be focused on testing your Parser directly. You should feel free to use mocks or stubs or whatever else you need to completely test that unit of functionality.
Integration tests are more structured. The intent is that the parser that you have implemented can be driven successfully from org.apache.metron.parsers.bolt.ParserBolt.
The procedure for creating a new test is as follows:
The way these tests function is by creating a ParserBolt instance with your specified global configuration and sensor configuration. It will then send your specified sample input data in line-by-line. It will then perform some basic sanity validation:
Validations are functions which indicate how one should validate the parsed messages. The basic one which is sufficient for most cases is org.apache.metron.parsers.integration.validation.SampleDataValidation. This will read the expected results from metron-integration-test/src/main/sample/data/${sensor_type}/parsed and validate that the actual parsed message conforms (excluding timestamp).
If you have special validations required, you may implement your own and return an instance of that in the getValidations() method of your Integration Test.
A sample integration test for the snort parser is as follows:
public class SnortIntegrationTest extends ParserIntegrationTest { @Override String getSensorType() { return "snort"; } @Override List<ParserValidation> getValidations() { return new ArrayList<ParserValidation>() {{ add(new SampleDataValidation()); }}; } }