[jboss-cvs] JBossAS SVN: r99649 - in trunk/testsuite: src/main/org/jboss/test/ejb3 and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jan 20 04:31:22 EST 2010


Author: jaikiran
Date: 2010-01-20 04:31:22 -0500 (Wed, 20 Jan 2010)
New Revision: 99649

Added:
   trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/
   trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManager.java
   trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManagerBean.java
   trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/Calculator.java
   trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/unit/
   trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/unit/EJB31NoInterfaceViewTestCase.java
Modified:
   trunk/testsuite/imports/sections/ejb3.xml
Log:
JBAS-7636 EJB3.1 no-interface view tests

Modified: trunk/testsuite/imports/sections/ejb3.xml
===================================================================
--- trunk/testsuite/imports/sections/ejb3.xml	2010-01-20 09:27:43 UTC (rev 99648)
+++ trunk/testsuite/imports/sections/ejb3.xml	2010-01-20 09:31:22 UTC (rev 99649)
@@ -124,10 +124,21 @@
 		   </fileset>
 	   </jar>
    </target>
+	
+   <target name="ejb31nointerface" depends="compile">
+	   <mkdir dir="${build.lib}" />
+	   
+	   <jar destfile="${build.lib}/ejb31nointerface.jar">
+		   <fileset dir="${build.classes}">
+			   <include name="org/jboss/test/ejb3/nointerface/**" />
+		   </fileset>
+	   </jar>
+   </target>
 
+
    <target name="_jars-ejb3" depends="ejb3-servlet,jbas6161,jbas6239,
       jbas7526,
