@Test public void testReadLineWithMimeTypeMismatch() throws Exception { String threeLines = "first\nsecond\nthird"; byte[] in = threeLines.getBytes("UTF-8"); morphline = createMorphline("test-morphlines/readLineWithMimeTypeMismatch"); // uses ignoreFirstLine : true Record record = new Record(); record.put(Fields.ATTACHMENT_BODY, in); processAndVerifyFailure(record); }
@Test public void testTranslateFailure() throws Exception { morphline = createMorphline("test-morphlines/translateFailure"); Record record = new Record(); record.replaceValues("level", 999); processAndVerifyFailure(record); }
@Test /* Fails because Boolean.TRUE is not equals to the String "true" */ public void testEqualsFailure() throws Exception { morphline = createMorphline("test-morphlines/equalsFailure"); Record record = new Record(); record.put("field0", true); processAndVerifyFailure(record); }
@Test public void testConvertTimestampBad() throws Exception { morphline = createMorphline("test-morphlines/convertTimestamp"); Record record = new Record(); record.put("ts1", "this is an invalid timestamp"); processAndVerifyFailure(record); }
@Test public void testContainsFailure() throws Exception { morphline = createMorphline("test-morphlines/contains"); Record record = new Record(); record.put("food", "veggies"); record.put("food", "xxxxxxxxxxxxxx"); processAndVerifyFailure(record); }
@Test public void testIsTrue() throws Exception { System.setProperty("MY_VARIABLE", "true"); morphline = createMorphline("test-morphlines/isTrue"); Record record = new Record(); record.put("isTooYoung", "true"); processAndVerifySuccess(record, record); System.setProperty("MY_VARIABLE", "false"); morphline = createMorphline("test-morphlines/isTrue"); processAndVerifyFailure(createBasicRecord()); System.clearProperty("MY_VARIABLE"); try { morphline = createMorphline("test-morphlines/isTrue"); fail(); } catch (ConfigException.UnresolvedSubstitution e) { ; } }
@Test public void testExtractURIComponents() throws Exception { String uriStr = "http://user-info@www.fool.com:8080/errors.log?foo=x&foo=y&foo=z#fragment"; morphline = createMorphline("test-morphlines/extractURIComponents"); Record record = new Record(); record.put("uri", uriStr); Record expected = new Record(); URI uri = new URI(uriStr); String prefix = "uri_component_"; expected.put("uri", uriStr); expected.put(prefix + "scheme", uri.getScheme()); expected.put(prefix + "authority", uri.getAuthority()); expected.put(prefix + "path", uri.getPath()); expected.put(prefix + "query", uri.getQuery()); expected.put(prefix + "fragment", uri.getFragment()); expected.put(prefix + "host", uri.getHost()); expected.put(prefix + "port", uri.getPort()); expected.put(prefix + "schemeSpecificPart", uri.getSchemeSpecificPart()); expected.put(prefix + "userInfo", uri.getUserInfo()); processAndVerifySuccess(record, expected); record = new Record(); record.put("uri", "invalidURI:"); processAndVerifyFailure(record); }
private void testExtractURIComponent2(String uriStr, String component, Object expectedComponent, boolean success) throws Exception { morphline = createMorphline( "test-morphlines/extractURIComponent", ConfigFactory.parseMap(ImmutableMap.of("component", component))); Record record = new Record(); record.put("uri", uriStr); Record expected = new Record(); expected.put("uri", uriStr); expected.put("output", expectedComponent); if (success) { processAndVerifySuccess(record, expected); } else { processAndVerifyFailure(record); } }