Skip to content

Commit 30f2c6e

Browse files
committed
SWS-544 - Added Client test to airline sample
1 parent f55cea9 commit 30f2c6e

File tree

9 files changed

+154
-39
lines changed

9 files changed

+154
-39
lines changed

parent/pom.xml

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
34
<modelVersion>4.0.0</modelVersion>
45
<groupId>org.springframework.ws</groupId>
56
<artifactId>spring-ws-parent</artifactId>
@@ -174,6 +175,11 @@
174175
<artifactId>spring-ws-security</artifactId>
175176
<version>${project.version}</version>
176177
</dependency>
178+
<dependency>
179+
<groupId>org.springframework.ws</groupId>
180+
<artifactId>spring-ws-test</artifactId>
181+
<version>${project.version}</version>
182+
</dependency>
177183
<!-- Spring dependencies -->
178184
<dependency>
179185
<groupId>org.springframework</groupId>
@@ -536,6 +542,11 @@
536542
</exclusion>
537543
</exclusions>
538544
</dependency>
545+
<dependency>
546+
<groupId>org.springframework.security</groupId>
547+
<artifactId>spring-security-config</artifactId>
548+
<version>3.0.2.RELEASE</version>
549+
</dependency>
539550
<!-- X.509 dependencies -->
540551
<dependency>
541552
<groupId>net.sf.ehcache</groupId>
@@ -677,7 +688,7 @@
677688
<dependency>
678689
<groupId>xmlunit</groupId>
679690
<artifactId>xmlunit</artifactId>
680-
<version>1.1</version>
691+
<version>1.3</version>
681692
<scope>test</scope>
682693
</dependency>
683694
<dependency>

samples/airline/client/spring-ws/pom.xml

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
34
<parent>
45
<artifactId>airline-client</artifactId>
56
<groupId>org.springframework.ws</groupId>
@@ -56,7 +57,7 @@
5657
</configuration>
5758
</plugin>
5859
</plugins>
59-
</build>
60+
</build>
6061
<dependencies>
6162
<dependency>
6263
<groupId>org.apache.xmlbeans</groupId>
@@ -70,6 +71,11 @@
7071
<groupId>org.springframework.ws</groupId>
7172
<artifactId>spring-xml</artifactId>
7273
</dependency>
74+
<dependency>
75+
<groupId>org.springframework.ws</groupId>
76+
<artifactId>spring-ws-test</artifactId>
77+
<scope>test</scope>
78+
</dependency>
7379
<dependency>
7480
<groupId>org.springframework.ws</groupId>
7581
<artifactId>spring-ws-security</artifactId>
@@ -82,5 +88,20 @@
8288
<groupId>org.apache.ws.security</groupId>
8389
<artifactId>wss4j</artifactId>
8490
</dependency>
91+
<dependency>
92+
<groupId>org.springframework</groupId>
93+
<artifactId>spring-test</artifactId>
94+
</dependency>
95+
<dependency>
96+
<groupId>org.springframework.security</groupId>
97+
<artifactId>spring-security-core</artifactId>
98+
<scope>test</scope>
99+
</dependency>
100+
<dependency>
101+
<groupId>log4j</groupId>
102+
<artifactId>log4j</artifactId>
103+
<scope>compile</scope>
104+
</dependency>
105+
85106
</dependencies>
86107
</project>

samples/airline/client/spring-ws/readme.txt

Lines changed: 0 additions & 11 deletions
This file was deleted.

samples/airline/client/spring-ws/src/main/java/org/springframework/ws/samples/airline/client/sws/GetFlights.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2007 the original author or authors.
2+
* Copyright 2005-2010 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ private void writeFlight(Flight flight) {
104104
public static void main(String[] args) {
105105
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
106106
"org/springframework/ws/samples/airline/client/sws/applicationContext.xml");
107-
GetFlights getFlights = (GetFlights) applicationContext.getBean("getFlights", GetFlights.class);
107+
GetFlights getFlights = applicationContext.getBean("getFlights", GetFlights.class);
108108
getFlights.getFlights();
109109
}
110110

