[jboss-svn-commits] JBL Code SVN: r37233 - in labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app: src/main and 7 other directories.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Tue Jul 5 08:04:13 EDT 2011


Author: tomjenkinson
Date: 2011-07-05 08:04:12 -0400 (Tue, 05 Jul 2011)
New Revision: 37233

Added:
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/CustomerManager.java
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/ManagedBeanCustomerManager.java
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/beans.xml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/faces-config.xml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/addCustomer.xhtml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/count.xhtml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/customers.xhtml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/duplicate.xhtml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/index.html
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/template.xhtml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestManagedBeanCustomerManager.java
Removed:
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/servlet/
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestSimpleServlet.java
Modified:
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/pom.xml
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJB.java
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJBImpl.java
   labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/txoj/AtomicObject.java
Log:
JBTM-854 updated to use JSF rather than a raw servlet

Modified: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/pom.xml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/pom.xml	2011-07-05 08:59:56 UTC (rev 37232)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/pom.xml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -22,6 +22,22 @@
       </snapshots>
     </repository>
   </repositories>
+  <pluginRepositories>
+    <pluginRepository>
+      <id>jboss-public-repository-group</id>
+      <name>JBoss Public Maven Repository Group</name>
+      <url>http://repository.jboss.org/nexus/content/groups/public-jboss/</url>
+      <layout>default</layout>
+      <releases>
+        <enabled>true</enabled>
+        <updatePolicy>never</updatePolicy>
+      </releases>
+      <snapshots>
+        <enabled>true</enabled>
+        <updatePolicy>never</updatePolicy>
+      </snapshots>
+    </pluginRepository>
+  </pluginRepositories>
 
   <properties>
     <!-- For arquillian -->
@@ -29,6 +45,7 @@
   </properties>
 
   <build>
+      <finalName>${pom.artifactId}</finalName>
     <plugins>
       <plugin>
         <artifactId>maven-war-plugin</artifactId>
@@ -42,19 +59,39 @@
           </archive>
         </configuration>
       </plugin>
+      <!-- JBoss AS plugin to deploy war as a convenience -->
+      <plugin>
+        <groupId>org.jboss.as.plugins</groupId>
+        <artifactId>jboss-as-maven-plugin</artifactId>
+        <version>7.0.0.CR1</version>
+      </plugin>
+         <!-- Compiler plugin enforces Java 1.6 compatibility and activates 
+            annotation processors -->
+         <plugin>
+            <artifactId>maven-compiler-plugin</artifactId>
+            <configuration>
+               <source>1.6</source>
+               <target>1.6</target>
+            </configuration>
+         </plugin>
     </plugins>
   </build>
 
+  <dependencyManagement>
+    <dependencies>
+      <!-- Define the version of JBoss' Java EE 6 APIs we want to import. Any dependencies from org.jboss.spec will have their version defined by this BOM -->
+      <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) of artifacts. We use this here so that we always get the correct versions of artifacts. Here we use the jboss-javaee-web-6.0 stack (you can read this as the JBoss stack of the Java EE Web Profile 6 APIs), and we use version 2.0.0.Beta1 which is the latest release of the stack. You can actually use this stack with any version of JBoss AS that implements Java EE 6, not just JBoss AS 7! -->
+      <dependency>
+        <groupId>org.jboss.spec</groupId>
+        <artifactId>jboss-javaee-web-6.0</artifactId>
+        <version>2.0.0.CR1</version>
+        <type>pom</type>
+        <scope>import</scope>
+      </dependency>
+    </dependencies>
+  </dependencyManagement>
+
   <dependencies>
-    <!-- Include the JBoss' Java EE 6 APIs -->
-    <!-- JBoss distributes a complete set of Java EE 6 APIs including a Bill of Materials (BOM). A BOM specifies the versions of a "stack" (or a collection) of artifacts. We use this here so that we always get the correct versions of artifacts. Here we use the jboss-javaee-web-6.0 stack (you can read this as the JBoss stack of the Java EE 6 Web Profile APIs), and we use version 2.0.0.Beta1 which is the latest release of the stack. You can actually use this stack with any version of JBoss AS that implements Java EE 6, not just JBoss AS 7! -->
-    <dependency>
-      <groupId>org.jboss.spec</groupId>
-      <artifactId>jboss-javaee-web-6.0</artifactId>
-      <version>2.0.0.CR1</version>
-      <type>pom</type>
-      <scope>provided</scope>
-    </dependency>
 
     <dependency>
       <groupId>org.jboss.ejb3</groupId>
