This commit is contained in:
Keith Donald
2008-04-04 22:14:06 +00:00
parent ec2c4ba105
commit ee597b7995
63 changed files with 866 additions and 542 deletions

View File

@@ -7,5 +7,6 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="var" path="IVY_CACHE/org.easymock/easymock/easymock-2.3.jar" sourcepath="/IVY_CACHE/org.easymock/easymock/easymock-sources-2.3.jar"/>
<classpathentry kind="var" path="IVY_CACHE/javax.el/el-api/el-api-1.0.jar" sourcepath="IVVY_CACHE/javax.el/el-api/el-api-sources-1.0.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>

View File

@@ -6,9 +6,15 @@ import java.util.List;
import javax.faces.model.DataModel;
import org.easymock.EasyMock;
import org.springframework.binding.mapping.Mapper;
import org.springframework.binding.mapping.MappingResults;
import org.springframework.faces.model.OneSelectionTrackingListDataModel;
import org.springframework.faces.model.converter.FacesConversionService;
import org.springframework.webflow.config.FlowDefinitionResource;
import org.springframework.webflow.config.FlowDefinitionResourceFactory;
import org.springframework.webflow.core.collection.AttributeMap;
import org.springframework.webflow.engine.EndState;
import org.springframework.webflow.engine.Flow;
import org.springframework.webflow.test.MockExternalContext;
import org.springframework.webflow.test.MockFlowBuilderContext;
import org.springframework.webflow.test.execution.AbstractXmlFlowExecutionTests;
@@ -32,7 +38,7 @@ public class MainFlowExecutionTests extends AbstractXmlFlowExecutionTests {
builderContext.getFlowBuilderServices().setConversionService(new FacesConversionService());
}
public void testStart() {
public void testStartMainFlow() {
List<Booking> bookings = new ArrayList<Booking>();
bookings.add(new Booking(new Hotel(), new User("keith", "password", "Keith Donald")));
EasyMock.expect(bookingService.findBookings("keith")).andReturn(bookings);
@@ -42,31 +48,80 @@ public class MainFlowExecutionTests extends AbstractXmlFlowExecutionTests {
context.setCurrentUser("keith");
startFlow(context);
assertCurrentStateEquals("enterSearchCriteria");
assertResponseWrittenEquals("enterSearchCriteria", context);
assertTrue(getRequiredFlowAttribute("searchCriteria") instanceof SearchCriteria);
assertTrue(getRequiredViewAttribute("bookings") instanceof DataModel);
EasyMock.verify(bookingService);
}
// public void testSearch() {
// setCurrentState("enterSearchCriteria");
// SearchCriteria criteria = new SearchCriteria();
// criteria.setSearchString("Jameson");
// getFlowScope().put("searchCriteria", criteria);
//
// List<Hotel> hotels = new ArrayList<Hotel>();
// hotels.add(new Hotel());
// EasyMock.expect(bookingService.findHotels(criteria)).andReturn(hotels);
// EasyMock.replay(bookingService);
//
// MockExternalContext context = new MockExternalContext();
// context.setEventId("search");
// resumeFlow(context);
//
// EasyMock.verify(bookingService);
//
// assertCurrentStateEquals("reviewHotels");
// assertTrue(getRequiredViewAttribute("hotels") instanceof DataModel);
// }
public void testSearchHotels() {
setCurrentState("enterSearchCriteria");
SearchCriteria criteria = new SearchCriteria();
criteria.setSearchString("Jameson");
getFlowScope().put("searchCriteria", criteria);
List<Hotel> hotels = new ArrayList<Hotel>();
hotels.add(new Hotel());
EasyMock.expect(bookingService.findHotels(criteria)).andReturn(hotels);
EasyMock.replay(bookingService);
MockExternalContext context = new MockExternalContext();
context.setEventId("search");
resumeFlow(context);
EasyMock.verify(bookingService);
assertCurrentStateEquals("reviewHotels");
assertResponseWrittenEquals("reviewHotels", context);
assertTrue(getRequiredViewAttribute("hotels") instanceof DataModel);
}
public void testSelectHotel() {
setCurrentState("reviewHotels");
List<Hotel> hotels = new ArrayList<Hotel>();
Hotel hotel = new Hotel();
hotel.setId(1L);
hotel.setName("Jameson Inn");
hotels.add(hotel);
OneSelectionTrackingListDataModel dataModel = new OneSelectionTrackingListDataModel(hotels);
dataModel.select(hotel);
getViewScope().put("hotels", dataModel);
MockExternalContext context = new MockExternalContext();
context.setEventId("select");
resumeFlow(context);
assertCurrentStateEquals("reviewHotel");
assertNull(getFlowAttribute("hotels"));
assertSame(hotel, getFlowAttribute("hotel"));
}
public void testBookHotel() {
setCurrentState("reviewHotel");
Hotel hotel = new Hotel();
hotel.setId(1L);
hotel.setName("Jameson Inn");
getFlowScope().put("hotel", hotel);
Flow mockBookingFlow = new Flow("booking");
mockBookingFlow.setInputMapper(new Mapper() {
public MappingResults map(Object source, Object target) {
assertEquals(new Long(1), ((AttributeMap) source).get("hotelId"));
return null;
}
});
new EndState(mockBookingFlow, "bookingConfirmed");
getFlowDefinitionRegistry().registerFlowDefinition(mockBookingFlow);
MockExternalContext context = new MockExternalContext();
context.setEventId("book");
resumeFlow(context);
assertFlowExecutionEnded();
assertFlowExecutionOutcomeEquals("finish");
}
}

View File

@@ -45,7 +45,6 @@
<label for="checkinDate">Check In Date:</label>
</div>
<div class="input">
<form:errors path="checkinDate" cssClass="errors"/>
<form:input path="checkinDate"/>
</div>
</div>
@@ -54,7 +53,6 @@
<label for="checkoutDate">Check Out Date:</label>
</div>
<div class="input">
<form:errors path="checkoutDate" cssClass="errors"/>
<form:input path="checkoutDate"/>
</div>
</div>
@@ -84,7 +82,6 @@
<label for="creditCard">Credit Card #:</label>
</div>
<div class="input">
<form:errors path="creditCard" cssClass="errors"/>
<form:input id="creditCard" path="creditCard"/>
</div>
</div>
@@ -93,7 +90,6 @@
<label for="creditCardName">Credit Card Name:</label>
</div>
<div class="input">
<form:errors path="creditCardName" cssClass="errors"/>
<form:input id="creditCardName" path="creditCardName"/>
</div>
</div>

View File

@@ -0,0 +1,2 @@
booking.checkinDate.typeMismatch=The Check In Date must be in the format dd/mm/yy
booking.checkoutDate.typeMismatch=The Check Out Date must be in the format dd/mm/yy

View File

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:web="http://www.springframework.org/schema/webflow-config"
xmlns:webflow="http://www.springframework.org/schema/webflow-config"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:security="http://www.springframework.org/schema/security"
xsi:schemaLocation="
@@ -48,18 +48,18 @@
</bean>
<!-- Executes flows: the central entry point into the Spring Web Flow system -->
<web:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<web:flow-execution-listeners>
<web:listener ref="jpaFlowExecutionListener" criteria="*" />
<web:listener ref="securityFlowExecutionListener" criteria="*" />
</web:flow-execution-listeners>
</web:flow-executor>
<webflow:flow-executor id="flowExecutor" flow-registry="flowRegistry">
<webflow:flow-execution-listeners>
<webflow:listener ref="jpaFlowExecutionListener" criteria="*" />
<webflow:listener ref="securityFlowExecutionListener" criteria="*" />
</webflow:flow-execution-listeners>
</webflow:flow-executor>
<!-- The registry of executable flow definitions -->
<web:flow-registry id="flowRegistry">
<web:flow-location path="WEB-INF/hotels/booking/booking.xml" />
</web:flow-registry>
<webflow:flow-registry id="flowRegistry">
<webflow:flow-location path="/WEB-INF/hotels/booking/booking.xml" />
</webflow:flow-registry>
<!-- Installs a listener that manages JPA persistence contexts for flows that require them -->
<bean id="jpaFlowExecutionListener" class="org.springframework.webflow.persistence.JpaFlowExecutionListener">
<constructor-arg ref="entityManagerFactory" />

View File

@@ -1,9 +0,0 @@
log4j.rootCategory=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %p [%c] - <%m>%n
# Enable web flow logging
log4j.category.org.springframework.webflow=DEBUG
log4j.category.org.springframework.binding=DEBUG