Updating Airline sample.

This commit is contained in:
Arjen Poutsma
2007-06-14 02:00:51 +00:00
parent e99238f32c
commit 59c3f34970
16 changed files with 0 additions and 891 deletions

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2005 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.dao.hibernate;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.ws.samples.airline.dao.FlightDao;
import org.springframework.ws.samples.airline.domain.Flight;
import org.springframework.ws.samples.airline.domain.ServiceClass;
public class HibernateFlightDao extends HibernateDaoSupport implements FlightDao {
public Flight getFlight(String flightNumber, DateTime departureTime) {
List flights = getHibernateTemplate().findByNamedParam(
"from Flight f where f.number = :number and " + "f.departureTime = :departureTime",
new String[]{"number", "departureTime"}, new Object[]{flightNumber, departureTime});
return !flights.isEmpty() ? (Flight) flights.get(0) : null;
}
public void update(Flight flight) {
getHibernateTemplate().update(flight);
}
public List findFlights(String fromAirportCode, String toAirportCode, Interval interval, ServiceClass serviceClass)
throws DataAccessException {
return getHibernateTemplate().findByNamedParam("from Flight f where f.from.code = :from " +
"and f.to.code = :to and " + "f.departureTime >= :start and f.departureTime <= :end and " +
"f.serviceClass = :class", new String[]{"from", "to", "start", "end", "class"},
new Object[]{fromAirportCode, toAirportCode, interval.getStart(), interval.getEnd(), serviceClass});
}
}

View File

@@ -1,37 +0,0 @@
/*
* Copyright 2006 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.dao.hibernate;
import java.util.List;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.util.CollectionUtils;
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
public class HibernateFrequentFlyerDao extends HibernateDaoSupport implements FrequentFlyerDao {
public FrequentFlyer get(String username) {
List flyers = getHibernateTemplate().find("from FrequentFlyer f where f.username = ?", username);
return !CollectionUtils.isEmpty(flyers) ? (FrequentFlyer) flyers.get(0) : null;
}
public void update(FrequentFlyer frequentFlyer) throws DataAccessException {
getHibernateTemplate().update(frequentFlyer);
}
}

View File

@@ -1,29 +0,0 @@
/*
* Copyright 2006 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.dao.hibernate;
import org.springframework.dao.DataAccessException;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.ws.samples.airline.dao.TicketDao;
import org.springframework.ws.samples.airline.domain.Ticket;
public class HibernateTicketDao extends HibernateDaoSupport implements TicketDao {
public void save(Ticket ticket) throws DataAccessException {
getHibernateTemplate().save(ticket);
}
}

View File

@@ -1,32 +0,0 @@
/*
* Copyright 2005 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.domain;
import java.io.Serializable;
public class Entity implements Serializable {
private Long id;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
}

View File

@@ -1,84 +0,0 @@
/*
* Copyright 2006 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.domain.hibernate;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Types;
import org.hibernate.HibernateException;
import org.hibernate.usertype.UserType;
import org.springframework.ws.samples.airline.domain.ServiceClass;
public class ServiceClassUserType implements UserType {
private static final int[] SQL_TYPES = {Types.VARCHAR};
public boolean isMutable() {
return false;
}
public int[] sqlTypes() {
return SQL_TYPES;
}
public Class returnedClass() {
return ServiceClass.class;
}
public boolean equals(Object x, Object y) {
return x == y;
}
public int hashCode(Object object) throws HibernateException {
return object.hashCode();
}
public Object nullSafeGet(ResultSet resultSet, String[] names, Object owner)
throws HibernateException, SQLException {
String name = resultSet.getString(names[0]);
return resultSet.wasNull() ? null : ServiceClass.getInstance(name);
}
public void nullSafeSet(PreparedStatement statement, Object value, int index)
throws HibernateException, SQLException {
if (value == null) {
statement.setNull(index, Types.VARCHAR);
}
else {
statement.setString(index, value.toString());
}
}
public Object deepCopy(Object value) {
return value;
}
public Serializable disassemble(Object object) throws HibernateException {
return (Serializable) object;
}
public Object assemble(Serializable serializable, Object object) throws HibernateException {
return serializable;
}
public Object replace(Object original, Object target, Object owner) throws HibernateException {
return original;
}
}

View File

@@ -1,49 +0,0 @@
/*
* Copyright 2006 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.security;
import org.acegisecurity.userdetails.UserDetails;
import org.acegisecurity.userdetails.UserDetailsService;
import org.acegisecurity.userdetails.UsernameNotFoundException;
import org.springframework.dao.DataAccessException;
import org.springframework.ws.samples.airline.dao.FrequentFlyerDao;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
/**
* Implementation of the Acegi <code>UserDetailsService</code> for <code>FrequentFlyerDetails</code>.
*
* @author Arjen Poutsma
*/
public class FrequentFlyerDetailsService implements UserDetailsService {
private FrequentFlyerDao frequentFlyerDao;
public void setFrequentFlyerDao(FrequentFlyerDao frequentFlyerDao) {
this.frequentFlyerDao = frequentFlyerDao;
}
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
FrequentFlyer frequentFlyer = frequentFlyerDao.get(username);
if (frequentFlyer != null) {
return new FrequentFlyerDetails(frequentFlyer);
}
else {
throw new UsernameNotFoundException("Frequent flyer '" + username + "' not found");
}
}
}