@@ -69,6 +106,34 @@
       </exclusions>
     </dependency>
 
+    <!-- Import the JPA API, we use provided scope as the API is included in JBoss AS 7 -->
+    <dependency>
+      <groupId>org.jboss.spec.javax.transaction</groupId>
+      <artifactId>jboss-transaction-api_1.1_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Import the JSF API, we use provided scope as the API is included in JBoss AS 7 -->
+    <dependency>
+      <groupId>org.jboss.spec.javax.faces</groupId>
+      <artifactId>jboss-jsf-api_2.0_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Import the JPA API, we use provided scope as the API is included in JBoss AS 7 -->
+    <dependency>
+      <groupId>org.hibernate.javax.persistence</groupId>
+      <artifactId>hibernate-jpa-2.0-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <!-- Import the EJB API, we use provided scope as the API is included in JBoss AS 7 -->
+    <dependency>
+      <groupId>org.jboss.spec.javax.ejb</groupId>
+      <artifactId>jboss-ejb-api_3.1_spec</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
     <!-- For the txoj -->
     <dependency>
       <groupId>org.jboss.jbossts</groupId>
@@ -82,6 +147,15 @@
         </exclusion>
       </exclusions>
     </dependency>
+    
+    <!-- Import the injection annotations -->
+    <dependency>
+      <groupId>javax.inject</groupId>
+      <artifactId>javax.inject</artifactId>
+      <version>1</version>
+      <scope>provided</scope>
+    </dependency>
+    
 
     <!-- We will provide some tests to check the quickstart deploys ok -->
     <dependency>

Modified: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJB.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJB.java	2011-07-05 08:59:56 UTC (rev 37232)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJB.java	2011-07-05 12:04:12 UTC (rev 37233)
@@ -20,7 +20,14 @@
  */
 package org.jboss.narayana.quickstarts.ejb;
 
+import java.util.List;
+
 import javax.naming.NamingException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
 
 /**
  * A simple example to show some transactional business logic.
@@ -31,8 +38,14 @@
 	 * 
 	 * @return
 	 * @throws NamingException
+	 * @throws Exception
 	 */
-	public int createCustomer(String name) throws NamingException;
+	public int createCustomer(String name) throws NamingException, Exception;
 
-	public String listCustomers() throws NamingException;
+	public List<Customer> listCustomers() throws NamingException,
+			NotSupportedException, SystemException, SecurityException,
+			IllegalStateException, RollbackException, HeuristicMixedException,
+			HeuristicRollbackException;
+
+	public int getCustomerCount() throws Exception;
 }

Modified: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJBImpl.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJBImpl.java	2011-07-05 08:59:56 UTC (rev 37232)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/ejb/SimpleEJBImpl.java	2011-07-05 12:04:12 UTC (rev 37233)
@@ -29,19 +29,32 @@
 import javax.naming.NamingException;
 import javax.persistence.EntityManager;
 import javax.persistence.PersistenceContext;
-import javax.transaction.UserTransaction;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
 
