private void assertMBeanInstanceNotFound(ObjectName objName, MBeanServer mBeanServer) throws IntrospectionException, ReflectionException, AttributeNotFoundException, MBeanException { try { mBeanServer.getMBeanInfo(objName); fail(); } catch (InstanceNotFoundException e) { ; // expected } try { mBeanServer.getAttribute(objName, "Count"); fail(); } catch (InstanceNotFoundException e) { ; // expected } }
@Test public void testExtractURIComponent() throws Exception { String uriStr = "http://user-info@www.fool.com:8080/errors.log?foo=x&foo=y&foo=z#fragment"; URI uri = new URI(uriStr); testExtractURIComponent2(uriStr, "scheme", uri.getScheme()); testExtractURIComponent2(uriStr, "authority", uri.getAuthority()); testExtractURIComponent2(uriStr, "path", uri.getPath()); testExtractURIComponent2(uriStr, "query", uri.getQuery()); testExtractURIComponent2(uriStr, "fragment", uri.getFragment()); testExtractURIComponent2(uriStr, "host", uri.getHost()); testExtractURIComponent2(uriStr, "port", uri.getPort()); testExtractURIComponent2(uriStr, "schemeSpecificPart", uri.getSchemeSpecificPart()); testExtractURIComponent2(uriStr, "userInfo", uri.getUserInfo()); try { testExtractURIComponent2(uriStr, "illegalType", uri.getUserInfo()); fail(); } catch (MorphlineCompilationException e) { ; // expected } testExtractURIComponent2("invalidURI:", "host", uri.getHost(), false); }
@Test public void testCompileWithMissingMorphline() throws Exception { String file = "test-morphlines/compileWithMissingMorphline"; try { new Compiler().compile( new File(RESOURCES_DIR + "/" + file + ".conf"), "morphline1", new MorphlineContext.Builder().build(), null); fail(); } catch (MorphlineCompilationException e) { ; // expected } }
@Test public void testJavaCompilationException() throws Exception { Config config = parse("test-morphlines/javaCompilationException"); try { createMorphline(config); fail(); } catch (MorphlineCompilationException e) { assertTrue(e.getMessage().startsWith("Cannot compile script")); } }
@Test public void testConvertTimestampWithBadTimezone() throws Exception { Config config = parse("test-morphlines/convertTimestampWithBadTimezone"); try { createMorphline(config); fail(); } catch (MorphlineCompilationException e) { assertTrue(e.getMessage().startsWith("Unknown timezone")); } }
@Test public void testCompileWithUnknownMorphlineId() throws Exception { String file = "test-morphlines/pipeWithTwoBasicCommands"; try { new Compiler().compile( new File(RESOURCES_DIR + "/" + file + ".conf"), "morphline2", new MorphlineContext.Builder().build(), null); fail(); } catch (MorphlineCompilationException e) { ; // expected } }
try { tolerance.handleException(new IOException(), new Record()); fail(); } catch (MorphlineRuntimeException e) { try { tolerance.handleException(new IOException(), new Record()); fail(); } catch (MorphlineRuntimeException e) { try { tolerance.handleException(new RuntimeException(), new Record()); fail(); } catch (MorphlineRuntimeException e) { try { tolerance.handleException(new Error(), new Record()); fail(); } catch (Error e) {
@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 testJavaRuntimeException() throws Exception { morphline = createMorphline("test-morphlines/javaRuntimeException"); Record record = new Record(); startSession(); assertEquals(1, collector.getNumStartEvents()); try { morphline.process(record); fail(); } catch (MorphlineRuntimeException e) { assertTrue(e.getMessage().startsWith("Cannot execute script")); } assertEquals(Lists.newArrayList(), collector.getRecords()); }
@Test public void testTryRulesFailTwice() throws Exception { morphline = createMorphline("test-morphlines/tryRulesFailTwice"); Record record = new Record(); record.put("first_name", "Nadja"); List<Record> expectedList = Lists.newArrayList(); startSession(); assertEquals(1, collector.getNumStartEvents()); try { morphline.process(record); fail(); } catch (MorphlineRuntimeException e) { assertTrue(e.getMessage().startsWith("tryRules command found no successful rule for record")); } assertEquals(expectedList, collector.getRecords()); }