View File

@@ -1,52 +0,0 @@
/*
* Copyright 2006 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.security;
import org.jdom.Element;
import org.jdom.Namespace;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.ws.samples.airline.service.AirlineService;
import org.springframework.ws.server.endpoint.AbstractJDomPayloadEndpoint;
/**
* Endpoint that returns the amount of frequent flyer miles for the currently logged in user. Secured via a WS-Security
* UsernameToken
*
* @author Arjen Poutsma
*/
public class GetFrequentFlyerMileageEndpoint extends AbstractJDomPayloadEndpoint implements InitializingBean {
private AirlineService airlineService;
private Namespace namespace;
public void setAirlineService(AirlineService airlineService) {
this.airlineService = airlineService;
}
protected Element invokeInternal(Element ignored) throws Exception {
int result = airlineService.getFrequentFlyerMileage();
Element response = new Element("GetFrequentFlyerMileageResponse", namespace);
response.setText(Integer.toString(result));
return response;
}
public void afterPropertiesSet() throws Exception {
namespace = Namespace.getNamespace("tns", "http://www.springframework.org/spring-ws/samples/airline/schemas");
}
}

View File

@@ -1,49 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:util="http://www.springframework.org/schema/util"
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
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
<bean id="abstractDao" abstract="true">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="flightDao" class="org.springframework.ws.samples.airline.dao.hibernate.HibernateFlightDao"
parent="abstractDao"/>
<bean id="ticketDao" class="org.springframework.ws.samples.airline.dao.hibernate.HibernateTicketDao"
parent="abstractDao"/>
<bean id="frequentFlyerDao" class="org.springframework.ws.samples.airline.dao.hibernate.HibernateFrequentFlyerDao"
parent="abstractDao"/>
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingLocations">
<list>
<value>classpath:org/springframework/ws/samples/airline/domain/hibernate/airline.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<util:properties
location="classpath:org/springframework/ws/samples/airline/dao/hibernate/hibernate.properties"/>
</property>
</bean>
<bean id="transactionManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations" value="classpath:org/springframework/ws/samples/airline/dao/jdbc.properties"/>
</bean>
</beans>

View File

@@ -1,5 +0,0 @@
# Properties file with hibernate-related settings.
hibernate.dialect=${hibernate.dialect}
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider

View File

