[seam-commits] Seam SVN: r13166 - in examples/trunk/booking-simplified/src: main/java/org/jboss/seam/examples/booking/model and 7 other directories.

seam-commits at lists.jboss.org seam-commits at lists.jboss.org
Tue Jun 15 16:53:33 EDT 2010


Author: lincolnthree
Date: 2010-06-15 16:53:32 -0400 (Tue, 15 Jun 2010)
New Revision: 13166

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/model/User.java
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/MockIdentity.java
   examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/setup/ApplicationSetupBean.java
   examples/trunk/booking-simplified/src/main/resources/META-INF/persistence.xml
   examples/trunk/booking-simplified/src/main/resources/messages.properties
   examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml
   examples/trunk/booking-simplified/src/main/webapp/search.xhtml
   examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java
Log:
Removed search button - updated identity to display messages on events.

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-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/account/AccountProducerBean.java	2010-06-15 20:53:32 UTC (rev 13166)
@@ -9,6 +9,7 @@
 import javax.persistence.PersistenceContext;
 
 import org.jboss.seam.examples.booking.model.User;
+import org.jboss.seam.examples.booking.security.MockCredentials;
 import org.slf4j.Logger;
 
 /**
@@ -23,13 +24,20 @@
    @PersistenceContext
    private EntityManager em;
 
+   @Inject
+   MockCredentials credentials;
+
    @Produces
    @Registered
    @Named("currentUser")
    @SessionScoped
    public User getCurrentAccount()
    {
-      log.info("Producing canned User");
-      return em.find(User.class, "dan");
+      User result = em.find(User.class, credentials.getUsername());
+      if (result == null)
+      {
+         result = new User();
+      }
+      return result;
    }
 }

Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/model/User.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/model/User.java	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/model/User.java	2010-06-15 20:53:32 UTC (rev 13166)
@@ -25,23 +25,26 @@
 
 import java.io.Serializable;
 
+import javax.enterprise.inject.Typed;
 import javax.persistence.Entity;
 import javax.persistence.Id;
 import javax.persistence.Table;
-
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Pattern;
 import javax.validation.constraints.Size;
 
 /**
- * <p><strong>User</strong> is the model/entity class that represents a customer
- * who may book a hotel.</p>
- *
+ * <p>
+ * <strong>User</strong> is the model/entity class that represents a customer
+ * who may book a hotel.
+ * </p>
+ * 
  * @author Gavin King
  * @author Dan Allen
  */
 @Entity
 @Table(name = "customer")
+ at Typed()
 public class User implements Serializable
 {
    private String username;
@@ -52,13 +55,13 @@
    {
    }
 
-   public User(String name, String username)
+   public User(final String name, final String username)
    {
       this.name = name;
       this.username = username;
    }
 
-   public User(String name, String username, String password)
+   public User(final String name, final String username, final String password)
    {
       this(name, username);
       this.password = password;
@@ -71,7 +74,7 @@
       return name;
    }
 
-   public void setName(String name)
+   public void setName(final String name)
    {
       this.name = name;
    }
@@ -83,7 +86,7 @@
       return password;
    }
 
-   public void setPassword(String password)
+   public void setPassword(final String password)
    {
       this.password = password;
    }
@@ -97,7 +100,7 @@
       return username;
    }
 
-   public void setUsername(String username)
+   public void setUsername(final String username)
    {
       this.username = username;
    }

Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/MockIdentity.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/MockIdentity.java	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/security/MockIdentity.java	2010-06-15 20:53:32 UTC (rev 13166)
@@ -29,6 +29,9 @@
 import javax.inject.Named;
 import javax.servlet.http.HttpSession;
 
+import org.jboss.seam.international.status.Messages;
+import org.jboss.seam.international.status.builder.BundleKey;
+
 /**
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  * 
@@ -42,6 +45,12 @@
    @Inject
    FacesContext context;
 
+   @Inject
+   Messages messages;
+
+   @Inject
+   MockCredentials credentials;
+
    public boolean isLoggedIn()
    {
       return loggedIn;
@@ -54,12 +63,20 @@
 
    public void login()
    {
-      loggedIn = true;
+      if ((credentials.getUsername() != null) && !"".equals(credentials.getUsername().trim()))
+      {
+         loggedIn = true;
+         messages.info(new BundleKey("messages.properties", "identity.loggedIn"));
+      }
+      else
+      {
+         messages.info(new BundleKey("messages.properties", "identity.loginFailed"));
+      }
    }
 
    public void logout()
    {
-      loggedIn = true;
+      loggedIn = false;
       HttpSession session = (HttpSession) context.getExternalContext().getSession(true);
       session.invalidate();
    }

Modified: examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/setup/ApplicationSetupBean.java
===================================================================
--- examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/setup/ApplicationSetupBean.java	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/java/org/jboss/seam/examples/booking/setup/ApplicationSetupBean.java	2010-06-15 20:53:32 UTC (rev 13166)
@@ -5,6 +5,7 @@
 
 import javax.ejb.Stateless;
 import javax.enterprise.event.Observes;
+import javax.enterprise.inject.Alternative;
 import javax.faces.event.PostConstructApplicationEvent;
 import javax.inject.Inject;
 import javax.persistence.EntityManager;
@@ -20,6 +21,7 @@
  * @author <a href="mailto:lincolnbaxter at gmail.com">Lincoln Baxter, III</a>
  */
 @Stateless