-      ejbthree1597,ejbthree7376, jboss51xsd">
+      ejbthree1597,ejbthree7376, jboss51xsd, ejb31nointerface">
       <mkdir dir="${build.lib}" />
 
       <!-- A jar with a simple ejb3 session -->

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManager.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManager.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManager.java	2010-01-20 09:31:22 UTC (rev 99649)
@@ -0,0 +1,33 @@
+/**
+ * 
+ */
+package org.jboss.test.ejb3.nointerface;
+
+/**
+ * AccountManager
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public interface AccountManager
+{
+   /**
+    * Credits the amount from the account corresponding to the
+    * <code>accountNumber</code>
+    * 
+    * @param accountNumber Account number
+    * @param amount Amount to be credited
+    * @return
+    */
+   int credit(long accountNumber, int amount);
+   
+   /**
+    * Debits the amount from the account corresponding to the
+    * <code>accountNumber</code>
+    * 
+    * @param accountNumber Account number
+    * @param amount Amount to be debited
+    * @return
+    */
+   int debit(long accountNumber, int amount);
+}
\ No newline at end of file

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManagerBean.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManagerBean.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/AccountManagerBean.java	2010-01-20 09:31:22 UTC (rev 99649)
@@ -0,0 +1,81 @@
+/**
+ * 
+ */
+package org.jboss.test.ejb3.nointerface;
+
+import javax.ejb.EJB;
+import javax.ejb.Remote;
+import javax.ejb.Stateful;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+
+import org.jboss.ejb3.annotation.RemoteBinding;
+
+
+
+/**
+ * AccountManagerBean
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateful
+ at Remote (AccountManager.class)
+ at RemoteBinding (jndiBinding = AccountManagerBean.JNDI_NAME)
+public class AccountManagerBean implements AccountManager
+{
+
+   /**
+    * JNDI name
+    */
+   public static final String JNDI_NAME = "AccountManagerRemoteView";
+   
+   /**
+    * Inject the no-interface view of the Calculator
+    */
+   @EJB
+   private Calculator simpleCalculator;
+
+   /**
+    * @see org.jboss.ejb3.nointerface.integration.test.common.AccountManager#credit(int)
+    */
+   @Override
+   public int credit(long accountNumber, int amount)
+   {
+      // get current account balance of this account number, from DB.
+      // But for this example let's just hardcode it
+      int currentBalance = 100;
+
+      Calculator calculator = null;
+      // lookup the no-interface view of the Calculator
+      // We could have used the injected Calculator too, but
+      // in this method we wanted to demonstrate how to lookup an no-interface view
+      try
+      {
+         Context context = new InitialContext();
+         calculator = (Calculator) context.lookup(Calculator.class.getSimpleName() + "/no-interface");
+      }
+      catch (NamingException ne)
+      {
+         throw new RuntimeException("Could not lookup no-interface view of calculator: ", ne);
+      }
+      return calculator.add(currentBalance, amount);
+
+   }
+
+   /**
+    * @see org.jboss.ejb3.nointerface.integration.test.common.AccountManager#debit(int)
+    */
+   @Override
+   public int debit(long accountNumber, int amount)
+   {
+      // get current account balance of this account number, from DB.
+      // But for this example let's just hardcode it
+      int currentBalance = 100;
+      
+      // let's use the injected calculator
+      return this.simpleCalculator.subtract(currentBalance, amount);
+   }
+
+}

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/Calculator.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/Calculator.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/Calculator.java	2010-01-20 09:31:22 UTC (rev 99649)
@@ -0,0 +1,26 @@
+/**
+ * 
+ */
+package org.jboss.test.ejb3.nointerface;
+
+import javax.ejb.Stateless;
+
+/**
+ * Calculator
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+ at Stateless
+public class Calculator
+{
+   public int subtract(int a, int b)
+   {
+      return a - b;
+   }
+
+   public int add(int a, int b)
+   {
+      return a + b;
+   }
+}

Added: trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/unit/EJB31NoInterfaceViewTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/unit/EJB31NoInterfaceViewTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/ejb3/nointerface/unit/EJB31NoInterfaceViewTestCase.java	2010-01-20 09:31:22 UTC (rev 99649)
@@ -0,0 +1,72 @@
+/**
+ * 
+ */
+package org.jboss.test.ejb3.nointerface.unit;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import junit.framework.Test;
+
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.ejb3.nointerface.AccountManager;
+import org.jboss.test.ejb3.nointerface.AccountManagerBean;
+import org.jboss.test.ejb3.nointerface.Calculator;
+
+/**
+ * EJB31NoInterfaceViewTestCase
+ * 
+ * Tests EJB3.1 no-interface view support
+ *
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class EJB31NoInterfaceViewTestCase extends JBossTestCase
+{
+
+   /**
+    * 
+    * @param name
+    */
+   public EJB31NoInterfaceViewTestCase(String name)
+   {
+      super(name);
+   }
+   
+   /**
+    * 
+    * @return
+    * @throws Exception
+    */
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(EJB31NoInterfaceViewTestCase.class, "ejb31nointerface.jar");
+   }
+   
+   /**
+    * Tests (indirect) access to a no-interface view bean ({@link Calculator})
+    * 
+    * @see Calculator and it's usage in {@link AccountManagerBean} 
+    * @throws Exception
+    */
+   public void testNoInterfaceViewAccess() throws Exception
+   {
+      Context ctx = new InitialContext();
+      AccountManager accountMgr = (AccountManager) ctx.lookup(AccountManagerBean.JNDI_NAME);
+      
+      long dummyAccountNumber = 123;
+      // credit 50 dollars (Note that the current balance is hard coded in the bean to 100)
+      // so after crediting, the current balance is going to be 150
+      int currentBalance = accountMgr.credit(dummyAccountNumber, 50);
+      
+      assertEquals("Unexpected account balance after credit", 150, currentBalance);
+      
+      // now let's debit 10 dollars (Note that the current balance is again hard coded in the bean to 100).
+      // So after debiting, the current balance is going to be 90
+      currentBalance = accountMgr.debit(dummyAccountNumber, 10);
+      
+      assertEquals("Unexpected account balance after debit", 90, currentBalance);
+   }
+   
+
+}




More information about the jboss-cvs-commits mailing list