From 59c3f349700154dae5652275e4d1fff34da8bdee Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Thu, 14 Jun 2007 02:00:51 +0000 Subject: [PATCH] Updating Airline sample. --- .../dao/hibernate/HibernateFlightDao.java | 49 -------- .../hibernate/HibernateFrequentFlyerDao.java | 37 ------ .../dao/hibernate/HibernateTicketDao.java | 29 ----- .../ws/samples/airline/domain/Entity.java | 32 ----- .../hibernate/ServiceClassUserType.java | 84 ------------- .../security/FrequentFlyerDetailsService.java | 49 -------- .../GetFrequentFlyerMileageEndpoint.java | 52 -------- .../applicationContext-hibernate.xml | 49 -------- .../dao/hibernate/hibernate.properties | 5 - .../airline/domain/hibernate/airline.hbm.xml | 53 -------- .../main/webapp/WEB-INF/airline-servlet.xml | 33 ----- samples/airline/src/main/webapp/airline.xsd | 118 ------------------ .../dao/hibernate/HibernateFlightDaoTest.java | 109 ---------------- .../HibernateFrequentFlyerDaoTest.java | 48 ------- .../dao/hibernate/HibernateTicketDaoTest.java | 91 -------------- .../GetFrequentFlyerMileageEndpointTest.java | 53 -------- 16 files changed, 891 deletions(-) delete mode 100644 samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDao.java delete mode 100644 samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDao.java delete mode 100644 samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDao.java delete mode 100644 samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/Entity.java delete mode 100644 samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/hibernate/ServiceClassUserType.java delete mode 100644 samples/airline/src/main/java/org/springframework/ws/samples/airline/security/FrequentFlyerDetailsService.java delete mode 100644 samples/airline/src/main/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpoint.java delete mode 100644 samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml delete mode 100644 samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/hibernate.properties delete mode 100644 samples/airline/src/main/resources/org/springframework/ws/samples/airline/domain/hibernate/airline.hbm.xml delete mode 100644 samples/airline/src/main/webapp/WEB-INF/airline-servlet.xml delete mode 100644 samples/airline/src/main/webapp/airline.xsd delete mode 100644 samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDaoTest.java delete mode 100644 samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDaoTest.java delete mode 100644 samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDaoTest.java delete mode 100644 samples/airline/src/test/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpointTest.java diff --git a/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDao.java b/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDao.java deleted file mode 100644 index 4a6323af..00000000 --- a/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDao.java +++ /dev/null @@ -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}); - } - -} diff --git a/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDao.java b/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDao.java deleted file mode 100644 index f37dba58..00000000 --- a/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDao.java +++ /dev/null @@ -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); - } -} diff --git a/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDao.java b/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDao.java deleted file mode 100644 index 25593688..00000000 --- a/samples/airline/src/main/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDao.java +++ /dev/null @@ -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); - } -} diff --git a/samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/Entity.java b/samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/Entity.java deleted file mode 100644 index 54b4812b..00000000 --- a/samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/Entity.java +++ /dev/null @@ -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; - } - -} diff --git a/samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/hibernate/ServiceClassUserType.java b/samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/hibernate/ServiceClassUserType.java deleted file mode 100644 index 5c193666..00000000 --- a/samples/airline/src/main/java/org/springframework/ws/samples/airline/domain/hibernate/ServiceClassUserType.java +++ /dev/null @@ -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; - } -} \ No newline at end of file diff --git a/samples/airline/src/main/java/org/springframework/ws/samples/airline/security/FrequentFlyerDetailsService.java b/samples/airline/src/main/java/org/springframework/ws/samples/airline/security/FrequentFlyerDetailsService.java deleted file mode 100644 index 2b2384c1..00000000 --- a/samples/airline/src/main/java/org/springframework/ws/samples/airline/security/FrequentFlyerDetailsService.java +++ /dev/null @@ -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 UserDetailsService for FrequentFlyerDetails. - * - * @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"); - } - } -} diff --git a/samples/airline/src/main/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpoint.java b/samples/airline/src/main/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpoint.java deleted file mode 100644 index dc0e42b2..00000000 --- a/samples/airline/src/main/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpoint.java +++ /dev/null @@ -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"); - - } -} diff --git a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml b/samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml deleted file mode 100644 index e19014c2..00000000 --- a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/applicationContext-hibernate.xml +++ /dev/null @@ -1,49 +0,0 @@ - - - - - - - - - - - - - - - - - classpath:org/springframework/ws/samples/airline/domain/hibernate/airline.hbm.xml - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/hibernate.properties b/samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/hibernate.properties deleted file mode 100644 index 2962f908..00000000 --- a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/dao/hibernate/hibernate.properties +++ /dev/null @@ -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 diff --git a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/domain/hibernate/airline.hbm.xml b/samples/airline/src/main/resources/org/springframework/ws/samples/airline/domain/hibernate/airline.hbm.xml deleted file mode 100644 index e2fc3d35..00000000 --- a/samples/airline/src/main/resources/org/springframework/ws/samples/airline/domain/hibernate/airline.hbm.xml +++ /dev/null @@ -1,53 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/samples/airline/src/main/webapp/WEB-INF/airline-servlet.xml b/samples/airline/src/main/webapp/WEB-INF/airline-servlet.xml deleted file mode 100644 index 9ff9258e..00000000 --- a/samples/airline/src/main/webapp/WEB-INF/airline-servlet.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - The handlerAdapter makes sure that Spring's DispatcherServlet - supports MessageEndpoints instances as handlers. - - - - - - - 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. - - - - - - - All incoming request are mapped to the messageDispatcher defined in applicationContext-ws.xml - - - - - airlineWsdl - - - - - \ No newline at end of file diff --git a/samples/airline/src/main/webapp/airline.xsd b/samples/airline/src/main/webapp/airline.xsd deleted file mode 100644 index 2a9dddc1..00000000 --- a/samples/airline/src/main/webapp/airline.xsd +++ /dev/null @@ -1,118 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDaoTest.java b/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDaoTest.java deleted file mode 100644 index 916dc386..00000000 --- a/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFlightDaoTest.java +++ /dev/null @@ -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); - } -} \ No newline at end of file diff --git a/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDaoTest.java b/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDaoTest.java deleted file mode 100644 index 2fb4d3a3..00000000 --- a/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateFrequentFlyerDaoTest.java +++ /dev/null @@ -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()); - } -} diff --git a/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDaoTest.java b/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDaoTest.java deleted file mode 100644 index 43ad81d4..00000000 --- a/samples/airline/src/test/java/org/springframework/ws/samples/airline/dao/hibernate/HibernateTicketDaoTest.java +++ /dev/null @@ -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); - } - -} diff --git a/samples/airline/src/test/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpointTest.java b/samples/airline/src/test/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpointTest.java deleted file mode 100644 index ab7bea72..00000000 --- a/samples/airline/src/test/java/org/springframework/ws/samples/airline/security/GetFrequentFlyerMileageEndpointTest.java +++ /dev/null @@ -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(); - } -} \ No newline at end of file