+ at Alternative
 public class ApplicationSetupBean implements SetupBean
 {
    @PersistenceContext

Modified: examples/trunk/booking-simplified/src/main/resources/META-INF/persistence.xml
===================================================================
--- examples/trunk/booking-simplified/src/main/resources/META-INF/persistence.xml	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/resources/META-INF/persistence.xml	2010-06-15 20:53:32 UTC (rev 13166)
@@ -5,9 +5,9 @@
    version="1.0">
    <persistence-unit name="booking">
 <!--      <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>-->
-      <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>jdbc/__default</jta-data-source>
       <!--
+      <provider>org.hibernate.ejb.HibernatePersistence</provider>
       <jta-data-source>java:/DefaultDS</jta-data-source>
       <jta-data-source>jdbc/__arquillian</jta-data-source>
       -->

Modified: examples/trunk/booking-simplified/src/main/resources/messages.properties
===================================================================
--- examples/trunk/booking-simplified/src/main/resources/messages.properties	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/resources/messages.properties	2010-06-15 20:53:32 UTC (rev 13166)
@@ -9,3 +9,6 @@
 account.usernameTaken=The username '{0}' is already taken. Please choose another username.
 registration.registered=You have been successfully registered as the user {0}!
 registration.invalid=Invalid registration. Please correct the errors and try again.
+identity.loggedOut=You have successfully logged out.
+identity.loggedIn=You've logged in as {0}.
+identity.loginFailed=Invalid username or password.

Modified: examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/webapp/WEB-INF/beans.xml	2010-06-15 20:53:32 UTC (rev 13166)
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8"?>
-<beans xmlns="http://java.sun.com/xml/ns/javaee"
-   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-   xsi:schemaLocation="
-      http://java.sun.com/xml/ns/javaee
-      http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
-   <interceptors>
-      <class>org.jboss.seam.faces.context.conversation.ConversationBoundaryInterceptor</class>
-   </interceptors>
+<beans 	xmlns="http://java.sun.com/xml/ns/javaee" 
+		xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+		xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
+							http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
+
+	<alternatives>
+		<class>org.jboss.seam.examples.booking.setup.ApplicationSetupBean</class>
+	</alternatives>
 </beans>
\ No newline at end of file

Modified: examples/trunk/booking-simplified/src/main/webapp/search.xhtml
===================================================================
--- examples/trunk/booking-simplified/src/main/webapp/search.xhtml	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/main/webapp/search.xhtml	2010-06-15 20:53:32 UTC (rev 13166)
@@ -39,10 +39,6 @@
                   <f:ajax event="keyup" listener="#{hotelSearch.find}" render=":searchResults" onevent="controlSpinner"/>
                </h:inputText>
                #{' '}
-               <h:commandButton id="findHotels" value="Find Hotels" action="#{hotelSearch.find}">
-                  <f:ajax execute="query" render=":searchResults" onevent="controlSpinner"/>
-               </h:commandButton>
-               #{' '}
                <span id="activity" style="display: none;"><h:graphicImage id="spinner" value="/img/spinner.gif"/></span>
                <br/>
                <h:outputLabel id="lblPageSize" for="pageSize" value="Maximum results:"/>

Modified: 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	2010-06-15 20:48:34 UTC (rev 13165)
+++ examples/trunk/booking-simplified/src/test/java/org/jboss/seam/examples/booking/booking/BookingAgentTest.java	2010-06-15 20:53:32 UTC (rev 13166)
@@ -25,9 +25,6 @@
 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;
@@ -38,31 +35,26 @@
 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");
+   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;
+   @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 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();
@@ -74,9 +66,10 @@
    public void testBookHotel() throws Exception
    {
       prepareSeedData();
-      ConversationContext cc = Container.instance().services().get(ContextLifecycle.class).getConversationContext();
-      cc.setBeanStore(new HashMapBeanStore());
-      cc.setActive(true);
+      // ConversationContext cc =
+      // Container.instance().services().get(ContextLifecycle.class).getConversationContext();
+      // cc.setBeanStore(new HashMapBeanStore());
+      // cc.setActive(true);
 
       bookingAgent.selectHotel(em.find(Hotel.class, 1l));
       bookingAgent.bookHotel();
@@ -92,7 +85,9 @@
       Assert.assertEquals(1, em.createQuery("select b from Booking b").getResultList().size());
    }
 
-   @Produces @Registered User getRegisteredUser()
+   @Produces
+   @Registered
+   User getRegisteredUser()
    {
       return em.find(User.class, "ike");
    }
@@ -100,13 +95,15 @@
    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() {
+      protected Map<String, ContextualInstance<? extends Object>> delegate()
+      {
          return delegate;
       }
    }



More information about the seam-commits mailing list