MultiPayloadXmlTransformService extends XmlTransformService { @Override public void doService(AdaptrisMessage msg) throws ServiceException { if (msg instanceof MultiPayloadAdaptrisMessage) { this.doTransform((MultiPayloadAdaptrisMessage)msg, obtainUrlToUse(msg)); } else { super.doService(msg); } } MultiPayloadXmlTransformService(); @Override void doService(AdaptrisMessage msg); String getSourcePayloadId(); void setSourcePayloadId(String sourcePayloadId); String getOutputPayloadId(); void setOutputPayloadId(String outputPayloadId);  }
@Test public void testOutputWithCache() throws Exception { MultiPayloadAdaptrisMessage m1 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); MultiPayloadAdaptrisMessage m2 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); MultiPayloadXmlTransformService service = createBaseExample(); try { start(service); service.doService(m1); service.doService(m2); assertEquals(PROPERTIES.getProperty(KEY_XML_TEST_OUTPUT), m1.getContent(PAYLOAD_ID_OUTPUT)); assertEquals(PROPERTIES.getProperty(KEY_XML_TEST_OUTPUT), m2.getContent(PAYLOAD_ID_OUTPUT)); } finally { stop(service); } }
@Test public void testOutputWithCacheResetsParameters() throws Exception { MultiPayloadAdaptrisMessage m1 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); m1.addMessageHeader("myKey", "myValue"); MultiPayloadAdaptrisMessage m2 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); MultiPayloadXmlTransformService service = createBaseExample(); service.setCacheTransforms(true); service.setTransformParameter(new StringMetadataParameter(new String[] {"myKey"}, new String[0])); try { start(service); service.doService(m1); assertNotNull(service.getTransforms().get(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL)).getParameter("myKey")); service.doService(m2); assertNull(service.getTransforms().get(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL)).getParameter("myKey")); } finally { stop(service); } }
@Test public void testOutputWithNoCache() throws Exception { MultiPayloadAdaptrisMessage m1 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); MultiPayloadAdaptrisMessage m2 = MessageHelper.createMultiPayloadMessage(PAYLOAD_ID_SOURCE, PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); MultiPayloadXmlTransformService service = createBaseExample(); service.setCacheTransforms(false); try { start(service); service.doService(m1); service.doService(m2); assertEquals(PROPERTIES.getProperty(KEY_XML_TEST_OUTPUT), m1.getContent(PAYLOAD_ID_OUTPUT)); assertEquals(PROPERTIES.getProperty(KEY_XML_TEST_OUTPUT), m2.getContent(PAYLOAD_ID_OUTPUT)); } finally { stop(service); } }
@Test public void testOutputWrongMessageType() throws Exception { AdaptrisMessage m1 = MessageHelper.createMessage(PROPERTIES.getProperty(KEY_XML_TEST_INPUT)); MultiPayloadXmlTransformService service = new MultiPayloadXmlTransformService(); service.setUrl(PROPERTIES.getProperty(KEY_XML_TEST_TRANSFORM_URL)); service.setCacheTransforms(false); try { start(service); service.doService(m1); assertEquals(PROPERTIES.getProperty(KEY_XML_TEST_OUTPUT), m1.getContent()); } finally { stop(service); } }