This commit is contained in:
@@ -12,9 +12,6 @@
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>hsqldb</id>
|
||||
<activation>
|
||||
<activeByDefault>true</activeByDefault>
|
||||
</activation>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>hsqldb</groupId>
|
||||
@@ -30,6 +27,7 @@
|
||||
<jdbc.password></jdbc.password>
|
||||
<jdbc.url>jdbc:hsqldb:hsql://localhost/airline</jdbc.url>
|
||||
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
|
||||
<hibernate.hbm2ddl.auto></hibernate.hbm2ddl.auto>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -73,6 +71,7 @@
|
||||
<jdbc.password>airline</jdbc.password>
|
||||
<jdbc.url>jdbc:mysql://localhost/airline</jdbc.url>
|
||||
<hibernate.dialect>org.hibernate.dialect.MySQLInnoDBDialect</hibernate.dialect>
|
||||
<hibernate.hbm2ddl.auto></hibernate.hbm2ddl.auto>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -110,12 +109,13 @@
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<!-- Change these properties to reflect your PostgreSQL connection settings -->
|
||||
<!-- Change these properties to reflect your PostgreSQL connection settings -->
|
||||
<jdbc.driverClassName>org.postgresql.Driver</jdbc.driverClassName>
|
||||
<jdbc.username>airline</jdbc.username>
|
||||
<jdbc.password>airline</jdbc.password>
|
||||
<jdbc.url>jdbc:postgresql://localhost/airline</jdbc.url>
|
||||
<hibernate.dialect>org.hibernate.dialect.PostgreSQLDialect</hibernate.dialect>
|
||||
<hibernate.hbm2ddl.auto></hibernate.hbm2ddl.auto>
|
||||
</properties>
|
||||
<build>
|
||||
<plugins>
|
||||
@@ -144,6 +144,16 @@
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
<properties>
|
||||
<!-- These properties are overriden by the profiles defined above.
|
||||
The following values are for using an in-memory database, which is used for testing -->
|
||||
<jdbc.driverClassName>org.hsqldb.jdbcDriver</jdbc.driverClassName>
|
||||
<jdbc.username>sa</jdbc.username>
|
||||
<jdbc.password></jdbc.password>
|
||||
<jdbc.url>jdbc:hsqldb:mem:airline</jdbc.url>
|
||||
<hibernate.dialect>org.hibernate.dialect.HSQLDialect</hibernate.dialect>
|
||||
<hibernate.hbm2ddl.auto>create-drop</hibernate.hbm2ddl.auto>
|
||||
</properties>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
@@ -313,4 +323,4 @@
|
||||
<version>0.8</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -19,8 +19,8 @@ To execute the sample with the supplied HSQLDB:
|
||||
|
||||
1. Start a command shell in the subdirectory hsqldb, and run "ant". This starts a HSQLDB server with a database named
|
||||
airline.
|
||||
2. Run "mvn sql:execute" to create the schema and insert data into the database.
|
||||
3. Run "mvn jetty:run" to run the sample in the Jetty6 Web container.
|
||||
2. Run "mvn -P hsqldb sql:execute" to create the schema and insert data into the database.
|
||||
3. Run "mvn -P hsqldb jetty:run" to run the sample in the Jetty6 Web container.
|
||||
|
||||
To execute the sample with MySQL or PostgreSQL:
|
||||
|
||||
|
||||
@@ -18,18 +18,15 @@ package org.springframework.ws.samples.airline.dao;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
|
||||
import org.joda.time.Interval;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.ws.samples.airline.domain.Flight;
|
||||
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||
|
||||
public interface FlightDao {
|
||||
|
||||
List findFlights(String fromAirportCode,
|
||||
String toAirportCode,
|
||||
DateTime startOfPeriod,
|
||||
DateTime endOfPeriod,
|
||||
ServiceClass serviceClass) throws DataAccessException;
|
||||
List findFlights(String fromAirportCode, String toAirportCode, Interval interval, ServiceClass serviceClass)
|
||||
throws DataAccessException;
|
||||
|
||||
Flight getFlight(String flightNumber, DateTime departureTime);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ 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;
|
||||
@@ -38,15 +38,12 @@ public class HibernateFlightDao extends HibernateDaoSupport implements FlightDao
|
||||
getHibernateTemplate().update(flight);
|
||||
}
|
||||
|
||||
public List findFlights(String fromAirportCode,
|
||||
String toAirportCode,
|
||||
DateTime startOfPeriod,
|
||||
DateTime endOfPeriod,
|
||||
ServiceClass serviceClass) throws DataAccessException {
|
||||
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, startOfPeriod, endOfPeriod, serviceClass});
|
||||
new Object[]{fromAirportCode, toAirportCode, interval.getStart(), interval.getEnd(), serviceClass});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,8 +18,7 @@ package org.springframework.ws.samples.airline.service;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.YearMonthDay;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.ws.samples.airline.domain.ServiceClass;
|
||||
import org.springframework.ws.samples.airline.domain.Ticket;
|
||||
|
||||
@@ -40,10 +39,7 @@ public interface AirlineService {
|
||||
* @return a list of flights
|
||||
* @see org.springframework.ws.samples.airline.domain.Flight
|
||||
*/
|
||||
List getFlights(String fromAirportCode,
|
||||
String toAirportCode,
|
||||
YearMonthDay departureDate,
|
||||
ServiceClass serviceClass);
|
||||
List getFlights(String fromAirportCode, String toAirportCode, LocalDate departureDate, ServiceClass serviceClass);
|
||||
|
||||
/**
|
||||
* Books a single flight for a number of passengers. Passengers can be either specified by name or by frequent flyer
|
||||
|
||||
@@ -21,6 +21,7 @@ import java.util.List;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.YearMonthDay;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.ws.samples.airline.dao.FlightDao;
|
||||
@@ -107,7 +108,7 @@ public class AirlineServiceImpl implements AirlineService {
|
||||
|
||||
public List getFlights(String fromAirportCode,
|
||||
String toAirportCode,
|
||||
YearMonthDay departureDate,
|
||||
LocalDate departureDate,
|
||||
ServiceClass serviceClass) {
|
||||
if (serviceClass == null) {
|
||||
serviceClass = ServiceClass.ECONOMY;
|
||||
@@ -116,8 +117,6 @@ public class AirlineServiceImpl implements AirlineService {
|
||||
logger.debug(
|
||||
"Getting flights from '" + fromAirportCode + "' to '" + toAirportCode + "' on " + departureDate);
|
||||
}
|
||||
DateTime startOfPeriod = departureDate.toDateTimeAtMidnight();
|
||||
DateTime endOfPeriod = startOfPeriod.plusDays(1);
|
||||
return flightDao.findFlights(fromAirportCode, toAirportCode, startOfPeriod, endOfPeriod, serviceClass);
|
||||
return flightDao.findFlights(fromAirportCode, toAirportCode, departureDate.toInterval(), serviceClass);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,7 +18,9 @@ package org.springframework.ws.samples.airline.ws;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.joda.time.YearMonthDay;
|
||||
import org.joda.time.Chronology;
|
||||
import org.joda.time.DateTimeZone;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.chrono.ISOChronology;
|
||||
import org.springframework.ws.samples.airline.schema.Airport;
|
||||
import org.springframework.ws.samples.airline.schema.Flight;
|
||||
@@ -48,7 +50,10 @@ public class GetFlightsEndpoint extends AbstractMarshallingPayloadEndpoint {
|
||||
|
||||
protected Object invokeInternal(Object requestObject) throws Exception {
|
||||
GetFlightsRequest request = (GetFlightsRequest) requestObject;
|
||||
YearMonthDay departureDate = new YearMonthDay(request.getDepartureDate(), ISOChronology.getInstance());
|
||||
|
||||
DateTimeZone dateTimeZone = DateTimeZone.forTimeZone(request.getDepartureDate().getTimeZone());
|
||||
Chronology chronology = ISOChronology.getInstance(dateTimeZone);
|
||||
LocalDate departureDate = new LocalDate(request.getDepartureDate(), chronology);
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Request for flights from '" + request.getFrom() + "' to '" + request.getTo() + "' on " +
|
||||
departureDate);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
# Properties file with hibernate-related settings.
|
||||
|
||||
hibernate.dialect=${hibernate.dialect}
|
||||
hibernate.hbm2ddl.auto=${hibernate.hbm2ddl.auto}
|
||||
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
|
||||
#hibernate.hbm2ddl.auto=create-drop
|
||||
#hibernate.show_sql=true
|
||||
|
||||
@@ -18,6 +18,7 @@ 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;
|
||||
@@ -35,6 +36,8 @@ public class HibernateFlightDaoTest extends AbstractTransactionalDataSourceSprin
|
||||
|
||||
private DateTime arrivalTime;
|
||||
|
||||
private Interval interval;
|
||||
|
||||
protected String[] getConfigLocations() {
|
||||
return new String[]{
|
||||
"classpath:org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml"};
|
||||
@@ -47,6 +50,7 @@ public class HibernateFlightDaoTest extends AbstractTransactionalDataSourceSprin
|
||||
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 {
|
||||
@@ -60,7 +64,7 @@ public class HibernateFlightDaoTest extends AbstractTransactionalDataSourceSprin
|
||||
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", departureTime, arrivalTime, ServiceClass.BUSINESS);
|
||||
List flights = flightDao.findFlights("RTM", "OSL", interval, ServiceClass.BUSINESS);
|
||||
assertNotNull("Invalid result", flights);
|
||||
assertEquals("Invalid amount of flights", 1, flights.size());
|
||||
}
|
||||
@@ -70,7 +74,7 @@ public class HibernateFlightDaoTest extends AbstractTransactionalDataSourceSprin
|
||||
.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", dateTime, dateTime, ServiceClass.BUSINESS);
|
||||
List flights = flightDao.findFlights("RTM", "OSL", new Interval(dateTime, dateTime), ServiceClass.BUSINESS);
|
||||
assertNotNull("Invalid result", flights);
|
||||
assertEquals("Invalid amount of flights", 0, flights.size());
|
||||
}
|
||||
|
||||
@@ -22,8 +22,7 @@ import java.util.List;
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.YearMonthDay;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.ws.samples.airline.dao.FlightDao;
|
||||
import org.springframework.ws.samples.airline.dao.TicketDao;
|
||||
import org.springframework.ws.samples.airline.domain.Flight;
|
||||
@@ -153,14 +152,12 @@ public class AirlineServiceImplTest extends TestCase {
|
||||
public void testGetFlights() throws Exception {
|
||||
String toCode = "to";
|
||||
String fromCode = "from";
|
||||
YearMonthDay departureDate = new YearMonthDay(2006, 1, 31);
|
||||
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
||||
Flight flight = new Flight();
|
||||
List flights = new ArrayList();
|
||||
flights.add(flight);
|
||||
DateTime startOfPeriod = new DateTime(2006, 1, 31, 0, 0, 0, 0);
|
||||
DateTime endOfPeriod = new DateTime(2006, 2, 1, 0, 0, 0, 0);
|
||||
flightDaoControl.expectAndReturn(
|
||||
flightDaoMock.findFlights(fromCode, toCode, startOfPeriod, endOfPeriod, ServiceClass.ECONOMY), flights);
|
||||
flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY), flights);
|
||||
flightDaoControl.replay();
|
||||
ticketDaoControl.replay();
|
||||
securityServiceControl.replay();
|
||||
@@ -172,14 +169,12 @@ public class AirlineServiceImplTest extends TestCase {
|
||||
public void testGetFlightsDefaultServiceClass() throws Exception {
|
||||
String toCode = "to";
|
||||
String fromCode = "from";
|
||||
YearMonthDay departureDate = new YearMonthDay(2006, 1, 31);
|
||||
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
||||
Flight flight = new Flight();
|
||||
List flights = new ArrayList();
|
||||
flights.add(flight);
|
||||
DateTime startOfPeriod = new DateTime(2006, 1, 31, 0, 0, 0, 0);
|
||||
DateTime endOfPeriod = new DateTime(2006, 2, 1, 0, 0, 0, 0);
|
||||
flightDaoControl.expectAndReturn(
|
||||
flightDaoMock.findFlights(fromCode, toCode, startOfPeriod, endOfPeriod, ServiceClass.ECONOMY), flights);
|
||||
flightDaoMock.findFlights(fromCode, toCode, departureDate.toInterval(), ServiceClass.ECONOMY), flights);
|
||||
flightDaoControl.replay();
|
||||
ticketDaoControl.replay();
|
||||
securityServiceControl.replay();
|
||||
|
||||
@@ -16,19 +16,24 @@
|
||||
package org.springframework.ws.samples.airline.ws;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.easymock.MockControl;
|
||||
import org.joda.time.DateTime;
|
||||
import org.joda.time.YearMonthDay;
|
||||
|
||||
import org.joda.time.LocalDate;
|
||||
import org.springframework.oxm.jaxb.Jaxb1Marshaller;
|
||||
import org.springframework.ws.WebServiceMessage;
|
||||
import org.springframework.ws.context.MessageContext;
|
||||
import org.springframework.ws.samples.airline.domain.Flight;
|
||||
import org.springframework.ws.samples.airline.schema.GetFlightsRequest;
|
||||
import org.springframework.ws.samples.airline.schema.GetFlightsResponse;
|
||||
import org.springframework.ws.samples.airline.schema.ServiceClass;
|
||||
import org.springframework.ws.samples.airline.schema.impl.GetFlightsRequestImpl;
|
||||
import org.springframework.ws.samples.airline.service.AirlineService;
|
||||
import org.springframework.xml.transform.StringResult;
|
||||
import org.springframework.xml.transform.StringSource;
|
||||
|
||||
public class GetFlightsEndpointTest extends TestCase {
|
||||
|
||||
@@ -48,7 +53,7 @@ public class GetFlightsEndpointTest extends TestCase {
|
||||
public void testInvoke() throws Exception {
|
||||
String fromAirportCode = "ABC";
|
||||
String toAirportCode = "DEF";
|
||||
YearMonthDay departureDate = new YearMonthDay();
|
||||
LocalDate departureDate = new LocalDate();
|
||||
GetFlightsRequest request = new GetFlightsRequestImpl();
|
||||
request.setFrom(fromAirportCode);
|
||||
request.setTo(toAirportCode);
|
||||
@@ -72,4 +77,42 @@ public class GetFlightsEndpointTest extends TestCase {
|
||||
assertEquals("Invalid flight number on flight", "1", responseFlight.getNumber());
|
||||
}
|
||||
|
||||
public void testMarshalling() throws Exception {
|
||||
Jaxb1Marshaller marshaller = new Jaxb1Marshaller();
|
||||
marshaller.setContextPath("org.springframework.ws.samples.airline.schema");
|
||||
marshaller.setValidating(true);
|
||||
marshaller.afterPropertiesSet();
|
||||
endpoint.setMarshaller(marshaller);
|
||||
endpoint.setUnmarshaller(marshaller);
|
||||
|
||||
MockControl contextControl = MockControl.createControl(MessageContext.class);
|
||||
MessageContext contextMock = (MessageContext) contextControl.getMock();
|
||||
MockControl messageControl = MockControl.createControl(WebServiceMessage.class);
|
||||
WebServiceMessage requestMock = (WebServiceMessage) messageControl.getMock();
|
||||
WebServiceMessage responseMock = (WebServiceMessage) messageControl.getMock();
|
||||
|
||||
contextControl.expectAndReturn(contextMock.getRequest(), requestMock);
|
||||
StringSource source = new StringSource(
|
||||
"<GetFlightsRequest xmlns=\"http://www.springframework.org/spring-ws/samples/airline/schemas\"><from>AMS</from><to>VCE</to><departureDate>2006-01-31Z</departureDate></GetFlightsRequest>");
|
||||
messageControl.expectAndReturn(requestMock.getPayloadSource(), source);
|
||||
String fromAirportCode = "AMS";
|
||||
String toAirportCode = "VCE";
|
||||
LocalDate departureDate = new LocalDate(2006, 1, 31);
|
||||
serviceControl.expectAndReturn(serviceMock.getFlights(fromAirportCode, toAirportCode, departureDate, null),
|
||||
Collections.EMPTY_LIST);
|
||||
contextControl.expectAndReturn(contextMock.getResponse(), responseMock);
|
||||
StringResult result = new StringResult();
|
||||
messageControl.expectAndReturn(responseMock.getPayloadResult(), result);
|
||||
|
||||
contextControl.replay();
|
||||
messageControl.replay();
|
||||
serviceControl.replay();
|
||||
|
||||
endpoint.invoke(contextMock);
|
||||
|
||||
contextControl.verify();
|
||||
messageControl.verify();
|
||||
serviceControl.verify();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
# Test-specific settings for the DAO layer
|
||||
# Uses an in-memory HSQL database
|
||||
|
||||
hibernate.dialect=org.hibernate.dialect.HSQLDialect
|
||||
hibernate.cache.provider_class=org.hibernate.cache.HashtableCacheProvider
|
||||
hibernate.hbm2ddl.auto=create-drop
|
||||
@@ -1,7 +0,0 @@
|
||||
# Test-specific settings for the DAO layer
|
||||
# Uses an in-memory HSQL database
|
||||
|
||||
jdbc.driverClassName=org.hsqldb.jdbcDriver
|
||||
jdbc.username=sa
|
||||
jdbc.password=
|
||||
jdbc.url=jdbc:hsqldb:mem:airline
|
||||
Reference in New Issue
Block a user