@@ -1,53 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping
package="org.springframework.ws.samples.airline.domain"
auto-import="true" default-lazy="false">
<class name="Passenger" table="PASSENGER">
<id name="id" column="ID">
<generator class="identity"/>
</id>
<property name="firstName" column="FIRST_NAME"/>
<property name="lastName" column="LAST_NAME"/>
<joined-subclass name="FrequentFlyer" table="FREQUENT_FLYER">
<key column="PASSENGER_ID"/>
<property name="miles" column="MILES"/>
<property name="password" column="PASSWORD"/>
<property name="username" column="USERNAME"/>
</joined-subclass>
</class>
<class name="Flight" table="FLIGHT">
<id name="id" column="ID">
<generator class="identity"/>
</id>
<property name="number" column="NUMBER" length="20" unique="true" unique-key="number-departureTime"/>
<property name="departureTime" column="DEPARTURE_TIME" unique="true" unique-key="number-departureTime"
type="org.joda.time.contrib.hibernate.PersistentDateTime"/>
<property name="arrivalTime" column="ARRIVAL_TIME" type="org.joda.time.contrib.hibernate.PersistentDateTime"/>
<property name="seatsAvailable" column="SEATS_AVAILABLE"/>
<property name="miles" column="MILES"/>
<many-to-one name="from" column="FROM_AIRPORT_CODE" class="Airport"/>
<many-to-one name="to" column="TO_AIRPORT_CODE" class="Airport"/>
<property name="serviceClass" column="SERVICE_CLASS"
type="org.springframework.ws.samples.airline.domain.hibernate.ServiceClassUserType"/>
</class>
<class name="Airport" table="AIRPORT">
<id name="code" column="CODE">
<generator class="assigned"/>
</id>
<property name="name" column="NAME"/>
<property name="city" column="CITY"/>
</class>
<class name="Ticket" table="TICKET">
<id name="id" column="ID">
<generator class="identity"/>
</id>
<property name="issueDate" column="ISSUE_DATE" type="org.joda.time.contrib.hibernate.PersistentYearMonthDay"/>
<set name="passengers" table="PASSENGER_TICKET" cascade="save-update">
<key column="TICKET_ID"/>
<many-to-many class="Passenger" column="PASSENGER_ID"/>
</set>
<many-to-one name="flight" column="FLIGHT_ID" class="Flight" cascade="none"/>
</class>
</hibernate-mapping>

View File

@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<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="handlerAdapter" class="org.springframework.ws.transport.http.WebServiceMessageReceiverHandlerAdapter">
<description>
The handlerAdapter makes sure that Spring's DispatcherServlet
supports MessageEndpoints instances as handlers.
</description>
<property name="messageFactory" ref="messageFactory"/>
</bean>
<bean id="wsdlDefinitionHandlerAdapter" class="org.springframework.ws.transport.http.WsdlDefinitionHandlerAdapter">
<description>
This handler adapter adds support for WsdlDefinitions to Spring's DispatcherServlet. It transforms location
attributes in the original WSDL to reflect the URL of the incoming HTTP request.
</description>
<property name="transformLocations" value="true"/>
</bean>
<bean id="handlerMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<description>
All incoming request are mapped to the messageDispatcher defined in applicationContext-ws.xml
</description>
<property name="defaultHandler" ref="messageDispatcher"/>
<property name="mappings">
<props>
<prop key="airline.wsdl">airlineWsdl</prop>
</props>
</property>
</bean>
</beans>

View File

