/** Test the putting of values into the SimpleScriptModule� */ public void testPutScriptFilter() throws Exception { ScriptFilter filter = null; final String contentType = "contentType"; final String classNameNotXMLFilter = "com.volantis.xml.pipeline.sax.drivers.web.SimpleScriptModuleTestCase"; final String classNameXMLFilter = "org.xml.sax.helpers.XMLFilterImpl"; // Test the creation with a null content type and class name. try { filter = createScriptFilter(null, null); fail("Null class should not be found"); } catch (NullPointerException e) { // ignore } assertTrue("Content type should not be in the list", !isFilterInContainer(filter)); ScriptFilter result = null; // Test the creation with a null content type a class name. filter = createScriptFilter(null, classNameNotXMLFilter); try { result = module.putScriptFilter(filter); fail("Expected and IllegalArgumentException"); } catch (IllegalArgumentException e) { // ignore } assertTrue("Content type should not be in the list", !isFilterInContainer(filter)); assertNull("XMLFilter result should be null.", result); // Test the creation with a null content type and class name. filter = createScriptFilter(contentType, classNameNotXMLFilter); try { result = module.putScriptFilter(filter); fail("Expected and IllegalArgumentException"); } catch (IllegalArgumentException e) { // ignore } assertTrue("Content type should not be in the list", !isFilterInContainer(filter)); assertNull("XMLFilter result should be null.", result); // Test the creation with a null content type and class name. // The script filter should be put in the hashmap. filter = createScriptFilter(contentType, classNameXMLFilter); result = module.putScriptFilter(filter); assertNull("XMLFilter result should be null.", result); assertTrue("Retrieved result should match", isFilterInContainer(filter)); result = module.putScriptFilter(filter); assertNotNull("XMLFilter result should be null.", result); assertTrue("Retrieved result should match", isFilterInContainer(filter)); String contentType2 = "contentType2"; filter = createScriptFilter(contentType2, classNameXMLFilter); result = module.putScriptFilter(filter); assertNull("Result should not be null.", result); assertTrue("Retrieved result should match", isFilterInContainer(filter)); }
/** Test the putting of values into the SimpleScriptModule. */ public void testSelectScriptFilter() throws Exception { assertNull("Should not be found", module.selectScriptFilter(null)); assertNull("Should not be found", module.selectScriptFilter("not there")); String contentType = "contentType"; ScriptFilter filter = createScriptFilter(contentType, "org.xml.sax.helpers.XMLFilterImpl"); module.putScriptFilter(filter); final XMLFilter xmlFilter = module.selectScriptFilter(contentType); assertNotNull("Should be found", xmlFilter); assertTrue("Value should match", xmlFilter instanceof XMLFilterImpl); }