samples/airline/client/spring-ws/src/main/resources/org/springframework/ws/samples/airline/client/sws/applicationContext.xml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,11 @@
22
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
33
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
44

5-
<bean id="messagFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
5+
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
66

77
<bean id="abstractClient" abstract="true">
8-
<constructor-arg ref="messagFactory"/>
9-
<property name="destinationProvider">
10-
<bean class="org.springframework.ws.client.support.destination.Wsdl11DestinationProvider">
11-
<property name="wsdl" value="http://localhost:8080/airline-server/airline.wsdl"/>
12-
</bean>
13-
</property>
8+
<constructor-arg ref="messageFactory"/>
9+
<property name="defaultUri" value="http://localhost:8080/airline-server/services"/>
1410
</bean>
1511

1612
<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"/>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
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.samples.airline.client.sws;
18+
19+
import java.util.Collections;
20+
import java.util.Map;
21+
import javax.xml.transform.Source;
22+
23+
import org.springframework.beans.factory.annotation.Autowired;
24+
import org.springframework.test.context.ContextConfiguration;
25+
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
26+
import org.springframework.xml.transform.StringSource;
27+
28+
import org.junit.Before;
29+
import org.junit.Test;
30+
import org.junit.runner.RunWith;
31+
32+
import static org.springframework.ws.mock.client.WebServiceMock.*;
33+
34+
/**
35+
* This test illustrates the use of the client-side testing API, introduced in Spring-WS 2.0.
36+
*
37+
* @author Arjen Poutsma
38+
*/
39+
@RunWith(SpringJUnit4ClassRunner.class)
40+
@ContextConfiguration("applicationContext.xml")
41+
public class GetFlightsTest {
42+
43+
@Autowired
44+
GetFlights getFlights;
45+
46+
private static final String MESSAGES_NS =
47+
"http://www.springframework.org/spring-ws/samples/airline/schemas/messages";
48+
49+
private static final String TYPES_NS = "http://www.springframework.org/spring-ws/samples/airline/schemas/types";
50+
51+
@Before
52+
public void setUpMocks() throws Exception {
53+
mockWebServiceTemplate(getFlights.getWebServiceTemplate());
54+
}
55+
56+
@Test
57+
public void getFlights() throws Exception {
58+
Source getFlightsRequest = new StringSource(
59+
"<GetFlightsRequest xmlns='" + MESSAGES_NS + "'>" + "<from>AMS</from>" + "<to>VCE</to>" +
60+
"<departureDate>2006-01-31</departureDate>" + "</GetFlightsRequest>");
61+
62+
String flightInfo =
63+
"<t:number>KL1653</t:number>" + "<t:departureTime>2006-01-31T10:05:00.000+01:00</t:departureTime>" +
64+
"<t:from><t:code>AMS</t:code><t:name>Schiphol Airport</t:name><t:city>Amsterdam</t:city></t:from>" +
65+
"<t:arrivalTime>2006-01-31T12:25:00.000+01:00</t:arrivalTime>" +
66+
"<t:to><t:code>VCE</t:code><t:name>Marco Polo Airport</t:name><t:city>Venice</t:city></t:to>" +
67+
"<t:serviceClass>economy</t:serviceClass>";
68+
69+
Source getFlightsResponse = new StringSource(
70+
"<m:GetFlightsResponse xmlns:m='" + MESSAGES_NS + "' xmlns:t='" + TYPES_NS + "'>" + "<m:flight>" +
71+
flightInfo + "</m:flight>" + "</m:GetFlightsResponse>");
72+
73+
expect(payload(getFlightsRequest)).andRespond(withPayload(getFlightsResponse));
74+
75+
Source bookFlightResponse = new StringSource(
76+
"<m:BookFlightResponse xmlns:m='" + MESSAGES_NS + "' xmlns:t='" + TYPES_NS + "'>" + "<t:id>4</t:id>" +
77+
"<t:issueDate>2010-07-28</t:issueDate>" +
78+
"<t:passengers><t:passenger><t:first>John</t:first><t:last>Doe</t:last></t:passenger></t:passengers>" +
79+
"<t:flight>" + flightInfo + "</t:flight>" + "</m:BookFlightResponse>");
80+
81+
Map<String, String> namespaces = Collections.singletonMap("m", MESSAGES_NS);
82+
83+
expect(xpath("/m:BookFlightRequest/m:flightNumber", namespaces).exists())
84+
.andExpect(xpath("/m:BookFlightRequest/m:departureTime", namespaces).exists())
85+
.andExpect(xpath("/m:BookFlightRequest/m:passengers", namespaces).exists())
86+
.andRespond(withPayload(bookFlightResponse));
87+
88+
getFlights.getFlights();
89+
90+
}
91+
92+
93+
}

