void doTest(String filename, Integer expectedInt, Class<?> exceptionClass) throws Exception { rulesMap.put(new ElementSelector("test"), new NOPAction()); rulesMap.put(new ElementSelector("test/badBegin"), new BadBeginAction()); rulesMap.put(new ElementSelector("test/badBegin/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/badEnd"), new BadEndAction()); rulesMap.put(new ElementSelector("test/badEnd/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/hello"), new HelloAction()); rulesMap.put(new ElementSelector("test/isolate"), new NOPAction()); rulesMap.put(new ElementSelector("test/isolate/badEnd"), new BadEndAction()); rulesMap.put(new ElementSelector("test/isolate/badEnd/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/isolate/touch"), new TouchAction()); rulesMap.put(new ElementSelector("test/hello"), new HelloAction()); TrivialConfigurator tc = new TrivialConfigurator(rulesMap); tc.setContext(context); tc.doConfigure(CoreTestConstants.TEST_SRC_PREFIX + "input/joran/skip/" + filename); String str = context.getProperty(HelloAction.PROPERTY_KEY); assertEquals("Hello John Doe.", str); Integer i = (Integer) context.getObject(TouchAction.KEY); if (expectedInt == null) { assertNull(i); } else { assertEquals(expectedInt, i); } // check the existence of an ERROR status List<Status> statusList = sm.getCopyOfStatusList(); Status s0 = statusList.get(0); assertEquals(Status.ERROR, s0.getLevel()); assertTrue(s0.getThrowable().getClass() == exceptionClass); }
@Test public void noClass() throws JoranException { simpleConfigurator.doConfigure(DEFINE_INPUT_DIR + NOCLASS_XML); String inContextFoo = context.getProperty("foo"); assertNull(inContextFoo); checker.assertContainsMatch( Status.ERROR, "Missing class name for property definer. Near \\[define\\] line 1"); }
@Test public void testBadClass() throws JoranException { simpleConfigurator.doConfigure(DEFINE_INPUT_DIR + BADCLASS_XML); // get from context String inContextFoo = context.getProperty("foo"); assertNull(inContextFoo); // check context errors checker.assertContainsMatch(Status.ERROR, "Could not create an PropertyDefiner of type"); }
@Test public void noName() throws JoranException { simpleConfigurator.doConfigure(DEFINE_INPUT_DIR + NONAME_XML); // get from context String inContextFoo = context.getProperty("foo"); assertNull(inContextFoo); // check context errors checker.assertContainsMatch( Status.ERROR, "Missing property name for property definer. Near \\[define\\] line 1"); }