diff --git a/ejb/stateful/src/main/java/org/javaee7/ejb/stateful/TestServlet.java b/ejb/stateful/src/main/java/org/javaee7/ejb/stateful/TestServlet.java
deleted file mode 100644
index 19f16c2ed..000000000
--- a/ejb/stateful/src/main/java/org/javaee7/ejb/stateful/TestServlet.java
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License"). You
- * may not use this file except in compliance with the License. You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt. See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license." If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above. However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-package org.javaee7.ejb.stateful;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import javax.inject.Inject;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author Arun Gupta
- */
-@WebServlet(urlPatterns = {"/TestServlet"})
-public class TestServlet extends HttpServlet {
- @Inject CartBean bean;;
-
- /**
- * Processes requests for both HTTP GET and POST
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
- out.println("");
- out.println("");
- out.println("
");
- out.println("Adding/Removing items from Stateful Bean (No Interface)");
- out.println("");
- out.println("");
- out.println("Adding/Removing items from Stateful Bean (No Interface)
");
- out.println("Adding items
");
- bean.addItem("apple");
- bean.addItem("banana");
- bean.addItem("mango");
- bean.addItem("kiwi");
- bean.addItem("passion fruit");
- out.println("added");
- out.println("Listing items
");
- out.println(bean.getItems());
- out.println("Removing item
");
- bean.removeItem("banana");
- out.println("removed");
- out.println("Listing items
");
- out.println(bean.getItems());
- out.println("");
- out.println("");
- }
- }
-
- //
- /**
- * Handles the HTTP GET method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
-
- /**
- * Handles the HTTP POST method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
-
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }//
-
-}
diff --git a/ejb/stateful/src/main/webapp/index.jsp b/ejb/stateful/src/main/webapp/index.jsp
deleted file mode 100644
index ee2c4087a..000000000
--- a/ejb/stateful/src/main/webapp/index.jsp
+++ /dev/null
@@ -1,57 +0,0 @@
-
-<%@page contentType="text/html" pageEncoding="UTF-8"%>
-
-
-
-
-
- EJB : Stateful
-
-
- EJB : Stateful
-
- Call beans no-interface
- and with-interface.
-
-
diff --git a/ejb/stateful/src/test/java/org/javaee7/ejb/stateful/CartBeanStatefulnessTest.java b/ejb/stateful/src/test/java/org/javaee7/ejb/stateful/CartBeanStatefulnessTest.java
new file mode 100644
index 000000000..d521455f0
--- /dev/null
+++ b/ejb/stateful/src/test/java/org/javaee7/ejb/stateful/CartBeanStatefulnessTest.java
@@ -0,0 +1,70 @@
+package org.javaee7.ejb.stateful;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.junit.InSequence;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.EJB;
+
+import static org.hamcrest.CoreMatchers.*;
+import static org.hamcrest.MatcherAssert.*;
+
+/**
+ * @author Jakub Marchwicki
+ */
+@RunWith(Arquillian.class)
+public class CartBeanStatefulnessTest {
+
+ final private String item_to_add = "apple";
+
+ @EJB
+ private CartBean bean1;
+
+ @EJB
+ private CartBean bean2;
+
+ @Deployment
+ public static Archive> deployment() {
+ return ShrinkWrap.create(JavaArchive.class, "test.jar")
+ .addClass(CartBean.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ /**
+ * JSR 318: Enterprise JavaBeans, Version 3.1
+ * 3.4.7.1 Session Object Identity / Stateful Session Beans
+ *
+ * A stateful session object has a unique identity that is assigned by
+ * the container at the time the object is created. A client of the stateful
+ * session bean business interface can determine if two business interface
+ * or no-interface view references refer to the same session object
+ * by use of the equals method
+ */
+ @Test
+ @InSequence(1)
+ public void should_not_be_identical_beans() {
+ assertThat("Expect different instances", bean1, is(not(bean2)));
+ }
+
+ @Test
+ @InSequence(2)
+ public void should_add_items_to_first_cart() {
+ // when
+ bean1.addItem(item_to_add);
+
+ // then
+ assertThat(bean1.getItems(), hasItem(item_to_add));
+ }
+
+ @Test
+ @InSequence(3)
+ public void should_not_contain_any_items_in_second_cart() {
+ assertThat(bean2.getItems().isEmpty(), is(true));
+ }
+}
\ No newline at end of file
diff --git a/ejb/stateless/src/main/java/org/javaee7/ejb/stateless/AccountSessionBean.java b/ejb/stateless/src/main/java/org/javaee7/ejb/stateless/AccountSessionBean.java
index fe5c05b0b..49c344ec0 100644
--- a/ejb/stateless/src/main/java/org/javaee7/ejb/stateless/AccountSessionBean.java
+++ b/ejb/stateless/src/main/java/org/javaee7/ejb/stateless/AccountSessionBean.java
@@ -47,11 +47,19 @@
@Stateless
public class AccountSessionBean {
+ private float amount = 0;
+
public String withdraw(float amount) {
+ this.amount -= amount;
return "Withdrawn: " + amount;
}
- public String deposit(float amount) {
+ public String deposit(float amount) {
+ this.amount += amount;
return "Deposited: " + amount;
}
+
+ public float getAmount() {
+ return this.amount;
+ }
}
diff --git a/ejb/stateless/src/main/java/org/javaee7/ejb/stateless/TestServlet.java b/ejb/stateless/src/main/java/org/javaee7/ejb/stateless/TestServlet.java
deleted file mode 100644
index 5c834f9f7..000000000
--- a/ejb/stateless/src/main/java/org/javaee7/ejb/stateless/TestServlet.java
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- *
- * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
- *
- * The contents of this file are subject to the terms of either the GNU
- * General Public License Version 2 only ("GPL") or the Common Development
- * and Distribution License("CDDL") (collectively, the "License"). You
- * may not use this file except in compliance with the License. You can
- * obtain a copy of the License at
- * https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
- * or packager/legal/LICENSE.txt. See the License for the specific
- * language governing permissions and limitations under the License.
- *
- * When distributing the software, include this License Header Notice in each
- * file and include the License file at packager/legal/LICENSE.txt.
- *
- * GPL Classpath Exception:
- * Oracle designates this particular file as subject to the "Classpath"
- * exception as provided by Oracle in the GPL Version 2 section of the License
- * file that accompanied this code.
- *
- * Modifications:
- * If applicable, add the following below the License Header, with the fields
- * enclosed by brackets [] replaced by your own identifying information:
- * "Portions Copyright [year] [name of copyright owner]"
- *
- * Contributor(s):
- * If you wish your version of this file to be governed by only the CDDL or
- * only the GPL Version 2, indicate your decision by adding "[Contributor]
- * elects to include this software in this distribution under the [CDDL or GPL
- * Version 2] license." If you don't indicate a single choice of license, a
- * recipient has the option to distribute your version of this file under
- * either the CDDL, the GPL Version 2 or to extend the choice of license to
- * its licensees as provided above. However, if you add GPL Version 2 code
- * and therefore, elected the GPL Version 2 license, then the option applies
- * only if the new code is made subject to such option by the copyright
- * holder.
- */
-package org.javaee7.ejb.stateless;
-
-import java.io.IOException;
-import java.io.PrintWriter;
-import javax.inject.Inject;
-import javax.servlet.ServletException;
-import javax.servlet.annotation.WebServlet;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * @author Arun Gupta
- */
-@WebServlet(urlPatterns = {"/TestServlet"})
-public class TestServlet extends HttpServlet {
- @Inject AccountSessionBean bean;;
-
- /**
- * Processes requests for both HTTP GET and POST
- * methods.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- protected void processRequest(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- response.setContentType("text/html;charset=UTF-8");
- try (PrintWriter out = response.getWriter()) {
- out.println("");
- out.println("");
- out.println("");
- out.println("Stateless Bean (No Interface)");
- out.println("");
- out.println("");
- out.println("Stateless Bean (No Interface)
");
- out.println("Withdraw and Deposit
");
- out.println(bean.deposit((float)5.0));
- out.println(bean.withdraw((float)5.0));
- out.println("");
- out.println("");
- }
- }
-
- //
- /**
- * Handles the HTTP GET method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doGet(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
-
- /**
- * Handles the HTTP POST method.
- *
- * @param request servlet request
- * @param response servlet response
- * @throws ServletException if a servlet-specific error occurs
- * @throws IOException if an I/O error occurs
- */
- @Override
- protected void doPost(HttpServletRequest request, HttpServletResponse response)
- throws ServletException, IOException {
- processRequest(request, response);
- }
-
- /**
- * Returns a short description of the servlet.
- *
- * @return a String containing servlet description
- */
- @Override
- public String getServletInfo() {
- return "Short description";
- }//
-
-}
diff --git a/ejb/stateless/src/main/webapp/index.jsp b/ejb/stateless/src/main/webapp/index.jsp
deleted file mode 100644
index ee2c4087a..000000000
--- a/ejb/stateless/src/main/webapp/index.jsp
+++ /dev/null
@@ -1,57 +0,0 @@
-
-<%@page contentType="text/html" pageEncoding="UTF-8"%>
-
-
-
-
-
- EJB : Stateful
-
-
- EJB : Stateful
-
- Call beans no-interface
- and with-interface.
-
-
diff --git a/ejb/stateless/src/test/java/org/javaee7/ejb/stateless/AccountSessionStatelessnessTest.java b/ejb/stateless/src/test/java/org/javaee7/ejb/stateless/AccountSessionStatelessnessTest.java
new file mode 100644
index 000000000..218a3f75e
--- /dev/null
+++ b/ejb/stateless/src/test/java/org/javaee7/ejb/stateless/AccountSessionStatelessnessTest.java
@@ -0,0 +1,70 @@
+package org.javaee7.ejb.stateless;
+
+import org.jboss.arquillian.container.test.api.Deployment;
+import org.jboss.arquillian.junit.Arquillian;
+import org.jboss.arquillian.junit.InSequence;
+import org.jboss.shrinkwrap.api.Archive;
+import org.jboss.shrinkwrap.api.ShrinkWrap;
+import org.jboss.shrinkwrap.api.asset.EmptyAsset;
+import org.jboss.shrinkwrap.api.spec.JavaArchive;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.EJB;
+
+import static org.hamcrest.MatcherAssert.*;
+import static org.hamcrest.Matchers.*;
+
+/**
+ * @author Jakub Marchwicki
+ */
+@RunWith(Arquillian.class)
+public class AccountSessionStatelessnessTest {
+
+ final private float deposit_amount = 10f;
+
+ @EJB
+ AccountSessionBean account1;
+
+ @EJB
+ AccountSessionBean account2;
+
+ @Deployment
+ public static Archive> deployment() {
+ return ShrinkWrap.create(JavaArchive.class, "test.jar")
+ .addClass(AccountSessionBean.class)
+ .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
+ }
+
+ /**
+ * JSR 318: Enterprise JavaBeans, Version 3.1
+ * 3.4.7.2 Session Object Identity / Stateless Session Beans
+ *
+ * All business object references of the same interface type for the same
+ * stateless session bean have the same object identity, which is assigned
+ * by the container. All references to the no-interface view of the same
+ * stateless session bean have the same object identity.
+ */
+ @Test
+ @InSequence(1)
+ public void should_be_identical_beans() {
+ assertThat("Expect same instances", account1, is(account2));
+ }
+
+ @Test
+ @InSequence(2)
+ public void should_deposit_amount_on_first_account() {
+ assertThat(account1.getAmount(), is(equalTo(0f)));
+
+ String actual = account1.deposit(deposit_amount);
+
+ assertThat(actual, is(equalTo("Deposited: " + deposit_amount)));
+ assertThat(account1.getAmount(), is(equalTo(deposit_amount)));
+ }
+
+ @Test
+ @InSequence(3)
+ public void should_contain_already_deposited_amount_on_second_account() {
+ assertThat(account2.getAmount(), is(equalTo(deposit_amount)));
+ }
+}
\ No newline at end of file