samples/airline/server/pom.xml

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
23
<parent>
34
<artifactId>airline</artifactId>
45
<groupId>org.springframework.ws</groupId>
@@ -73,12 +74,12 @@
7374
<goal>xjc</goal>
7475
</goals>
7576
</execution>
76-
</executions>
77-
<configuration>
78-
<schemaDirectory>src/main/webapp/</schemaDirectory>
79-
<packageName>org.springframework.ws.samples.airline.schema</packageName>
80-
</configuration>
81-
</plugin>
77+
</executions>
78+
<configuration>
79+
<schemaDirectory>src/main/webapp/</schemaDirectory>
80+
<packageName>org.springframework.ws.samples.airline.schema</packageName>
81+
</configuration>
82+
</plugin>
8283
<plugin>
8384
<groupId>org.codehaus.mojo</groupId>
8485
<artifactId>openjpa-maven-plugin</artifactId>
@@ -246,6 +247,10 @@
246247
<groupId>org.springframework.security</groupId>
247248
<artifactId>spring-security-core</artifactId>
248249
</dependency>
250+
<dependency>
251+
<groupId>org.springframework.security</groupId>
252+
<artifactId>spring-security-config</artifactId>
253+
</dependency>
249254
<dependency>
250255
<groupId>org.apache.activemq</groupId>
251256
<artifactId>activemq-core</artifactId>
@@ -265,7 +270,6 @@
265270
<dependency>
266271
<groupId>org.springframework.security</groupId>
267272
<artifactId>spring-security-core</artifactId>
268-
<version>3.0.2.RELEASE</version>
269273
<classifier>tests</classifier>
270274
<scope>test</scope>
271275
</dependency>

samples/airline/server/src/main/resources/org/springframework/ws/samples/airline/security/applicationContext-security.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,18 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:security="http://www.springframework.org/schema/security"
5-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
6-
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
6+
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
77

88
<description>
9-
This application context contains the WS-Security and Sprign Security beans.
9+
This application context contains the WS-Security and Spring Security beans.
1010
</description>
1111

1212
<security:global-method-security secured-annotations="enabled"/>
1313

14-
<security:authentication-provider user-service-ref="securityService"/>
14+
<security:authentication-manager>
15+
<security:authentication-provider user-service-ref="securityService"/>
16+
</security:authentication-manager>
1517

1618
<bean id="securityService"
1719
class="org.springframework.ws.samples.airline.security.SpringFrequentFlyerSecurityService">

samples/airline/server/src/main/webapp/WEB-INF/mvc-servlet.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,17 @@
22
<beans xmlns="http://www.springframework.org/schema/beans"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xmlns:context="http://www.springframework.org/schema/context"
5-
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
5+
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
66
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
77

88
<description>
99
This web application context contains a simple Spring Web MVC web application that shows flights
1010
</description>
1111

12-
<context:annotation-config/>
12+
<context:component-scan base-package="org.springframework.ws.samples.airline.web"/>
1313

1414
<!-- ===================== HANDLERS ===================================== -->
1515

16-
<bean id="flightController" class="org.springframework.ws.samples.airline.web.FlightsController"/>
1716

1817
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
1918
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>

0 commit comments

Comments
 (0)