1+ package org .javaee7 .ejb .stateful ;
2+
3+ import org .jboss .arquillian .container .test .api .Deployment ;
4+ import org .jboss .arquillian .junit .Arquillian ;
5+ import org .jboss .arquillian .junit .InSequence ;
6+ import org .jboss .shrinkwrap .api .Archive ;
7+ import org .jboss .shrinkwrap .api .ShrinkWrap ;
8+ import org .jboss .shrinkwrap .api .asset .EmptyAsset ;
9+ import org .jboss .shrinkwrap .api .spec .JavaArchive ;
10+ import org .junit .Test ;
11+ import org .junit .runner .RunWith ;
12+
13+ import javax .ejb .EJB ;
14+
15+ import static org .hamcrest .CoreMatchers .*;
16+ import static org .hamcrest .MatcherAssert .*;
17+
18+ /**
19+ * @author Jakub Marchwicki
20+ */
21+ @ RunWith (Arquillian .class )
22+ public class CartBeanStatefulnessTest {
23+
24+ final private String item_to_add = "apple" ;
25+
26+ @ EJB
27+ private CartBean bean1 ;
28+
29+ @ EJB
30+ private CartBean bean2 ;
31+
32+ @ Deployment
33+ public static Archive <?> deployment () {
34+ return ShrinkWrap .create (JavaArchive .class , "test.jar" )
35+ .addClass (CartBean .class )
36+ .addAsManifestResource (EmptyAsset .INSTANCE , "beans.xml" );
37+ }
38+
39+ /**
40+ * JSR 318: Enterprise JavaBeans, Version 3.1
41+ * 3.4.7.1 Session Object Identity / Stateful Session Beans
42+ *
43+ * A stateful session object has a unique identity that is assigned by
44+ * the container at the time the object is created. A client of the stateful
45+ * session bean business interface can determine if two business interface
46+ * or no-interface view references refer to the same session object
47+ * by use of the equals method
48+ */
49+ @ Test
50+ @ InSequence (1 )
51+ public void should_not_be_identical_beans () {
52+ assertThat ("Expect different instances" , bean1 , is (not (bean2 )));
53+ }
54+
55+ @ Test
56+ @ InSequence (2 )
57+ public void should_add_items_to_first_cart () {
58+ // when
59+ bean1 .addItem (item_to_add );
60+
61+ // then
62+ assertThat (bean1 .getItems (), hasItem (item_to_add ));
63+ }
64+
65+ @ Test
66+ @ InSequence (3 )
67+ public void should_not_contain_any_items_in_second_cart () {
68+ assertThat (bean2 .getItems ().isEmpty (), is (true ));
69+ }
70+ }
0 commit comments