1   /*
2    * Copyright 2005-2010 the original author or authors.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package org.springframework.ws.server.endpoint;
18  
19  import javax.xml.transform.Source;
20  
21  import org.springframework.ws.MockWebServiceMessage;
22  import org.springframework.ws.MockWebServiceMessageFactory;
23  import org.springframework.ws.context.DefaultMessageContext;
24  import org.springframework.ws.context.MessageContext;
25  import org.springframework.xml.transform.StringSource;
26  
27  import org.junit.Before;
28  import org.junit.Test;
29  
30  import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual;
31  import static org.junit.Assert.assertFalse;
32  import static org.junit.Assert.assertTrue;
33  
34  public abstract class AbstractMessageEndpointTestCase extends AbstractEndpointTestCase {
35  
36      private MessageEndpoint endpoint;
37  
38      @Before
39      public void createEndpoint() throws Exception {
40          endpoint = createResponseEndpoint();
41      }
42  
43      @Test
44      public void testNoResponse() throws Exception {
45          endpoint = createNoResponseEndpoint();
46          StringSource requestSource = new StringSource(REQUEST);
47  
48          MessageContext context =
49                  new DefaultMessageContext(new MockWebServiceMessage(requestSource), new MockWebServiceMessageFactory());
50          endpoint.invoke(context);
51          assertFalse("Response message created", context.hasResponse());
52      }
53  
54      @Test
55      public void testNoRequestPayload() throws Exception {
56          endpoint = createNoRequestPayloadEndpoint();
57  
58          MessageContext context = new DefaultMessageContext(new MockWebServiceMessage((StringBuilder) null),
59                  new MockWebServiceMessageFactory());
60          endpoint.invoke(context);
61          assertFalse("Response message created", context.hasResponse());
62      }
63  
64      @Override
65      protected final void testSource(Source requestSource) throws Exception {
66          MessageContext context =
67                  new DefaultMessageContext(new MockWebServiceMessage(requestSource), new MockWebServiceMessageFactory());
68          endpoint.invoke(context);
69          assertTrue("No response message created", context.hasResponse());
70          assertXMLEqual(RESPONSE, ((MockWebServiceMessage) context.getResponse()).getPayloadAsString());
71      }
72  
73      protected abstract MessageEndpoint createNoResponseEndpoint();
74  
75      protected abstract MessageEndpoint createNoRequestPayloadEndpoint();
76  
77      protected abstract MessageEndpoint createResponseEndpoint();
78  
79  }