Don't like ads? PRO users don't see any ads ;-)
Guest

Soap Envelope Matcher / Creator

By: a guest on Jul 20th, 2012  |  syntax: Diff  |  size: 22.17 KB  |  hits: 24  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. diff -rupN original/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java new/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java
  2. --- original/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java 2010-11-04 15:40:20.774255000 +0300
  3. +++ new/test/src/main/java/org/springframework/ws/test/client/RequestMatchers.java      2012-07-20 20:41:57.790534224 +0400
  4. @@ -27,6 +27,7 @@ import org.springframework.util.Assert;
  5.  import org.springframework.ws.WebServiceMessage;
  6.  import org.springframework.ws.test.support.matcher.PayloadDiffMatcher;
  7.  import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher;
  8. +import org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher;
  9.  import org.springframework.ws.test.support.matcher.SoapHeaderMatcher;
  10.  import org.springframework.xml.transform.ResourceSource;
  11.  
  12. @@ -75,6 +76,32 @@ public abstract class RequestMatchers {
  13.          Assert.notNull(payload, "'payload' must not be null");
  14.          return payload(new ResourceSource(payload));
  15.      }
  16. +    
  17. +    /**
  18. +     * Expects the given {@link javax.xml.transform.Source} XML SOAP envelope.
  19. +     *
  20. +     * @param soapEnvelope the XML SOAP envelope
  21. +     * @return the request matcher
  22. +     * @author Alexander Shutyaev
  23. +     * @since 2.1.1
  24. +     */
  25. +    public static RequestMatcher soapEnvelope(Source soapEnvelope) {
  26. +        Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
  27. +        return new WebServiceMessageMatcherAdapter(new SoapEnvelopeDiffMatcher(soapEnvelope));
  28. +    }
  29. +
  30. +    /**
  31. +     * Expects the given {@link org.springframework.core.io.Resource} XML SOAP envelope.
  32. +     *
  33. +     * @param soapEnvelope the XML SOAP envelope
  34. +     * @return the request matcher
  35. +     * @author Alexander Shutyaev
  36. +     * @since 2.1.1
  37. +     */
  38. +    public static RequestMatcher soapEnvelope(Resource soapEnvelope) throws IOException {
  39. +        Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
  40. +        return soapEnvelope(new ResourceSource(soapEnvelope));
  41. +    }
  42.  
  43.      /**
  44.       * Expects the payload to validate against the given XSD schema(s).
  45. diff -rupN original/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java new/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java
  46. --- original/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java        2010-11-05 14:32:32.463811000 +0300
  47. +++ new/test/src/main/java/org/springframework/ws/test/client/ResponseCreators.java     2012-07-21 00:26:18.462962872 +0400
  48. @@ -27,6 +27,7 @@ import org.springframework.ws.WebService
  49.  import org.springframework.ws.WebServiceMessageFactory;
  50.  import org.springframework.ws.soap.SoapBody;
  51.  import org.springframework.ws.test.support.creator.PayloadMessageCreator;
  52. +import org.springframework.ws.test.support.creator.SoapEnvelopeMessageCreator;
  53.  import org.springframework.ws.test.support.creator.WebServiceMessageCreator;
  54.  import org.springframework.xml.transform.ResourceSource;
  55.  
  56. @@ -63,6 +64,32 @@ public abstract class ResponseCreators {
  57.          Assert.notNull(payload, "'payload' must not be null");
  58.          return withPayload(new ResourceSource(payload));
  59.      }
  60. +    
  61. +    /**
  62. +     * Respond with the given {@link javax.xml.transform.Source} XML as SOAP envelope response.
  63. +     *
  64. +     * @param soapEnvelope the response SOAP envelope
  65. +     * @return the response callback
  66. +     * @author Alexander Shutyaev
  67. +     * @since 2.1.1
  68. +     */
  69. +    public static ResponseCreator withSoapEnvelope(Source soapEnvelope) {
  70. +        Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
  71. +        return new WebServiceMessageCreatorAdapter(new SoapEnvelopeMessageCreator(soapEnvelope));
  72. +    }
  73. +
  74. +    /**
  75. +     * Respond with the given {@link org.springframework.core.io.Resource} XML as SOAP envelope response.
  76. +     *
  77. +     * @param soapEnvelope the response SOAP envelope
  78. +     * @return the response callback
  79. +     * @author Alexander Shutyaev
  80. +     * @since 2.1.1
  81. +     */
  82. +    public static ResponseCreator withSoapEnvelope(Resource soapEnvelope) throws IOException {
  83. +        Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
  84. +        return withSoapEnvelope(new ResourceSource(soapEnvelope));
  85. +    }
  86.  
  87.      /**
  88.       * Respond with an error.
  89. diff -rupN original/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java new/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java
  90. --- original/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java 2010-11-05 13:22:32.460749000 +0300
  91. +++ new/test/src/main/java/org/springframework/ws/test/server/RequestCreators.java      2012-07-21 00:30:03.954972217 +0400
  92. @@ -24,6 +24,7 @@ import org.springframework.util.Assert;
  93.  import org.springframework.ws.WebServiceMessage;
  94.  import org.springframework.ws.WebServiceMessageFactory;
  95.  import org.springframework.ws.test.support.creator.PayloadMessageCreator;
  96. +import org.springframework.ws.test.support.creator.SoapEnvelopeMessageCreator;
  97.  import org.springframework.ws.test.support.creator.WebServiceMessageCreator;
  98.  import org.springframework.xml.transform.ResourceSource;
  99.  
  100. @@ -60,6 +61,32 @@ public abstract class RequestCreators {
  101.          Assert.notNull(payload, "'payload' must not be null");
  102.          return withPayload(new ResourceSource(payload));
  103.      }
  104. +    
  105. +    /**
  106. +     * Create a request with the given {@link Source} XML as SOAP envelope.
  107. +     *
  108. +     * @param soapEnvelope the request SOAP envelope
  109. +     * @return the request creator
  110. +     * @author Alexander Shutyaev
  111. +     * @since 2.1.1
  112. +     */
  113. +    public static RequestCreator withSoapEnvelope(Source soapEnvelope) {
  114. +        Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
  115. +        return new WebServiceMessageCreatorAdapter(new SoapEnvelopeMessageCreator(soapEnvelope));
  116. +    }
  117. +
  118. +    /**
  119. +     * Create a request with the given {@link Resource} XML as SOAP envelope.
  120. +     *
  121. +     * @param soapEnvelope the request SOAP envelope
  122. +     * @return the request creator
  123. +     * @author Alexander Shutyaev
  124. +     * @since 2.1.1
  125. +     */
  126. +    public static RequestCreator withSoapEnvelope(Resource soapEnvelope) throws IOException {
  127. +        Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
  128. +        return withSoapEnvelope(new ResourceSource(soapEnvelope));
  129. +    }
  130.  
  131.      /**
  132.       * Adapts a {@link WebServiceMessageCreator} to the {@link RequestCreator} contract.
  133. diff -rupN original/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java new/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java
  134. --- original/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java        2010-12-10 12:44:28.170784000 +0300
  135. +++ new/test/src/main/java/org/springframework/ws/test/server/ResponseMatchers.java     2012-07-20 20:44:37.806540857 +0400
  136. @@ -29,6 +29,7 @@ import org.springframework.ws.WebService
  137.  import org.springframework.ws.soap.SoapVersion;
  138.  import org.springframework.ws.test.support.matcher.PayloadDiffMatcher;
  139.  import org.springframework.ws.test.support.matcher.SchemaValidatingMatcher;
  140. +import org.springframework.ws.test.support.matcher.SoapEnvelopeDiffMatcher;
  141.  import org.springframework.ws.test.support.matcher.SoapHeaderMatcher;
  142.  import org.springframework.xml.transform.ResourceSource;
  143.  
  144. @@ -45,6 +46,32 @@ public abstract class ResponseMatchers {
  145.  
  146.      private ResponseMatchers() {
  147.      }
  148. +    
  149. +    // SOAP envelope
  150. +    
  151. +    /**
  152. +     * Expects the given {@link Source} XML SOAP envelope.
  153. +     *
  154. +     * @param soapEnvelope the XML SOAP envelope
  155. +     * @return the response matcher
  156. +     * @author Alexander Shutyaev
  157. +     * @since 2.1.1
  158. +     */
  159. +    public static ResponseMatcher soapEnvelope(Source soapEnvelope) {
  160. +        return new WebServiceMessageMatcherAdapter(new SoapEnvelopeDiffMatcher(soapEnvelope));
  161. +    }
  162. +
  163. +    /**
  164. +     * Expects the given {@link Resource} XML SOAP envelope.
  165. +     *
  166. +     * @param soapEnvelope the XML SOAP envelope
  167. +     * @return the response matcher
  168. +     * @author Alexander Shutyaev
  169. +     * @since 2.1.1
  170. +     */
  171. +    public static ResponseMatcher soapEnvelope(Resource soapEnvelope) throws IOException {
  172. +        return soapEnvelope(new ResourceSource(soapEnvelope));
  173. +    }
  174.  
  175.      // Payload
  176.  
  177. diff -rupN original/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java new/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java
  178. --- original/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java     1970-01-01 03:00:00.000000000 +0300
  179. +++ new/test/src/main/java/org/springframework/ws/test/support/creator/SoapEnvelopeMessageCreator.java  2012-07-21 00:22:00.442952168 +0400
  180. @@ -0,0 +1,69 @@
  181. +/*
  182. + * Copyright 2005-2012 the original author or authors.
  183. + *
  184. + * Licensed under the Apache License, Version 2.0 (the "License");
  185. + * you may not use this file except in compliance with the License.
  186. + * You may obtain a copy of the License at
  187. + *
  188. + *      http://www.apache.org/licenses/LICENSE-2.0
  189. + *
  190. + * Unless required by applicable law or agreed to in writing, software
  191. + * distributed under the License is distributed on an "AS IS" BASIS,
  192. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  193. + * See the License for the specific language governing permissions and
  194. + * limitations under the License.
  195. + */
  196. +
  197. +package org.springframework.ws.test.support.creator;
  198. +
  199. +import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
  200. +import static org.springframework.ws.test.support.AssertionErrors.fail;
  201. +
  202. +import java.io.IOException;
  203. +
  204. +import javax.xml.transform.Source;
  205. +import javax.xml.transform.TransformerException;
  206. +import javax.xml.transform.dom.DOMResult;
  207. +
  208. +import org.springframework.util.Assert;
  209. +import org.springframework.ws.WebServiceMessage;
  210. +import org.springframework.ws.soap.SoapMessage;
  211. +import org.springframework.xml.transform.TransformerHelper;
  212. +import org.w3c.dom.Document;
  213. +
  214. +/**
  215. + * Implementation of {@link WebServiceMessageCreator} that creates a request based on a SOAP envelope {@link Source}.
  216. + *
  217. + * @author Alexander Shutyaev
  218. + * @since 2.1.1
  219. + */
  220. +public class SoapEnvelopeMessageCreator extends AbstractMessageCreator {
  221. +      
  222. +       private final Source soapEnvelope;
  223. +
  224. +    private final TransformerHelper transformerHelper = new TransformerHelper();
  225. +      
  226. +       /**
  227. +     * Creates a new instance of the {@code SoapEnvelopeMessageCreator} with the given SOAP envelope source.
  228. +     *
  229. +     * @param soapEnvelope the SOAP envelope source
  230. +     */
  231. +    public SoapEnvelopeMessageCreator(Source soapEnvelope) {
  232. +        Assert.notNull(soapEnvelope, "'soapEnvelope' must not be null");
  233. +        this.soapEnvelope = soapEnvelope;
  234. +    }
  235. +
  236. +       @Override
  237. +       protected void doWithMessage(WebServiceMessage message) throws IOException {
  238. +               assertTrue("Message created with factory is not a SOAP message", message instanceof SoapMessage);
  239. +               try {
  240. +                       DOMResult result = new DOMResult();
  241. +            transformerHelper.transform(soapEnvelope, result);
  242. +            ((SoapMessage)message).setDocument((Document)result.getNode());
  243. +        }
  244. +        catch (TransformerException ex) {
  245. +            fail("Could not transform request SOAP envelope to message: " + ex.getMessage());
  246. +        }             
  247. +       }
  248. +
  249. +}
  250. diff -rupN original/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java new/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java
  251. --- original/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java        1970-01-01 03:00:00.000000000 +0300
  252. +++ new/test/src/main/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcher.java     2012-07-20 23:50:08.378872902 +0400
  253. @@ -0,0 +1,71 @@
  254. +/*
  255. + * Copyright 2005-2012 the original author or authors.
  256. + *
  257. + * Licensed under the Apache License, Version 2.0 (the "License");
  258. + * you may not use this file except in compliance with the License.
  259. + * You may obtain a copy of the License at
  260. + *
  261. + *      http://www.apache.org/licenses/LICENSE-2.0
  262. + *
  263. + * Unless required by applicable law or agreed to in writing, software
  264. + * distributed under the License is distributed on an "AS IS" BASIS,
  265. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  266. + * See the License for the specific language governing permissions and
  267. + * limitations under the License.
  268. + */
  269. +
  270. +package org.springframework.ws.test.support.matcher;
  271. +
  272. +import static org.springframework.ws.test.support.AssertionErrors.assertTrue;
  273. +import static org.springframework.ws.test.support.AssertionErrors.fail;
  274. +
  275. +import java.io.IOException;
  276. +
  277. +import javax.xml.transform.Source;
  278. +import javax.xml.transform.TransformerException;
  279. +import javax.xml.transform.dom.DOMResult;
  280. +
  281. +import org.custommonkey.xmlunit.Diff;
  282. +import org.springframework.util.Assert;
  283. +import org.springframework.ws.soap.SoapMessage;
  284. +import org.springframework.xml.transform.TransformerHelper;
  285. +import org.w3c.dom.Document;
  286. +
  287. +/**
  288. + * Matches {@link Source} SOAP envelopes.
  289. + *
  290. + * @author Alexander Shutyaev
  291. + * @since 2.1.1
  292. + */
  293. +public class SoapEnvelopeDiffMatcher extends AbstractSoapMessageMatcher {
  294. +      
  295. +       private final Source expected;
  296. +
  297. +    private final TransformerHelper transformerHelper = new TransformerHelper();
  298. +
  299. +    public SoapEnvelopeDiffMatcher(Source expected) {
  300. +        Assert.notNull(expected, "'expected' must not be null");
  301. +        this.expected = expected;
  302. +    }
  303. +    
  304. +    @Override
  305. +    protected void match(SoapMessage soapMessage) throws IOException, AssertionError {
  306. +       Document actualDocument = soapMessage.getDocument();
  307. +        Document expectedDocument = createDocumentFromSource(expected);
  308. +       Diff diff = new Diff(expectedDocument, actualDocument);
  309. +        assertTrue("Envelopes are different, " + diff.toString(), diff.similar());
  310. +    }
  311. +
  312. +       private Document createDocumentFromSource(Source source) {
  313. +        try {
  314. +            DOMResult result = new DOMResult();
  315. +            transformerHelper.transform(source, result);
  316. +            return (Document) result.getNode();
  317. +        }
  318. +        catch (TransformerException ex) {
  319. +            fail("Could not transform source to DOMResult" + ex.getMessage());
  320. +            return null;
  321. +        }
  322. +    }
  323. +
  324. +}
  325. diff -rupN original/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java new/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java
  326. --- original/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java    2010-11-05 14:32:32.463811000 +0300
  327. +++ new/test/src/test/java/org/springframework/ws/test/client/ResponseCreatorsTest.java 2012-07-21 00:37:46.774991403 +0400
  328. @@ -16,12 +16,21 @@
  329.  
  330.  package org.springframework.ws.test.client;
  331.  
  332. +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
  333. +import static org.junit.Assert.assertEquals;
  334. +import static org.junit.Assert.assertSame;
  335. +import static org.junit.Assert.assertTrue;
  336. +
  337.  import java.io.IOException;
  338.  import java.util.Locale;
  339. +
  340.  import javax.xml.namespace.QName;
  341.  import javax.xml.transform.Result;
  342.  import javax.xml.transform.TransformerException;
  343. +import javax.xml.transform.dom.DOMSource;
  344.  
  345. +import org.junit.Before;
  346. +import org.junit.Test;
  347.  import org.springframework.core.io.ByteArrayResource;
  348.  import org.springframework.ws.WebServiceMessage;
  349.  import org.springframework.ws.soap.SoapMessage;
  350. @@ -32,12 +41,6 @@ import org.springframework.xml.transform
  351.  import org.springframework.xml.transform.StringSource;
  352.  import org.springframework.xml.transform.TransformerHelper;
  353.  
  354. -import org.junit.Before;
  355. -import org.junit.Test;
  356. -
  357. -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
  358. -import static org.junit.Assert.*;
  359. -
  360.  public class ResponseCreatorsTest {
  361.  
  362.      private final TransformerHelper transformerHelper = new TransformerHelper();
  363. @@ -71,6 +74,34 @@ public class ResponseCreatorsTest {
  364.  
  365.          assertXMLEqual(payload, getPayloadAsString(response));
  366.      }
  367. +    
  368. +    @Test
  369. +    public void withSoapEnvelopeSource() throws Exception {
  370. +       StringBuilder xmlBuilder = new StringBuilder();
  371. +               xmlBuilder.append("<?xml version='1.0'?>");
  372. +               xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
  373. +               xmlBuilder.append("<soap:Header><header xmlns='http://springframework.org'/></soap:Header>");
  374. +               xmlBuilder.append("<soap:Body><payload xmlns='http://springframework.org'/></soap:Body>");
  375. +               xmlBuilder.append("</soap:Envelope>");
  376. +               String envelope = xmlBuilder.toString();
  377. +               ResponseCreator responseCreator = ResponseCreators.withSoapEnvelope(new StringSource(envelope));
  378. +        WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
  379. +        assertXMLEqual(envelope, getSoapEnvelopeAsString((SoapMessage)response));
  380. +    }
  381. +    
  382. +    @Test
  383. +    public void withSoapEnvelopeResource() throws Exception {
  384. +       StringBuilder xmlBuilder = new StringBuilder();
  385. +               xmlBuilder.append("<?xml version='1.0'?>");
  386. +               xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
  387. +               xmlBuilder.append("<soap:Header><header xmlns='http://springframework.org'/></soap:Header>");
  388. +               xmlBuilder.append("<soap:Body><payload xmlns='http://springframework.org'/></soap:Body>");
  389. +               xmlBuilder.append("</soap:Envelope>");
  390. +               String envelope = xmlBuilder.toString();
  391. +               ResponseCreator responseCreator = ResponseCreators.withSoapEnvelope(new ByteArrayResource(envelope.getBytes("UTF-8")));
  392. +        WebServiceMessage response = responseCreator.createResponse(null, null, messageFactory);
  393. +        assertXMLEqual(envelope, getSoapEnvelopeAsString((SoapMessage)response));
  394. +    }
  395.  
  396.      @Test
  397.      public void withIOException() throws Exception {
  398. @@ -145,4 +176,11 @@ public class ResponseCreatorsTest {
  399.          transformerHelper.transform(message.getPayloadSource(), result);
  400.          return result.toString();
  401.      }
  402. +    
  403. +    private String getSoapEnvelopeAsString(SoapMessage message) throws TransformerException {
  404. +       DOMSource source = new DOMSource(message.getDocument());
  405. +        Result result = new StringResult();
  406. +        transformerHelper.transform(source, result);
  407. +        return result.toString();
  408. +    }
  409.  }
  410. diff -rupN original/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java new/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java
  411. --- original/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java    1970-01-01 03:00:00.000000000 +0300
  412. +++ new/test/src/test/java/org/springframework/ws/test/support/matcher/SoapEnvelopeDiffMatcherTest.java 2012-07-20 23:57:29.578891192 +0400
  413. @@ -0,0 +1,78 @@
  414. +/*
  415. + * Copyright 2005-2012 the original author or authors.
  416. + *
  417. + * Licensed under the Apache License, Version 2.0 (the "License");
  418. + * you may not use this file except in compliance with the License.
  419. + * You may obtain a copy of the License at
  420. + *
  421. + *      http://www.apache.org/licenses/LICENSE-2.0
  422. + *
  423. + * Unless required by applicable law or agreed to in writing, software
  424. + * distributed under the License is distributed on an "AS IS" BASIS,
  425. + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  426. + * See the License for the specific language governing permissions and
  427. + * limitations under the License.
  428. + */
  429. +
  430. +package org.springframework.ws.test.support.matcher;
  431. +
  432. +import static org.easymock.EasyMock.createMock;
  433. +import static org.easymock.EasyMock.expect;
  434. +import static org.easymock.EasyMock.replay;
  435. +import static org.easymock.EasyMock.verify;
  436. +
  437. +import javax.xml.transform.dom.DOMResult;
  438. +
  439. +import org.junit.Test;
  440. +import org.springframework.ws.soap.SoapMessage;
  441. +import org.springframework.xml.transform.StringSource;
  442. +import org.springframework.xml.transform.TransformerHelper;
  443. +import org.w3c.dom.Document;
  444. +
  445. +public class SoapEnvelopeDiffMatcherTest {
  446. +      
  447. +       @Test
  448. +    public void match() throws Exception {
  449. +               StringBuilder xmlBuilder = new StringBuilder();
  450. +               xmlBuilder.append("<?xml version='1.0'?>");
  451. +               xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
  452. +               xmlBuilder.append("<soap:Header><header xmlns='http://example.com'/></soap:Header>");
  453. +               xmlBuilder.append("<soap:Body><payload xmlns='http://example.com'/></soap:Body>");
  454. +               xmlBuilder.append("</soap:Envelope>");
  455. +               String xml = xmlBuilder.toString();
  456. +               DOMResult result = new DOMResult();
  457. +               TransformerHelper transformerHelper = new TransformerHelper();
  458. +               transformerHelper.transform(new StringSource(xml), result);
  459. +        SoapMessage message = createMock(SoapMessage.class);
  460. +        expect(message.getDocument()).andReturn((Document)result.getNode()).once();
  461. +        replay(message);
  462. +
  463. +        SoapEnvelopeDiffMatcher matcher = new SoapEnvelopeDiffMatcher(new StringSource(xml));
  464. +        matcher.match(message);
  465. +
  466. +        verify(message);
  467. +    }
  468. +      
  469. +       @Test(expected = AssertionError.class)
  470. +    public void nonMatch() throws Exception {
  471. +               StringBuilder xmlBuilder = new StringBuilder();
  472. +               xmlBuilder.append("<?xml version='1.0'?>");
  473. +               xmlBuilder.append("<soap:Envelope xmlns:soap='http://www.w3.org/2003/05/soap-envelope'>");
  474. +               xmlBuilder.append("<soap:Header><header xmlns='http://example.com'/></soap:Header>");
  475. +               xmlBuilder.append("<soap:Body><payload%s xmlns='http://example.com'/></soap:Body>");
  476. +               xmlBuilder.append("</soap:Envelope>");
  477. +               String xml = xmlBuilder.toString();
  478. +               String actual = String.format(xml, "1");
  479. +               DOMResult result = new DOMResult();
  480. +               TransformerHelper transformerHelper = new TransformerHelper();
  481. +               transformerHelper.transform(new StringSource(actual), result);
  482. +        SoapMessage message = createMock(SoapMessage.class);
  483. +        expect(message.getDocument()).andReturn((Document)result.getNode()).once();
  484. +        replay(message);
  485. +
  486. +        String expected = String.format(xml, "2");
  487. +        SoapEnvelopeDiffMatcher matcher = new SoapEnvelopeDiffMatcher(new StringSource(expected));
  488. +        matcher.match(message);
  489. +    }
  490. +      
  491. +}