CommonLogParser extends LogParser { @Override public void setup(Context.OperatorContext context) { this.setLogFileFormat(schema); super.setup(context); super.setClazz(CommonLog.class); }  @Override void setup(Context.OperatorContext context);  }
@Test public void TestEmptyInput() { String tuple = ""; commonLogParser.setup(null); commonLogParser.beginWindow(0); commonLogParser.in.process(tuple.getBytes()); commonLogParser.endWindow(); Assert.assertEquals(0, pojoPort.collectedTuples.size()); Assert.assertEquals(1, error.collectedTuples.size()); }
@Test public void TestNullInput() { commonLogParser.setup(null); commonLogParser.in.process(null); commonLogParser.endWindow(); Assert.assertEquals(0, pojoPort.collectedTuples.size()); Assert.assertEquals(1, error.collectedTuples.size()); }
@Test public void TestValidCommonLogInputCase() throws JSONException, IOException { commonLogParser.setup(null); commonLogParser.beginWindow(0); String log = "125.125.125.125 - dsmith [10/Oct/1999:21:15:05 +0500] \"GET /index.html HTTP/1.0\" 200 1043"; commonLogParser.in.process(log.getBytes()); commonLogParser.endWindow(); Assert.assertEquals(1, pojoPort.collectedTuples.size()); Assert.assertEquals(0, error.collectedTuples.size()); Object obj = pojoPort.collectedTuples.get(0); Assert.assertNotNull(obj); Assert.assertEquals(CommonLog.class, obj.getClass()); CommonLog pojo = (CommonLog)obj; Assert.assertNotNull(obj); Assert.assertEquals("125.125.125.125", pojo.getHost()); Assert.assertEquals("dsmith", pojo.getUsername()); Assert.assertEquals("10/Oct/1999:21:15:05 +0500", pojo.getDatetime()); Assert.assertEquals("GET /index.html HTTP/1.0", pojo.getRequest()); Assert.assertEquals("200", pojo.getStatusCode()); Assert.assertEquals("1043", pojo.getBytes()); }
@Test public void TestInvalidCommonLogInput() { String tuple = "127.0.0.1 - dsmith 10/Oct/1999:21:15:05] \"GET /index.html HTTP/1.0\" 200 1043"; commonLogParser.setup(null); commonLogParser.beginWindow(0); commonLogParser.in.process(tuple.getBytes()); commonLogParser.endWindow(); Assert.assertEquals(0, pojoPort.collectedTuples.size()); Assert.assertEquals(1, error.collectedTuples.size()); }