SWS-544 - Added Client test to airline sample

This commit is contained in:
Arjen Poutsma
2010-07-28 11:11:36 +00:00
parent f55cea91f9
commit 30f2c6ec3d
9 changed files with 154 additions and 39 deletions

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-parent</artifactId>
@@ -174,6 +175,11 @@
<artifactId>spring-ws-security</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-test</artifactId>
<version>${project.version}</version>
</dependency>
<!-- Spring dependencies -->
<dependency>
<groupId>org.springframework</groupId>
@@ -536,6 +542,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.0.2.RELEASE</version>
</dependency>
<!-- X.509 dependencies -->
<dependency>
<groupId>net.sf.ehcache</groupId>
@@ -677,7 +688,7 @@
<dependency>
<groupId>xmlunit</groupId>
<artifactId>xmlunit</artifactId>
<version>1.1</version>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<parent>
<artifactId>airline-client</artifactId>
<groupId>org.springframework.ws</groupId>
@@ -56,7 +57,7 @@
</configuration>
</plugin>
</plugins>
</build>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
@@ -70,6 +71,11 @@
<groupId>org.springframework.ws</groupId>
<artifactId>spring-xml</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.ws</groupId>
<artifactId>spring-ws-security</artifactId>
@@ -82,5 +88,20 @@
<groupId>org.apache.ws.security</groupId>
<artifactId>wss4j</artifactId>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@@ -1,11 +0,0 @@
SPRING WEB SERVICES
This directory contains a Java client for the Airline Web Service that uses
the Spring-WS WebServiceTemplate in combination with XMLBeans marshalling.
The client can be run from the provided ant file, by calling "ant run".
SAJA Client Sample table of contents
---------------------------------------------------
* src - The source files for the client
* build.xml - Ant build file with a 'build' and a 'run' target

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2007 the original author or authors.
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -104,7 +104,7 @@ public class GetFlights extends WebServiceGatewaySupport {
public static void main(String[] args) {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
"org/springframework/ws/samples/airline/client/sws/applicationContext.xml");
GetFlights getFlights = (GetFlights) applicationContext.getBean("getFlights", GetFlights.class);
GetFlights getFlights = applicationContext.getBean("getFlights", GetFlights.class);
getFlights.getFlights();
}

View File

@@ -2,15 +2,11 @@
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
<bean id="messagFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
<bean id="messageFactory" class="org.springframework.ws.soap.saaj.SaajSoapMessageFactory"/>
<bean id="abstractClient" abstract="true">
<constructor-arg ref="messagFactory"/>
<property name="destinationProvider">
<bean class="org.springframework.ws.client.support.destination.Wsdl11DestinationProvider">
<property name="wsdl" value="http://localhost:8080/airline-server/airline.wsdl"/>
</bean>
</property>
<constructor-arg ref="messageFactory"/>
<property name="defaultUri" value="http://localhost:8080/airline-server/services"/>
</bean>
<bean id="marshaller" class="org.springframework.oxm.xmlbeans.XmlBeansMarshaller"/>

View File