@@ -1,118 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.springframework.org/spring-ws/samples/airline/schemas"
xmlns:tns="http://www.springframework.org/spring-ws/samples/airline/schemas"
elementFormDefault="qualified">
<element name="GetFlightsRequest">
<complexType>
<all>
<element name="from" type="tns:AirportCode"/>
<element name="to" type="tns:AirportCode"/>
<element name="departureDate" type="date"/>
<element name="serviceClass" type="tns:ServiceClass" minOccurs="0"/>
</all>
</complexType>
</element>
<element name="GetFlightsResponse">
<complexType>
<sequence>
<element name="flight" type="tns:Flight" minOccurs="0" maxOccurs="unbounded"/>
</sequence>
</complexType>
</element>
<element name="BookFlightRequest">
<complexType>
<all>
<element name="flightNumber" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="passengers">
<complexType>
<choice maxOccurs="9">
<element name="passenger" type="tns:Name"/>
<element name="username" type="tns:FrequentFlyerUsername"/>
</choice>
</complexType>
</element>
</all>
</complexType>
</element>
<element name="BookFlightResponse" type="tns:Ticket"/>
<element name="GetFrequentFlyerMileageRequest"/>
<element name="GetFrequentFlyerMileageResponse" type="int"/>
<complexType name="Flight">
<sequence>
<element name="number" type="tns:FlightNumber"/>
<element name="departureTime" type="dateTime"/>
<element name="from" type="tns:Airport"/>
<element name="arrivalTime" type="dateTime"/>
<element name="to" type="tns:Airport"/>
<element name="serviceClass" type="tns:ServiceClass"/>
</sequence>
</complexType>
<simpleType name="FlightNumber">
<restriction base="string">
<pattern value="[A-Z][A-Z][0-9][0-9][0-9][0-9]"/>
</restriction>
</simpleType>
<complexType name="Name">
<sequence>
<element name="first" type="string"/>
<element name="last" type="string"/>
</sequence>
</complexType>
<simpleType name="FrequentFlyerUsername">
<restriction base="string"/>
</simpleType>
<complexType name="Airport">
<all>
<element name="code" type="tns:AirportCode"/>
<element name="name" type="string"/>
<element name="city" type="string"/>
</all>
</complexType>
<simpleType name="AirportCode">
<restriction base="string">
<pattern value="[A-Z][A-Z][A-Z]"/>
</restriction>
</simpleType>
<complexType name="Ticket">
<all>
<element name="id" type="long"/>
<element name="issueDate" type="date"/>
<element name="passengers">
<complexType>
<sequence>
<element name="passenger" type="tns:Name" maxOccurs="9"/>
</sequence>
</complexType>
</element>
<element name="flight" type="tns:Flight"/>
</all>
</complexType>
<simpleType name="ServiceClass">
<restriction base="NCName">
<enumeration value="economy"/>
<enumeration value="business"/>
<enumeration value="first"/>
</restriction>
</simpleType>
</schema>

View File

