@Test public void testJavaScript() throws IOException, ImporterHandlerException { String script = "metadata.addString('test', 'success');" + "text = content.replace(/Alice/g, 'Roger');" + "/*return*/ text;"; ScriptTransformer t = new ScriptTransformer(); t.setScript(script); File htmlFile = TestUtil.getAliceHtmlFile(); FileInputStream is = new FileInputStream(htmlFile); ByteArrayOutputStream out = new ByteArrayOutputStream(); ImporterMetadata metadata = new ImporterMetadata(); metadata.setString(ImporterMetadata.DOC_CONTENT_TYPE, "text/html"); t.transformDocument(htmlFile.getAbsolutePath(), is, out, metadata, false); is.close(); String successField = metadata.getString("test"); Assert.assertEquals("success", successField); String content = new String(out.toString()); Assert.assertEquals(0, StringUtils.countMatches(content, "Alice")); Assert.assertEquals(34, StringUtils.countMatches(content, "Roger")); }
@Test public void testWriteRead() throws IOException { ScriptTransformer t = new ScriptTransformer(); t.setScript("a script"); t.setEngineName("an engine name"); t.setMaxReadSize(256); System.out.println("Writing/Reading this: " + t); ConfigurationUtil.assertWriteRead(t); }