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.test.client;
18  
19  import java.io.IOException;
20  
21  import org.springframework.xml.transform.StringSource;
22  
23  import org.junit.Test;
24  
25  import static org.junit.Assert.*;
26  import static org.springframework.ws.test.client.ResponseCreators.withError;
27  import static org.springframework.ws.test.client.ResponseCreators.withPayload;
28  
29  public class MockSenderConnectionTest {
30  
31      @Test
32      public void error() throws IOException {
33          String testErrorMessage = "Test Error Message";
34          MockSenderConnection connection = new MockSenderConnection();
35          connection.andRespond(withError(testErrorMessage));
36          assertTrue(connection.hasError());
37          assertEquals(testErrorMessage, connection.getErrorMessage());
38      }
39  
40      @Test
41      public void normal() throws IOException {
42          MockSenderConnection connection = new MockSenderConnection();
43          connection.andRespond(withPayload(new StringSource("<response/>")));
44          assertFalse(connection.hasError());
45          assertNull(connection.getErrorMessage());
46      }
47  
48      @Test(expected = AssertionError.class)
49      public void noRequestMatchers() throws IOException {
50          MockSenderConnection connection = new MockSenderConnection();
51          connection.andRespond(withPayload(new StringSource("<response/>")));
52          connection.send(null);
53      }
54  }