XmlTransformService extends ServiceImp { public void setUrl(String s) { if ("".equals(s)) { throw new IllegalArgumentException("null param"); } url = s; } XmlTransformService(); @Override void doService(AdaptrisMessage msg); @Override void prepare(); String getUrl(); void setUrl(String s); String getMetadataKey(); void setMetadataKey(String s); Boolean getCacheTransforms(); void setCacheTransforms(Boolean b); Boolean getAllowOverride(); void setAllowOverride(Boolean b); String getOutputMessageEncoding(); void setOutputMessageEncoding(String s); XmlTransformerFactory getXmlTransformerFactory(); void setXmlTransformerFactory(XmlTransformerFactory xmlTransformerFactory); XmlTransformParameter getTransformParameter(); void setTransformParameter(XmlTransformParameter param);  }
@Test public void testSetUrl() { try { XmlTransformService service = new XmlTransformService(); service.setUrl(""); fail(); } catch (IllegalArgumentException expected) { } XmlTransformService service = new XmlTransformService(); service.setUrl("url"); assertEquals("url", service.getUrl()); }
@Test public void testXSLTOutput() throws Exception { AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); XmlTransformService service = new XmlTransformService(); service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL)); execute(service, m1); assertEquals("payload " + m1.getContent(), PROPERTIES.getProperty(KEY_XML_TEST_OUTPUT), m1.getContent()); }
@Test public void testXSLT_RecoverableError() throws Exception { AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); String oldName = Thread.currentThread().getName(); Thread.currentThread().setName(getName()); XmlTransformService service = new XmlTransformService(); service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_INVALID_TRANSFORM_URL)); try { execute(service, m1); } catch (ServiceException e) { assertTrue(e.getCause() instanceof TransformerException); } finally { Thread.currentThread().setName(oldName); } }
@Test public void testXSLT_FatalError() throws Exception { AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); XmlTransformService service = new XmlTransformService(); service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_FATAL_TRANSFORM_URL)); try { execute(service, m1); fail("Exception expected but none thrown"); } catch (ServiceException expected) { assertExceptionCause(expected, TransformerException.class, UncheckedXPathException.class); } }
@Test public void testIssue2641_NoOutputMessageEncoding() throws Exception { DefaultMessageFactory factory = new DefaultMessageFactory(); factory.setDefaultCharEncoding("ISO-8859-1"); AdaptrisMessage msg = MessageHelper.createMessage(factory, PROPERTIES.getProperty(KEY_ISSUE2641_INPUT)); Document srcXml = createDocument(msg.getPayload()); XPath srcXpath = new XPath(); String srcValue = srcXpath.selectSingleTextItem(srcXml, ISSUE2641_SRC_XPATH); assertEquals("ISO-8859-1", msg.getContentEncoding()); XmlTransformService service = new XmlTransformService(); service.setUrl(PROPERTIES.getProperty(KEY_ISSUE2641_TRANSFORM_URL)); execute(service, msg); assertEquals("ISO-8859-1", msg.getContentEncoding()); Document destXml = createDocument(msg.getPayload()); XPath destXpath = new XPath(); String destValue = destXpath.selectSingleTextItem(destXml, ISSUE2641_DEST_XPATH); log.debug("testIssue2641:: srcValue = [" + srcValue + "]"); log.debug("testIssue2641:: destValue = [" + destValue + "]"); assertEquals(srcValue, destValue); }