@@ -0,0 +1,93 @@
/*
* Copyright 2005-2010 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.ws.samples.airline.client.sws;
import java.util.Collections;
import java.util.Map;
import javax.xml.transform.Source;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.xml.transform.StringSource;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.springframework.ws.mock.client.WebServiceMock.*;
/**
* This test illustrates the use of the client-side testing API, introduced in Spring-WS 2.0.
*
* @author Arjen Poutsma
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("applicationContext.xml")
public class GetFlightsTest {
@Autowired
GetFlights getFlights;
private static final String MESSAGES_NS =
"http://www.springframework.org/spring-ws/samples/airline/schemas/messages";
private static final String TYPES_NS = "http://www.springframework.org/spring-ws/samples/airline/schemas/types";
@Before
public void setUpMocks() throws Exception {
mockWebServiceTemplate(getFlights.getWebServiceTemplate());
}
@Test
public void getFlights() throws Exception {
Source getFlightsRequest = new StringSource(
"<GetFlightsRequest xmlns='" + MESSAGES_NS + "'>" + "<from>AMS</from>" + "<to>VCE</to>" +
"<departureDate>2006-01-31</departureDate>" + "</GetFlightsRequest>");
String flightInfo =
"<t:number>KL1653</t:number>" + "<t:departureTime>2006-01-31T10:05:00.000+01:00</t:departureTime>" +
"<t:from><t:code>AMS</t:code><t:name>Schiphol Airport</t:name><t:city>Amsterdam</t:city></t:from>" +
"<t:arrivalTime>2006-01-31T12:25:00.000+01:00</t:arrivalTime>" +
"<t:to><t:code>VCE</t:code><t:name>Marco Polo Airport</t:name><t:city>Venice</t:city></t:to>" +
"<t:serviceClass>economy</t:serviceClass>";
Source getFlightsResponse = new StringSource(
"<m:GetFlightsResponse xmlns:m='" + MESSAGES_NS + "' xmlns:t='" + TYPES_NS + "'>" + "<m:flight>" +
flightInfo + "</m:flight>" + "</m:GetFlightsResponse>");
expect(payload(getFlightsRequest)).andRespond(withPayload(getFlightsResponse));
Source bookFlightResponse = new StringSource(
"<m:BookFlightResponse xmlns:m='" + MESSAGES_NS + "' xmlns:t='" + TYPES_NS + "'>" + "<t:id>4</t:id>" +
"<t:issueDate>2010-07-28</t:issueDate>" +
"<t:passengers><t:passenger><t:first>John</t:first><t:last>Doe</t:last></t:passenger></t:passengers>" +
"<t:flight>" + flightInfo + "</t:flight>" + "</m:BookFlightResponse>");
Map<String, String> namespaces = Collections.singletonMap("m", MESSAGES_NS);
expect(xpath("/m:BookFlightRequest/m:flightNumber", namespaces).exists())
.andExpect(xpath("/m:BookFlightRequest/m:departureTime", namespaces).exists())
.andExpect(xpath("/m:BookFlightRequest/m:passengers", namespaces).exists())
.andRespond(withPayload(bookFlightResponse));
getFlights.getFlights();
}
}

View File

@@ -1,4 +1,5 @@
<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">
<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">
<parent>
<artifactId>airline</artifactId>
<groupId>org.springframework.ws</groupId>
@@ -73,12 +74,12 @@
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>src/main/webapp/</schemaDirectory>
<packageName>org.springframework.ws.samples.airline.schema</packageName>
</configuration>
</plugin>
</executions>
<configuration>
<schemaDirectory>src/main/webapp/</schemaDirectory>
<packageName>org.springframework.ws.samples.airline.schema</packageName>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>openjpa-maven-plugin</artifactId>
@@ -246,6 +247,10 @@
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
</dependency>
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-core</artifactId>
@@ -265,7 +270,6 @@
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-core</artifactId>
<version>3.0.2.RELEASE</version>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>

View File

@@ -2,16 +2,18 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-2.0.xsd">
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.0.xsd">
<description>
This application context contains the WS-Security and Sprign Security beans.
This application context contains the WS-Security and Spring Security beans.
</description>
<security:global-method-security secured-annotations="enabled"/>
<security:authentication-provider user-service-ref="securityService"/>
<security:authentication-manager>
<security:authentication-provider user-service-ref="securityService"/>
</security:authentication-manager>
<bean id="securityService"
class="org.springframework.ws.samples.airline.security.SpringFrequentFlyerSecurityService">

View File

@@ -2,18 +2,17 @@
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd">
<description>
This web application context contains a simple Spring Web MVC web application that shows flights
</description>
<context:annotation-config/>
<context:component-scan base-package="org.springframework.ws.samples.airline.web"/>
<!-- ===================== HANDLERS ===================================== -->
<bean id="flightController" class="org.springframework.ws.samples.airline.web.FlightsController"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>