[seam-commits] Seam SVN: r13129 - in examples/trunk/booking-simplified: src/main/java/org/jboss/seam/examples/booking/account and 5 other directories.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Fri Jun 11 20:10:25 EDT 2010
Author: dan.j.allen
Date: 2010-06-11 20:10:24 -0400 (Fri, 11 Jun 2010)
New Revision: 13129
Added:
examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/
examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java
examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTest.java
Removed:
examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTestCase.java
Modified:
examples/trunk/booking-simplified/
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/model/Booking.java
Log:
add test for booking
fix up booking
Property changes on: examples/trunk/booking-simplified
___________________________________________________________________
Name: svn:ignore
- target
.settings
.classpath
.project
faces-config.NavData
+ target
.settings
.classpath
.project
faces-config.NavData
nbactions*
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java 2010-06-12 00:09:08 UTC (rev 13128)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java 2010-06-12 00:10:24 UTC (rev 13129)
@@ -30,6 +30,7 @@
public User getCurrentAccount()
{
log.info("Producing canned User");
- return new User("Dan Allen", "dan");
+ //return new User("Dan Allen", "dan");
+ return em.find(User.class, "dan");
}
}
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java 2010-06-12 00:09:08 UTC (rev 13128)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgent.java 2010-06-12 00:10:24 UTC (rev 13129)
@@ -48,6 +48,4 @@
Booking getBooking();
boolean isBookingValid();
-
- void destroy();
}
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java 2010-06-12 00:09:08 UTC (rev 13128)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/booking/BookingAgentBean.java 2010-06-12 00:10:24 UTC (rev 13129)
@@ -27,7 +27,6 @@
import java.util.Calendar;
-import javax.ejb.Remove;
import javax.ejb.Stateful;
import javax.enterprise.context.Conversation;
import javax.enterprise.context.ConversationScoped;
@@ -87,6 +86,7 @@
private boolean bookingValid;
+ //@Begin
public void selectHotel(final Hotel hotel)
{
// NOTE get a fresh reference that's managed by the conversational
@@ -128,6 +128,7 @@
}
}
+ //@End
public void confirm()
{
em.persist(booking);
@@ -141,6 +142,7 @@
conversation.end();
}
+ //@End
public void cancel()
{
booking = null;
@@ -168,9 +170,4 @@
{
return bookingValid;
}
-
- @Remove
- public void destroy()
- {
- }
}
Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/model/Booking.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/model/Booking.java 2010-06-12 00:09:08 UTC (rev 13128)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/model/Booking.java 2010-06-12 00:10:24 UTC (rev 13129)
@@ -29,6 +29,7 @@
import java.math.BigDecimal;
import java.text.DateFormat;
import java.util.Date;
+import javax.enterprise.inject.Typed;
import javax.persistence.Entity;
import javax.persistence.EnumType;
@@ -52,6 +53,7 @@
* @author Dan Allen
*/
@Entity
+ at Typed()
public class Booking implements Serializable
{
private Long id;
@@ -76,6 +78,8 @@
this.hotel = hotel;
this.user = user;
this.creditCardName = user.getName();
+ this.smoking = false;
+ this.beds = 1;
}
@Id
Added: examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java
===================================================================
--- examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java (rev 0)
+++ examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java 2010-06-12 00:10:24 UTC (rev 13129)
@@ -0,0 +1,112 @@
+package org.jboss.seam.examples.booking.booking;
+
+import java.io.Serializable;
+import java.util.HashMap;
+import java.util.Map;
+import javax.enterprise.inject.Instance;
+import javax.enterprise.inject.Produces;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.UserTransaction;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.examples.booking.account.Registered;
+import org.jboss.seam.examples.booking.controls.BookingFormControls;
+import org.jboss.seam.examples.booking.model.Booking;
+import org.jboss.seam.examples.booking.model.CreditCardType;
+import org.jboss.seam.examples.booking.support.MavenArtifactResolver;
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.examples.booking.support.NoOpLogger;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.jboss.weld.Container;
+import org.jboss.weld.context.ContextLifecycle;
+import org.jboss.weld.context.ConversationContext;
+import org.jboss.weld.context.api.ContextualInstance;
+import org.jboss.weld.context.api.helpers.AbstractMapBackedBeanStore;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class BookingAgentTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive() {
+ WebArchive war = ShrinkWrap.create("test.war", WebArchive.class)
+ .addPackage(Hotel.class.getPackage())
+ .addClasses(BookingAgent.class, BookingAgentBean.class, Confirmed.class,
+ Registered.class, BookingEvent.class, BookingFormControls.class, NoOpLogger.class)
+ .addLibraries(
+ MavenArtifactResolver.resolve("joda-time:joda-time:1.6"),
+ MavenArtifactResolver.resolve("org.jboss.seam.international:seam-international-api:3.0.0.Alpha1"),
+ MavenArtifactResolver.resolve("org.jboss.seam.international:seam-international:3.0.0.Alpha1")
+ )
+ .addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml")
+ .addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ return war;
+ }
+
+ @Inject UserTransaction utx;
+ @PersistenceContext EntityManager em;
+ @Inject BookingAgent bookingAgent;
+ @Inject Instance<Booking> bookingInstance;
+
+ public void prepareSeedData() throws Exception
+ {
+ utx.begin();
+ em.joinTransaction();
+ em.createQuery("delete from Booking").executeUpdate();
+ em.createQuery("delete from Hotel").executeUpdate();
+ em.persist(new Hotel("Doubletree Atlanta-Buckhead", "3342 Peachtree Road NE", "Atlanta", "GA", "30326", "USA"));
+ em.createQuery("delete from User").executeUpdate();
+ em.persist(new User("Ike", "ike", "incontainer"));
+ utx.commit();
+ }
+
+ @Test
+ public void testBookHotel() throws Exception
+ {
+ prepareSeedData();
+ ConversationContext cc = Container.instance().deploymentServices().get(ContextLifecycle.class).getConversationContext();
+ cc.setBeanStore(new HashMapBeanStore());
+ cc.setActive(true);
+
+ bookingAgent.selectHotel(em.find(Hotel.class, 1l));
+ bookingAgent.bookHotel();
+ Booking booking = bookingInstance.get();
+ booking.setCreditCardNumber("1111222233334444");
+ booking.setCreditCardExpiryMonth(1);
+ booking.setCreditCardExpiryYear(2012);
+ booking.setCreditCardType(CreditCardType.VISA);
+ booking.setBeds(1);
+ booking.setSmoking(false);
+ bookingAgent.confirm();
+
+ Assert.assertEquals(1, em.createQuery("select b from Booking b").getResultList().size());
+ }
+
+ @Produces @Registered User getRegisteredUser()
+ {
+ return em.find(User.class, "ike");
+ }
+
+ public static class HashMapBeanStore extends AbstractMapBackedBeanStore implements Serializable
+ {
+ protected Map<String, ContextualInstance<? extends Object>> delegate;
+ public HashMapBeanStore()
+ {
+ delegate = new HashMap<String, ContextualInstance<? extends Object>>();
+ }
+
+ @Override
+ protected Map<String, ContextualInstance<? extends Object>> delegate() {
+ return delegate;
+ }
+ }
+
+}
Copied: examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTest.java (from rev 13127, examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTestCase.java)
===================================================================
--- examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTest.java (rev 0)
+++ examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTest.java 2010-06-12 00:10:24 UTC (rev 13129)
@@ -0,0 +1,82 @@
+package org.jboss.seam.examples.booking.inventory;
+
+import java.util.List;
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+import javax.persistence.EntityManager;
+import javax.persistence.PersistenceContext;
+import javax.transaction.UserTransaction;
+import org.jboss.arquillian.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.seam.examples.booking.support.MavenArtifactResolver;
+import org.jboss.seam.examples.booking.model.Hotel;
+import org.jboss.seam.examples.booking.support.NoOpLogger;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class HotelSearchTest
+{
+ @Deployment
+ public static Archive<?> createTestArchive() {
+ // JavaArchive doesn't work on GlassFish (would work on JBoss AS, but it breaks because of the EJBs)
+// JavaArchive jar = ShrinkWrap.create("test.jar", JavaArchive.class)
+// .addPackage(HotelSearch.class.getPackage())
+// .addPackage(Hotel.class.getPackage())
+// .addManifestResource("META-INF/persistence.xml", "persistence.xml")
+// .addManifestResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+// return jar;
+ // WebArchive does work in all cases (except JBoss AS still breaks with EJBs)
+ WebArchive war = ShrinkWrap.create("test.war", WebArchive.class)
+ .addPackage(HotelSearch.class.getPackage())
+ .addPackage(Hotel.class.getPackage())
+ .addClasses(NoOpLogger.class)
+ .addLibraries(
+ MavenArtifactResolver.resolve("joda-time:joda-time:1.6"),
+ MavenArtifactResolver.resolve("org.jboss.seam.international:seam-international-api:3.0.0.Alpha1"),
+ MavenArtifactResolver.resolve("org.jboss.seam.international:seam-international:3.0.0.Alpha1")
+ )
+ .addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml")
+ .addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
+ return war;
+ }
+
+ @Inject UserTransaction utx;
+ @PersistenceContext EntityManager em;
+ @Inject SearchCriteria criteria;
+ @Inject HotelSearch hotelSearch;
+ @Inject Instance<List<Hotel>> hotelsInstance;
+
+ public void prepareSeedData() throws Exception
+ {
+ utx.begin();
+ em.joinTransaction();
+ em.createQuery("delete from Hotel").executeUpdate();
+ em.persist(new Hotel("Doubletree Atlanta-Buckhead", "3342 Peachtree Road NE", "Atlanta", "GA", "30326", "USA"));
+ utx.commit();
+ }
+
+ @Test
+ public void testSearch() throws Exception
+ {
+ prepareSeedData();
+
+ criteria.setQuery("atlanta");
+ hotelSearch.find();
+ List<Hotel> hotels = hotelsInstance.get();
+ Assert.assertEquals(1, hotels.size());
+ Assert.assertEquals(hotels.get(0).getName(), "Doubletree Atlanta-Buckhead");
+
+ criteria.setQuery("boston");
+ hotelSearch.find();
+ hotels = hotelsInstance.get();
+ Assert.assertEquals(0, hotels.size());
+ }
+
+}
Deleted: examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTestCase.java
===================================================================
--- examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTestCase.java 2010-06-12 00:09:08 UTC (rev 13128)
+++ examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/inventory/HotelSearchTestCase.java 2010-06-12 00:10:24 UTC (rev 13129)
@@ -1,82 +0,0 @@
-package org.jboss.seam.examples.booking.inventory;
-
-import java.util.List;
-import javax.enterprise.inject.Instance;
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-import javax.transaction.UserTransaction;
-import org.jboss.arquillian.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.seam.examples.booking.support.MavenArtifactResolver;
-import org.jboss.seam.examples.booking.model.Hotel;
-import org.jboss.seam.examples.booking.support.NoOpLogger;
-import org.jboss.shrinkwrap.api.Archive;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.spec.JavaArchive;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.impl.base.asset.ByteArrayAsset;
-import org.junit.Assert;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
- at RunWith(Arquillian.class)
-public class HotelSearchTestCase
-{
- @Deployment
- public static Archive<?> createTestArchive() {
- // JavaArchive doesn't work on GlassFish (would work on JBoss AS, but it breaks because of the EJBs)
-// JavaArchive jar = ShrinkWrap.create("test.jar", JavaArchive.class)
-// .addPackage(HotelSearch.class.getPackage())
-// .addPackage(Hotel.class.getPackage())
-// .addManifestResource("META-INF/persistence.xml", "persistence.xml")
-// .addManifestResource(new ByteArrayAsset(new byte[0]), "beans.xml");
-// return jar;
- // WebArchive does work in all cases (except JBoss AS still breaks with EJBs)
- WebArchive war = ShrinkWrap.create("test.war", WebArchive.class)
- .addPackage(HotelSearch.class.getPackage())
- .addPackage(Hotel.class.getPackage())
- .addClasses(NoOpLogger.class)
- .addLibraries(
- MavenArtifactResolver.resolve("joda-time:joda-time:1.6"),
- MavenArtifactResolver.resolve("org.jboss.seam.international:seam-international-api:3.0.0.Alpha1"),
- MavenArtifactResolver.resolve("org.jboss.seam.international:seam-international:3.0.0.Alpha1")
- )
- .addWebResource("META-INF/persistence.xml", "classes/META-INF/persistence.xml")
- .addWebResource(new ByteArrayAsset(new byte[0]), "beans.xml");
- return war;
- }
-
- @Inject UserTransaction utx;
- @PersistenceContext EntityManager em;
- @Inject SearchCriteria criteria;
- @Inject HotelSearch hotelSearch;
- @Inject Instance<List<Hotel>> hotelsInstance;
-
- public void prepareSeedData() throws Exception
- {
- utx.begin();
- em.joinTransaction();
- em.createQuery("delete from Hotel").executeUpdate();
- em.persist(new Hotel("Doubletree Atlanta-Buckhead", "3342 Peachtree Road NE", "Atlanta", "GA", "30326", "USA"));
- utx.commit();
- }
-
- @Test
- public void testSearch() throws Exception
- {
- prepareSeedData();
-
- criteria.setQuery("atlanta");
- hotelSearch.find();
- List<Hotel> hotels = hotelsInstance.get();
- Assert.assertEquals(1, hotels.size());
- Assert.assertEquals(hotels.get(0).getName(), "Doubletree Atlanta-Buckhead");
-
- criteria.setQuery("boston");
- hotelSearch.find();
- hotels = hotelsInstance.get();
- Assert.assertEquals(0, hotels.size());
- }
-
-}
More information about the seam-commits
mailing list