ModuleReader implements ModuleReaderIF { @Override public Map read(InputStream source) throws IOException, SAXException { logger.debug("Start to read in module."); parser = getXMLParser(); ModuleContentHandler handler = new ModuleContentHandler(); handler.register(parser); InputSource inpsrc = new InputSource(); if (encrypted) inpsrc.setByteStream(new EncryptedInputStream(source)); else inpsrc.setByteStream(source); try { parser.parse(inpsrc); } catch (SAXParseException e) { throw new SAXException(e.getLineNumber() + ":" + e.getColumnNumber() + ": " + e.getMessage()); } return handler.getFunctions(); } ModuleReader(boolean encrypted); @Override Map read(InputStream source);  }
@Test public void testPlain() throws IOException, SAXException { String inpFile = TestFileUtils.getTestInputFile(testdataDirectory, "functions", "plainTest.jsm"); ModuleReaderIF modReader = new ModuleReader(false); Map funcs = modReader.read(StreamUtils.getInputStream(inpFile)); Assert.assertTrue("Could not retrieve correct number of functions from plain module file", funcs.size() == 1); Assert.assertTrue("Could not retrieve function 'names' from plain module file", funcs.containsKey("names")); Assert.assertTrue("Object is not instance of FunctionIF.", funcs.get("names") instanceof FunctionIF); }
@Test public void testEncrypted() throws IOException, SAXException { String inpFile = TestFileUtils.getTestInputFile(testdataDirectory, "functions", "encryptedTest.jsm"); ModuleReaderIF modReader = new ModuleReader(true); Map funcs = modReader.read(StreamUtils.getInputStream(inpFile)); Assert.assertTrue("Could not retrieve correct number of functions from encrypted module file", funcs.size() == 1); Assert.assertTrue("Could not retrieve function 'names' from encrypted module file", funcs.containsKey("names")); Assert.assertTrue("Object is not instance of FunctionIF.", funcs.get("names") instanceof FunctionIF); }