+import org.jboss.narayana.quickstarts.txoj.AtomicObject;
+
 @Stateless
 public class SimpleEJBImpl implements SimpleEJB {
+
+	private AtomicObject atomicObject = new AtomicObject();
+
 	@PersistenceContext(name = "my_persistence_ctx")
 	EntityManager em;
 
 	@TransactionAttribute(TransactionAttributeType.REQUIRED)
-	public int createCustomer(String name) throws NamingException {
-		UserTransaction tx = (UserTransaction) new InitialContext()
-				.lookup("java:comp/UserTransaction");
+	public int createCustomer(String name) throws Exception {
 		System.out.println("createCustomer transaction is identified as: "
-				+ tx.toString());
+				+ new InitialContext().lookup("java:comp/UserTransaction")
+						.toString());
+
+		// Can do this first because if there is a duplicate it will be rolled
+		// back for us
+		atomicObject.incr(1);
+
 		Customer c1 = new Customer();
 		c1.setName(name);
 		em.persist(c1);
@@ -50,26 +63,22 @@
 	}
 
 	@TransactionAttribute(TransactionAttributeType.REQUIRED)
-	public String listCustomers() throws NamingException {
-		UserTransaction tx = (UserTransaction) new InitialContext()
-				.lookup("java:comp/UserTransaction");
-		System.out.println("listIds transaction is identified as: "
-				+ tx.toString());
-		final List<Customer> list = em.createQuery("select c from Customer c")
-				.getResultList();
-		StringBuffer toReturn = new StringBuffer("customers: ");
-		boolean added = false;
-		for (Customer customer : list) {
-			toReturn.append(customer.getId());
-			toReturn.append("/");
-			toReturn.append(customer.getName());
-			toReturn.append(", ");
-			added = true;
-		}
-		if (added) {
-			return toReturn.substring(0, toReturn.length() - 2);
-		} else {
-			return toReturn.toString();
-		}
+	@SuppressWarnings("unchecked")
+	public List<Customer> listCustomers() throws NamingException,
+			NotSupportedException, SystemException, SecurityException,
+			IllegalStateException, RollbackException, HeuristicMixedException,
+			HeuristicRollbackException {
+		System.out.println("listCustomers transaction is identified as: "
+				+ new InitialContext().lookup("java:comp/UserTransaction")
+						.toString());
+		return em.createQuery("select c from Customer c").getResultList();
 	}
+
+	@TransactionAttribute(TransactionAttributeType.REQUIRED)
+	public int getCustomerCount() throws Exception {
+		System.out.println("getCustomerCount transaction is identified as: "
+				+ new InitialContext().lookup("java:comp/UserTransaction")
+						.toString());
+		return atomicObject.get();
+	}
 }

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/CustomerManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/CustomerManager.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/CustomerManager.java	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,22 @@
+package org.jboss.narayana.quickstarts.jsf;
+
+import java.util.List;
+
+import javax.naming.NamingException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+
+import org.jboss.narayana.quickstarts.ejb.Customer;
+
+public interface CustomerManager {
+
+	public List<Customer> getCustomers() throws SecurityException, IllegalStateException, NamingException, NotSupportedException, SystemException, RollbackException, HeuristicMixedException, HeuristicRollbackException;
+
+	public String addCustomer(String name);
+
+	public int getCustomerCount() throws Exception;
+
+}
\ No newline at end of file

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/ManagedBeanCustomerManager.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/ManagedBeanCustomerManager.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/jsf/ManagedBeanCustomerManager.java	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,59 @@
+package org.jboss.narayana.quickstarts.jsf;
+
+import java.util.List;
+
+import javax.ejb.EJB;
+import javax.faces.bean.RequestScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.naming.NamingException;
+import javax.transaction.HeuristicMixedException;
+import javax.transaction.HeuristicRollbackException;
+import javax.transaction.NotSupportedException;
+import javax.transaction.RollbackException;
+import javax.transaction.SystemException;
+import javax.transaction.UserTransaction;
+
+import org.jboss.narayana.quickstarts.ejb.Customer;
+import org.jboss.narayana.quickstarts.ejb.SimpleEJB;
+
+ at Named("customerManager")
+ at RequestScoped
+public class ManagedBeanCustomerManager implements CustomerManager {
+
+	@EJB
+	private SimpleEJB simpleEJB;
+
+	@Inject
+	private UserTransaction utx;
+
+	public List<Customer> getCustomers() throws SecurityException,
+			IllegalStateException, NamingException, NotSupportedException,
+			SystemException, RollbackException, HeuristicMixedException,
+			HeuristicRollbackException {
+		System.out.println("Getting customers");
+		return simpleEJB.listCustomers();
+	}
+
+	public String addCustomer(String name) {
+		System.out.println("Adding customer: " + name);
+		try {
+			utx.begin();
+			System.out.println("Creating customer");
+			simpleEJB.createCustomer(name);
+			utx.commit();
+			System.out.println("Created customer");
+			return "customerAdded";
+		} catch (Exception e) {
+			e.printStackTrace();
+			// Transaction will be marked rollback only anyway utx.rollback();
+			return "customerDuplicate";
+		}
+	}
+
+	public int getCustomerCount() throws Exception {
+		System.out.println("Getting count");
+		int count = simpleEJB.getCustomerCount();
+		return count;
+	}
+}

Modified: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/txoj/AtomicObject.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/txoj/AtomicObject.java	2011-07-05 08:59:56 UTC (rev 37232)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/java/org/jboss/narayana/quickstarts/txoj/AtomicObject.java	2011-07-05 12:04:12 UTC (rev 37233)
@@ -43,6 +43,7 @@
 
 	public AtomicObject() {
 		this(ObjectModel.SINGLE);
+		System.out.println("Creating new atomic object");
 	}
 
 	public AtomicObject(int om) {

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/beans.xml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/beans.xml	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/beans.xml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,11 @@
+<!-- Marker file indicating CDI should be enabled -->
+<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">
+
+      <!-- Uncomment this alternative to see EJB declarative transactions in use -->
+<!--       <alternatives> -->
+<!--          <class>org.jboss.as.quickstarts.login.EJBUserManager</class> -->
+<!--       </alternatives> -->
+</beans>
\ No newline at end of file

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/faces-config.xml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/faces-config.xml	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/WEB-INF/faces-config.xml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,21 @@
+<!-- Marker file indicating JSF should be enabled -->
+
+<faces-config version="2.0" 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/web-facesconfig_2_0.xsd">
+
+  <navigation-rule>
+    <from-view-id>/addCustomer.xhtml</from-view-id>
+    <navigation-case>
+      <from-action>#{customerManager.addCustomer(name)}</from-action>
+      <from-outcome>customerAdded</from-outcome>
+      <to-view-id>/customers.xhtml</to-view-id>
+      <redirect />
+    </navigation-case>
+    <navigation-case>
+      <from-action>#{customerManager.addCustomer(name)}</from-action>
+      <from-outcome>customerDuplicate</from-outcome>
+      <to-view-id>/duplicate.xhtml</to-view-id>
+      <redirect />
+    </navigation-case>
+  </navigation-rule>
+
+</faces-config>

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/addCustomer.xhtml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/addCustomer.xhtml	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/addCustomer.xhtml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,23 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core">
+
+<ui:composition template="template.xhtml">
+	<ui:define name="content">
+		<h:messages />
+		<h:form id="addCustomerForm">
+			<h:panelGrid columns="3">
+				<h:outputLabel for="name">Name:</h:outputLabel>
+				<h:inputText value="#{name}" />
+				<h:commandButton id="add" value="Add"
+					action="#{customerManager.addCustomer(name)}">
+				</h:commandButton>
+			</h:panelGrid>
+		</h:form>
+		<h:link outcome="/customers.xhtml">List customers</h:link>
+		<h:link outcome="/count.xhtml">List count</h:link>
+	</ui:define>
+</ui:composition>
+</html>

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/count.xhtml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/count.xhtml	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/count.xhtml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core">
+
+<ui:composition template="template.xhtml">
+	<ui:define name="content">
+		<Count />
+		<h1>Customer Count</h1>
+		<h:outputText value="Count this run: #{customerManager.customerCount}" />
+		<a href="javascript:history.back(-1)">Go Back</a>
+	</ui:define>
+</ui:composition>
+</html>

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/customers.xhtml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/customers.xhtml	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/customers.xhtml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core">
+
+<ui:composition template="template.xhtml">
+	<ui:define name="content">
+		<h:messages />
+		<h1>List of customers</h1>
+		<h:dataTable value="#{customerManager.customers}" var="u">
+			<h:column>
+				<f:facet name="header">
+               Name
+            </f:facet>
+				<h:outputText value="#{u.name}" />
+			</h:column>
+			<h:column>
+				<f:facet name="header">
+               Id
+            </f:facet>
+				<h:outputText value="#{u.id}" />
+			</h:column>
+		</h:dataTable>
+		<a href="javascript:history.back(-1)">Go Back</a>
+	</ui:define>
+</ui:composition>
+</html>

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/duplicate.xhtml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/duplicate.xhtml	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/duplicate.xhtml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,15 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core">
+
+<ui:composition template="template.xhtml">
+	<ui:define name="content">
+		<Count />
+		<h1>Customer Already Existed</h1>
+		<h:outputText value="Customer already existed: #{name}" />
+		<a href="javascript:history.back(-1)">Go Back</a>
+	</ui:define>
+</ui:composition>
+</html>

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/index.html
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/index.html	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/index.html	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,7 @@
+<!-- Plain HTML page that kicks us into the app -->
+
+<html>
+<head>
+<meta http-equiv="Refresh" content="0; URL=addCustomer.jsf">
+</head>
+</html>
\ No newline at end of file

Added: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/template.xhtml
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/template.xhtml	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/main/webapp/template.xhtml	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,32 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml"
+	xmlns:ui="http://java.sun.com/jsf/facelets"
+	xmlns:h="http://java.sun.com/jsf/html"
+	xmlns:f="http://java.sun.com/jsf/core">
+
+<!-- The template for our app, defines some regions and imports styles -->
+
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
+<title>Customer Database</title>
+<ui:insert name="head" />
+</head>
+
+<body>
+
+	<h1>Customer Database</h1>
+	<div id="container">
+		<div id="header"></div>
+
+		<div id="sidebar"></div>
+
+		<div id="content">
+			<ui:insert name="content" />
+		</div>
+
+		<br style="clear: both" />
+	</div>
+
+</body>
+</html>
+

Copied: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestManagedBeanCustomerManager.java (from rev 37232, labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestSimpleServlet.java)
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestManagedBeanCustomerManager.java	                        (rev 0)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestManagedBeanCustomerManager.java	2011-07-05 12:04:12 UTC (rev 37233)
@@ -0,0 +1,142 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2011, Red Hat, Inc. and/or its affiliates,
+ * and individual contributors as indicated by the @author tags.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+ * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
+ * You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA  02110-1301, USA.
+ *
+ * (C) 2011,
+ * @author JBoss, by Red Hat.
+ */
+import static org.junit.Assert.assertTrue;
+
+import java.util.List;
+
+import javax.inject.Inject;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.narayana.quickstarts.ejb.Customer;
+import org.jboss.narayana.quickstarts.ejb.SimpleEJB;
+import org.jboss.narayana.quickstarts.ejb.SimpleEJBImpl;
+import org.jboss.narayana.quickstarts.jsf.CustomerManager;
+import org.jboss.narayana.quickstarts.jsf.ManagedBeanCustomerManager;
+import org.jboss.narayana.quickstarts.txoj.AtomicObject;
+import org.jboss.shrinkwrap.api.ArchivePaths;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.asset.StringAsset;
+import org.jboss.shrinkwrap.api.spec.WebArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+ at RunWith(Arquillian.class)
+public class TestManagedBeanCustomerManager {
+	@Inject
+	private ManagedBeanCustomerManager managedBeanCustomerManager;
+
+	@Deployment
+	public static WebArchive createDeployment() {
+		WebArchive archive = ShrinkWrap
+				.create(WebArchive.class, "test.war")
+				.addClasses(SimpleEJB.class, SimpleEJBImpl.class,
+						Customer.class)
+				.addClasses(AtomicObject.class)
+				.addClasses(CustomerManager.class,
+						ManagedBeanCustomerManager.class)
+				.addAsResource("META-INF/persistence.xml",
+						"META-INF/persistence.xml")
+				.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
+		archive.delete(ArchivePaths.create("META-INF/MANIFEST.MF"));
+
+		// Need to make sure we add the arquillian-service and msc as a
+		// dependency
+		final String ManifestMF = "Manifest-Version: 1.0\n"
+				+ "Dependencies: org.jboss.modules,deployment.arquillian-service,org.jboss.msc,org.jboss.jts\n";
+		archive.setManifest(new StringAsset(ManifestMF));
+
+		return archive;
+	}
+
+	@Test
+	public void checkListCustomers() throws Exception {
+
+		// Create a customer
+		managedBeanCustomerManager.addCustomer("Test"
+				+ System.currentTimeMillis());
+		List<Customer> firstList = managedBeanCustomerManager.getCustomers();
+		// Create a different customer
+		managedBeanCustomerManager.addCustomer("Test"
+				+ System.currentTimeMillis());
+		List<Customer> secondList = managedBeanCustomerManager.getCustomers();
+
+		// Check that the list size increased
+		assertTrue(firstList.size() < secondList.size());
+	}
+
+	@Test
+	public void checkCustomerCount() throws Exception {
+		int response = -1;
+		int size = managedBeanCustomerManager.getCustomerCount();
+
+		// Create a new customer
+		managedBeanCustomerManager.addCustomer("Test"
+				+ System.currentTimeMillis());
+
+		// Get the initial number of customers
+		response = managedBeanCustomerManager.getCustomerCount();
+		assertTrue("" + response, response == size + 1);
+		size = response;
+
+		// Create a new customer
+		managedBeanCustomerManager.addCustomer("Test"
+				+ System.currentTimeMillis());
+
+		// Check that one extra customer was created
+		response = managedBeanCustomerManager.getCustomerCount();
+		assertTrue("" + response, response == size + 1);
+		size = response;
+	}
+
+	@Test
+	public void testCustomerCountInPresenceOfRollback() throws Exception {
+		int response = -1;
+		int size = managedBeanCustomerManager.getCustomerCount();
+
+		String firstCustomerName = "Test" + System.currentTimeMillis();
+		// Create a new customer
+		managedBeanCustomerManager.addCustomer(firstCustomerName);
+
+		// Get the initial number of customers
+		response = managedBeanCustomerManager.getCustomerCount();
+		assertTrue("" + response, response == size + 1);
+		size = response;
+
+		// Create a new customer
+		managedBeanCustomerManager.addCustomer(firstCustomerName);
+
+		// Check that no extra customers were created
+		response = managedBeanCustomerManager.getCustomerCount();
+		assertTrue("" + response, response == size);
+		size = response;
+
+		// Create a new customer
+		managedBeanCustomerManager.addCustomer("Test"
+				+ System.currentTimeMillis());
+
+		// Check that one extra customer was created
+		response = managedBeanCustomerManager.getCustomerCount();
+		assertTrue("" + response, response == size + 1);
+		size = response;
+	}
+}
\ No newline at end of file

Deleted: labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestSimpleServlet.java
===================================================================
--- labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestSimpleServlet.java	2011-07-05 08:59:56 UTC (rev 37232)
+++ labs/jbosstm/trunk/ArjunaJTA/quickstarts/jee_transactional_app/src/test/java/TestSimpleServlet.java	2011-07-05 12:04:12 UTC (rev 37233)
@@ -1,185 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2011, Red Hat, Inc. and/or its affiliates,
- * and individual contributors as indicated by the @author tags.
- * See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- * This copyrighted material is made available to anyone wishing to use,
- * modify, copy, or redistribute it subject to the terms and conditions
- * of the GNU Lesser General Public License, v. 2.1.
- * This program is distributed in the hope that it will be useful, but WITHOUT A
- * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
- * PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more details.
- * You should have received a copy of the GNU Lesser General Public License,
- * v.2.1 along with this distribution; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
- * MA  02110-1301, USA.
- *
- * (C) 2011,
- * @author JBoss, by Red Hat.
- */
-import static org.junit.Assert.assertTrue;
-
-import java.lang.reflect.Field;
-
-import javax.ejb.EJB;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.narayana.quickstarts.ejb.Customer;
-import org.jboss.narayana.quickstarts.ejb.SimpleEJB;
-import org.jboss.narayana.quickstarts.ejb.SimpleEJBImpl;
-import org.jboss.narayana.quickstarts.servlet.SimpleServlet;
-import org.jboss.narayana.quickstarts.txoj.AtomicObject;
-import org.jboss.shrinkwrap.api.ArchivePaths;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.asset.StringAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
- at RunWith(Arquillian.class)
-public class TestSimpleServlet {
-	@EJB(lookup = "java:module/SimpleEJBImpl")
-	private SimpleEJB simpleEJB;
-
-	@Deployment
-	public static WebArchive createDeployment() {
-		WebArchive archive = ShrinkWrap
-				.create(WebArchive.class, "test.war")
-				.addClasses(SimpleEJB.class, SimpleEJBImpl.class,
-						Customer.class)
-				.addClasses(AtomicObject.class)
-				.addClasses(SimpleServlet.class)
-				.addAsResource("META-INF/persistence.xml",
-						"META-INF/persistence.xml")
-				.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
-		archive.delete(ArchivePaths.create("META-INF/MANIFEST.MF"));
-
-		// Need to make sure we add the arquillian-service and msc as a
-		// dependency
-		final String ManifestMF = "Manifest-Version: 1.0\n"
-				+ "Dependencies: org.jboss.modules,deployment.arquillian-service,org.jboss.msc,org.jboss.jts\n";
-		archive.setManifest(new StringAsset(ManifestMF));
-
-		return archive;
-	}
-
-	@Test
-	public void checkListCustomers() throws SecurityException,
-			NoSuchFieldException, IllegalArgumentException,
-			IllegalAccessException {
-
-		// Declare the servlet outside the container
-		SimpleServlet servlet = new SimpleServlet();
-		Field field = servlet.getClass().getDeclaredField("simpleEJB");
-		field.setAccessible(true);
-		field.set(servlet, simpleEJB);
-		field.setAccessible(false);
-
-		// Create a customer
-		servlet.createCustomer("checkThatDoubleCallIncreasesListSize");
-		String firstList = servlet.listCustomers();
-		// Create a different customer
-		servlet.createCustomer("checkThatDoubleCallIncreasesListSize2");
-		String secondList = servlet.listCustomers();
-
-		// Check that the list size increased
-		assertTrue(firstList.length() < secondList.length());
-	}
-
-	@Test
-	public void testCustomerCount() throws Exception {
-		// Declare the servlet outside the container
-		SimpleServlet servlet = new SimpleServlet();
-		Field field = servlet.getClass().getDeclaredField("simpleEJB");
-		field.setAccessible(true);
-		field.set(servlet, simpleEJB);
-		field.setAccessible(false);
-
-		String toLookFor = "<p>Customers created this run: ";
-		String response = null;
-		int indexOf = -1;
-		String customersCreated = null;
-		int size = 0;
-		int newSize = -1;
-
-		// Create a new customer
-		servlet.createCustomer("testCustomerCount");
-
-		// Get the initial number of customers
-		response = servlet.getCustomerCount();
-		indexOf = response.indexOf(toLookFor);
-		customersCreated = response.substring(indexOf + toLookFor.length(),
-				response.indexOf("</p>", indexOf));
-		newSize = Integer.parseInt(customersCreated);
-		assertTrue(newSize == size + 1);
-		size = newSize;
-
-		// Create a new customer
-		servlet.createCustomer("testCustomerCount2");
-
-		// Check that one extra customer was created
-		response = servlet.getCustomerCount();
-		indexOf = response.indexOf(toLookFor);
-		customersCreated = response.substring(indexOf + toLookFor.length(),
-				response.indexOf("</p>", indexOf));
-		newSize = Integer.parseInt(customersCreated);
-		assertTrue(newSize == size + 1);
-		size = newSize;
-	}
-
-	@Test
-	public void testCustomerCountInPresenceOfRollback() throws Exception {
-		// Declare the servlet outside the container
-		SimpleServlet servlet = new SimpleServlet();
-		Field field = servlet.getClass().getDeclaredField("simpleEJB");
-		field.setAccessible(true);
-		field.set(servlet, simpleEJB);
-		field.setAccessible(false);
-
-		String toLookFor = "<p>Customers created this run: ";
-		String response = null;
-		int indexOf = -1;
-		String customersCreated = null;
-		int size = 0;
-		int newSize = -1;
-
-		// Create a new customer
-		servlet.createCustomer("testCustomerCountInPresenceOfRollback");
-
-		// Get the initial number of customers
-		response = servlet.getCustomerCount();
-		indexOf = response.indexOf(toLookFor);
-		customersCreated = response.substring(indexOf + toLookFor.length(),
-				response.indexOf("</p>", indexOf));
-		newSize = Integer.parseInt(customersCreated);
-		assertTrue(newSize == size + 1);
-		size = newSize;
-
-		// Create a new customer
-		servlet.createCustomer("testCustomerCountInPresenceOfRollback");
-
-		// Check that no extra customers were created
-		response = servlet.getCustomerCount();
-		indexOf = response.indexOf(toLookFor);
-		customersCreated = response.substring(indexOf + toLookFor.length(),
-				response.indexOf("</p>", indexOf));
-		newSize = Integer.parseInt(customersCreated);
-		assertTrue(newSize == size);
-		size = newSize;
-
-		// Create a new customer
-		servlet.createCustomer("testCustomerCountInPresenceOfRollback2");
-
-		// Check that one extra customer was created
-		response = servlet.getCustomerCount();
-		indexOf = response.indexOf(toLookFor);
-		customersCreated = response.substring(indexOf + toLookFor.length(),
-				response.indexOf("</p>", indexOf));
-		newSize = Integer.parseInt(customersCreated);
-		assertTrue(newSize == size + 1);
-		size = newSize;
-	}
-}
\ No newline at end of file



More information about the jboss-svn-commits mailing list