[jboss-cvs] jboss-seam/examples/hibernate/src/org/jboss/seam/example/hibernate/test ...

Gavin King gavin.king at jboss.com
Thu Feb 22 02:52:27 EST 2007


  User: gavin   
  Date: 07/02/22 02:52:27

  Modified:    examples/hibernate/src/org/jboss/seam/example/hibernate/test 
                        BookingTest.java
  Log:
  improve test
  
  Revision  Changes    Path
  1.7       +42 -63    jboss-seam/examples/hibernate/src/org/jboss/seam/example/hibernate/test/BookingTest.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: BookingTest.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/examples/hibernate/src/org/jboss/seam/example/hibernate/test/BookingTest.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- BookingTest.java	22 Feb 2007 07:33:16 -0000	1.6
  +++ BookingTest.java	22 Feb 2007 07:52:27 -0000	1.7
  @@ -1,4 +1,4 @@
  -//$Id: BookingTest.java,v 1.6 2007/02/22 07:33:16 gavin Exp $
  +//$Id: BookingTest.java,v 1.7 2007/02/22 07:52:27 gavin Exp $
   package org.jboss.seam.example.hibernate.test;
   
   import java.util.Calendar;
  @@ -16,7 +16,6 @@
   import org.jboss.seam.example.hibernate.Booking;
   import org.jboss.seam.example.hibernate.BookingListAction;
   import org.jboss.seam.example.hibernate.Hotel;
  -import org.jboss.seam.example.hibernate.HotelBookingAction;
   import org.jboss.seam.example.hibernate.User;
   import org.jboss.seam.jsf.SeamPhaseListener;
   import org.jboss.seam.jsf.TransactionalSeamPhaseListener;
  @@ -30,57 +29,52 @@
      public void testBookHotel() throws Exception
      {
         
  -      new FacesRequest()
  -      {
  +      new FacesRequest() {
  +         
            @Override
  -         protected void invokeApplication()
  +         protected void invokeApplication() throws Exception
            {
  -            Contexts.getSessionContext().set("loggedIn", true);
               Contexts.getSessionContext().set("user", new User("Gavin King", "foobar", "gavin"));
  +            setValue("#{identity.username}", "gavin");
  +            setValue("#{identity.password}", "foobar");            
  +            invokeMethod("#{identity.login}");
            }
   
         }.run();
   
  -      String id = new FacesRequest("/main.xhtml") 
  -      {
  -
  -         HotelBookingAction hotelBooking;
  +      String id = new FacesRequest("/main.xhtml") {
            
            @Override
            protected void updateModelValues() throws Exception
            {
  -            hotelBooking = (HotelBookingAction) Component.getInstance("hotelBooking", true);
  -            hotelBooking.setSearchString("Union Square");
  +            setValue("#{hotelBooking.searchString}", "Union Square");
            }
   
            @Override
            protected void invokeApplication()
            {
  -            String outcome = hotelBooking.find();
  -            assert "main".equals(outcome);
  +            assert invokeMethod("#{hotelBooking.find}").equals("main");
            }
   
            @Override
            protected void renderResponse()
            {
  -            DataModel hotelsDataModel = (DataModel) Contexts.getConversationContext().get("hotels");
  -            assert hotelsDataModel.getRowCount()==1;
  -            assert ( (Hotel) hotelsDataModel.getRowData() ).getCity().equals("NY");
  -            assert "Union Square".equals( hotelBooking.getSearchString() );
  +            DataModel hotels = (DataModel) Contexts.getConversationContext().get("hotels");
  +            assert hotels.getRowCount()==1;
  +            assert ( (Hotel) hotels.getRowData() ).getCity().equals("NY");
  +            assert getValue("#{hotelBooking.searchString}").equals("Union Square");
               assert Manager.instance().isLongRunningConversation();
            }
            
         }.run();
         
  -      new FacesRequest("/main.xhtml", id) {
  +      id = new FacesRequest("/hotel.xhtml", id) {
   
            @Override
  -         protected void invokeApplication()
  -         {
  -            //getRequest().getParameterMap().put("hotelId", "2");
  -        	   HotelBookingAction hotelBooking = (HotelBookingAction) Contexts.getConversationContext().get("hotelBooking");
  -            String outcome = hotelBooking.selectHotel();
  -            assert "selected".equals( outcome );
  +         protected void invokeApplication() throws Exception {
  +            DataModel hotels = (DataModel) Contexts.getConversationContext().get("hotels");
  +            assert hotels.getRowCount()==1;
  +            invokeMethod("#{hotelBooking.selectHotel}");
            }
   
            @Override
  @@ -94,27 +88,25 @@
            
         }.run();
         
  -      new FacesRequest("/hotel.xhtml", id) {
  +      id = new FacesRequest("/hotel.xhtml", id) {
   
            @Override
            protected void invokeApplication()
            {
  -        	   HotelBookingAction hotelBooking = (HotelBookingAction) Contexts.getConversationContext().get("hotelBooking");
  -            String outcome = hotelBooking.bookHotel();
  -            assert "book".equals( outcome );
  +            invokeMethod("#{hotelBooking.bookHotel}");
            }
   
            @Override
            protected void renderResponse()
            {
  +            assert getValue("#{booking.user}")!=null;
  +            assert getValue("#{booking.hotel}")!=null;
  +            assert getValue("#{booking.creditCard}")==null;
  +            assert getValue("#{booking.creditCardName}")==null;
               Booking booking = (Booking) Contexts.getConversationContext().get("booking");
  -            assert booking.getUser()!=null;
  -            assert booking.getHotel()!=null;
               assert booking.getHotel()==Contexts.getConversationContext().get("hotel");
               assert booking.getUser()==Contexts.getSessionContext().get("user");
               assert Manager.instance().isLongRunningConversation();
  -            assert booking.getCreditCard()==null;
  -            assert booking.getCreditCardName()==null;
            }
            
         }.run();
  @@ -166,21 +158,18 @@
            @Override @SuppressWarnings("deprecation")
            protected void updateModelValues() throws Exception
            {
  -            Booking booking = (Booking) Contexts.getConversationContext().get("booking");
  -            booking.setCreditCard("1234567891021234");
  -            booking.setCreditCardName("GAVIN KING");
  -            booking.setBeds(2);
  +            setValue("#{booking.creditCard}", "1234567891021234");
  +            setValue("#{booking.creditCardName}", "GAVIN KING");
  +            setValue("#{booking.beds}", 2);
               Date now = new Date();
  -            booking.setCheckinDate(now);
  -            booking.setCheckoutDate(now);
  +            setValue("#{booking.checkinDate}", now);
  +            setValue("#{booking.checkoutDate}", now);
            }
   
            @Override
            protected void invokeApplication()
            {
  -        	   HotelBookingAction hotelBooking = (HotelBookingAction) Contexts.getConversationContext().get("hotelBooking");
  -            String outcome = hotelBooking.setBookingDetails();
  -            assert outcome==null;
  +            assert invokeMethod("#{hotelBooking.setBookingDetails}")==null;
            }
   
            @Override
  @@ -188,7 +177,8 @@
            {
               Iterator messages = FacesContext.getCurrentInstance().getMessages();
               assert messages.hasNext();
  -            assert ( (FacesMessage) messages.next() ).getSummary().equals("Check out date must be later than check in date");
  +            FacesMessage message = (FacesMessage) messages.next();
  +            assert message.getSummary().equals("Check out date must be later than check in date");
               assert !messages.hasNext();
               assert Manager.instance().isLongRunningConversation();
            }
  @@ -200,18 +190,15 @@
            @Override @SuppressWarnings("deprecation")
            protected void updateModelValues() throws Exception
            {
  -            Booking booking = (Booking) Contexts.getConversationContext().get("booking");
               Calendar cal = Calendar.getInstance();
               cal.add(Calendar.DAY_OF_MONTH, 2);
  -            booking.setCheckoutDate( cal.getTime() );
  +            setValue("#{booking.checkoutDate}", cal.getTime() );
            }
   
            @Override
            protected void invokeApplication()
            {
  -        	   HotelBookingAction hotelBooking = (HotelBookingAction) Contexts.getConversationContext().get("hotelBooking");
  -            String outcome = hotelBooking.setBookingDetails();
  -            assert "confirm".equals(outcome);
  +            assert invokeMethod("#{hotelBooking.setBookingDetails}").equals("confirm");
            }
   
            @Override
  @@ -227,15 +214,7 @@
            @Override
            protected void invokeApplication()
            {
  -        	   HotelBookingAction hotelBooking = (HotelBookingAction) Contexts.getConversationContext().get("hotelBooking");
  -            String outcome = hotelBooking.confirm();
  -            assert "confirmed".equals( outcome );
  -         }
  -
  -         @Override
  -         protected void renderResponse()
  -         {
  -            assert !Manager.instance().isLongRunningConversation();
  +            assert invokeMethod("#{hotelBooking.confirm}").equals("confirmed");
            }
            
         }.run();
  @@ -251,7 +230,7 @@
               Booking booking = (Booking) bookings.getRowData();
               assert booking.getHotel().getCity().equals("NY");
               assert booking.getUser().getUsername().equals("gavin");
  -            //assert !Manager.instance().isLongRunningConversation();
  +            assert !Manager.instance().isLongRunningConversation();
            }
            
         }.run();
  @@ -273,7 +252,7 @@
            {
               ListDataModel bookings = (ListDataModel) Component.getInstance("bookings", true);
               assert bookings.getRowCount()==0;
  -            //assert !Manager.instance().isLongRunningConversation();
  +            assert !Manager.instance().isLongRunningConversation();
            }
            
         }.run();
  
  
  



More information about the jboss-cvs-commits mailing list