@@ -1,109 +0,0 @@
/*
* Copyright 2006 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.dao.hibernate;
import java.util.List;
import org.joda.time.DateTime;
import org.joda.time.Interval;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import org.springframework.ws.samples.airline.domain.Airport;
import org.springframework.ws.samples.airline.domain.Flight;
import org.springframework.ws.samples.airline.domain.ServiceClass;
public class HibernateFlightDaoTest extends AbstractTransactionalDataSourceSpringContextTests {
private HibernateFlightDao flightDao;
private Airport fromAirport;
private Airport toAirport;
private DateTime departureTime;
private DateTime arrivalTime;
private Interval interval;
protected String[] getConfigLocations() {
return new String[]{
"classpath:org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml"};
}
public void setFlightDao(HibernateFlightDao flightDao) {
this.flightDao = flightDao;
}
protected void onSetUpBeforeTransaction() throws Exception {
departureTime = new DateTime(2006, 1, 31, 10, 5, 0, 0);
arrivalTime = new DateTime(2006, 1, 31, 12, 25, 0, 0);
interval = new Interval(departureTime, arrivalTime);
}
protected void onSetUpInTransaction() throws Exception {
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('RTM', 'Rotterdam Airport', 'Rotterdam')");
fromAirport = new Airport("RTM", "Rotterdam Airport", "Rotterdam");
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('OSL', 'Gardermoen', 'Oslo')");
toAirport = new Airport("OSL", "Gardermoen", "Oslo");
}
public void testGetFlightsInPeriod() throws Exception {
jdbcTemplate
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'business', 90, 10)");
List flights = flightDao.findFlights("RTM", "OSL", interval, ServiceClass.BUSINESS);
assertNotNull("Invalid result", flights);
assertEquals("Invalid amount of flights", 1, flights.size());
}
public void testGetFlightsOutOfPeriod() throws Exception {
jdbcTemplate
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'business', 90, 10)");
DateTime dateTime = new DateTime(2006, 6, 1, 0, 0, 0, 0);
List flights = flightDao.findFlights("RTM", "OSL", new Interval(dateTime, dateTime), ServiceClass.BUSINESS);
assertNotNull("Invalid result", flights);
assertEquals("Invalid amount of flights", 0, flights.size());
}
public void testGetFlightByNumberDepartureTime() throws Exception {
jdbcTemplate
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'business', 90, 10)");
Flight flight = flightDao.getFlight("KL020", departureTime);
assertNotNull("No flight returned", flight);
assertNotNull("Invalid flight id", flight.getId());
assertEquals("Invalid flight number", "KL020", flight.getNumber());
assertEquals("Invalid flight departure time", departureTime, flight.getDepartureTime());
assertEquals("Invalid flight arrival time", arrivalTime, flight.getArrivalTime());
assertEquals("Invalid flight from airport", fromAirport, flight.getFrom());
assertEquals("Invalid flight to airport", toAirport, flight.getTo());
assertEquals("Invalid flight service class", ServiceClass.BUSINESS, flight.getServiceClass());
}
public void testUpdate() throws Exception {
jdbcTemplate
.update("INSERT INTO FLIGHT(NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
"VALUES ('KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'business', 90, 10)");
Flight flight = flightDao.getFlight("KL020", departureTime);
flight.setSeatsAvailable(0);
flightDao.update(flight);
flightDao.getHibernateTemplate().flush();
int count = jdbcTemplate
.queryForInt("SELECT SEATS_AVAILABLE FROM FLIGHT WHERE ID = ?", new Object[]{flight.getId()});
assertEquals("Flight not updated", 0, count);
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright 2006 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.dao.hibernate;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import org.springframework.ws.samples.airline.domain.FrequentFlyer;
public class HibernateFrequentFlyerDaoTest extends AbstractTransactionalDataSourceSpringContextTests {
private HibernateFrequentFlyerDao dao;
protected String[] getConfigLocations() {
return new String[]{
"classpath:org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml"};
}
public void setDao(HibernateFrequentFlyerDao dao) {
this.dao = dao;
}
public void testGetByUsername() throws Exception {
jdbcTemplate
.update("INSERT INTO PASSENGER(ID, FIRST_NAME, LAST_NAME) " + "VALUES (42, 'Arjen', 'Poutsma')");
jdbcTemplate
.update("INSERT INTO FREQUENT_FLYER(PASSENGER_ID, USERNAME, PASSWORD, MILES) " +
"VALUES (42, 'arjen', 'changeme', 0)");
FrequentFlyer flyer = dao.get("arjen");
assertNotNull("No frequent flyer returned", flyer);
assertEquals("Invalid username", "arjen", flyer.getUsername());
assertEquals("Invalid password", "changeme", flyer.getPassword());
assertEquals("Invalid first name", "Arjen", flyer.getFirstName());
assertEquals("Invalid last name", "Poutsma", flyer.getLastName());
}
}

View File

@@ -1,91 +0,0 @@
/*
* Copyright 2006 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.dao.hibernate;
import org.joda.time.DateTime;
import org.joda.time.DateTimeZone;
import org.joda.time.YearMonthDay;
import org.springframework.test.AbstractTransactionalDataSourceSpringContextTests;
import org.springframework.ws.samples.airline.domain.Airport;
import org.springframework.ws.samples.airline.domain.Flight;
import org.springframework.ws.samples.airline.domain.Passenger;
import org.springframework.ws.samples.airline.domain.ServiceClass;
import org.springframework.ws.samples.airline.domain.Ticket;
public class HibernateTicketDaoTest extends AbstractTransactionalDataSourceSpringContextTests {
private HibernateTicketDao dao;
private Flight flight;
private DateTime departureTime;
private DateTime arrivalTime;
private Passenger passenger;
protected String[] getConfigLocations() {
return new String[]{
"classpath:org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml"};
}
public void setDao(HibernateTicketDao dao) {
this.dao = dao;
}
protected void onSetUpBeforeTransaction() throws Exception {
departureTime = new DateTime(2006, 1, 31, 10, 5, 0, 0, DateTimeZone.UTC);
arrivalTime = new DateTime(2006, 1, 31, 12, 25, 0, 0, DateTimeZone.UTC);
}
protected void onSetUpInTransaction() throws Exception {
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('RTM', 'Rotterdam Airport', 'Rotterdam')");
Airport fromAirport = new Airport("RTM", "Rotterdam Airport", "Rotterdam");
jdbcTemplate.update("INSERT INTO AIRPORT(CODE, NAME, CITY) VALUES('OSL', 'Gardermoen', 'Oslo')");
Airport toAirport = new Airport("OSL", "Gardermoen", "Oslo");
jdbcTemplate
.update("INSERT INTO FLIGHT(ID, NUMBER, DEPARTURE_TIME, FROM_AIRPORT_CODE, ARRIVAL_TIME, TO_AIRPORT_CODE, SERVICE_CLASS, SEATS_AVAILABLE, MILES) " +
"VALUES (42, 'KL020','2006-01-31 10:05:00', 'RTM', '2006-01-31 12:25:00', 'OSL', 'business', 90, 10)");
flight = new Flight();
flight.setId(new Long(42));
flight.setNumber("KL1653");
flight.setDepartureTime(departureTime);
flight.setFrom(fromAirport);
flight.setArrivalTime(arrivalTime);
flight.setTo(toAirport);
flight.setServiceClass(ServiceClass.BUSINESS);
flight.setSeatsAvailable(90);
passenger = new Passenger();
passenger.setFirstName("John");
passenger.setLastName("Doe");
}
public void testInsert() throws Exception {
Ticket ticket = new Ticket();
ticket.addPassenger(passenger);
ticket.setFlight(flight);
ticket.setIssueDate(new YearMonthDay());
int startTicketCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM TICKET");
int startPassengerCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM PASSENGER");
dao.save(ticket);
int endTicketCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM TICKET");
int endPassengerCount = jdbcTemplate.queryForInt("SELECT COUNT(0) FROM PASSENGER");
assertEquals("Flight not inserted", 1, endTicketCount - startTicketCount);
assertEquals("Passenger not inserted", 1, endPassengerCount - startPassengerCount);
}
}

View File

@@ -1,53 +0,0 @@
/*
* Copyright 2006 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.security;
import junit.framework.TestCase;
import org.easymock.MockControl;
import org.jdom.Element;
import org.springframework.ws.samples.airline.service.AirlineService;
public class GetFrequentFlyerMileageEndpointTest extends TestCase {
private GetFrequentFlyerMileageEndpoint endpoint;
private MockControl control;
private AirlineService mock;
protected void setUp() throws Exception {
endpoint = new GetFrequentFlyerMileageEndpoint();
control = MockControl.createControl(AirlineService.class);
mock = (AirlineService) control.getMock();
endpoint.setAirlineService(mock);
endpoint.afterPropertiesSet();
}
public void testInvokeInternal() throws Exception {
control.expectAndReturn(mock.getFrequentFlyerMileage(), 42);
control.replay();
Element element = endpoint.invokeInternal(null);
assertNotNull("No element returned", element);
assertEquals("Invalid local name", "GetFrequentFlyerMileageResponse", element.getName());
assertEquals("Invalid namespace", "http://www.springframework.org/spring-ws/samples/airline/schemas",
element.getNamespaceURI());
assertEquals("Invalid result", "42", element.getTextNormalize());
control.verify();
}
}