Skip to content

Commit 0c9d84b

Browse files
committed
Changed the bean name to be more meaningful. Also added some simple tests but still getting NPE and needs further investigation.
1 parent b18342a commit 0c9d84b

File tree

7 files changed

+139
-19
lines changed

7 files changed

+139
-19
lines changed

ejb/stateless/src/main/java/org/javaee7/ejb/stateless/AccountSessionBean.java

+4-6
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,11 @@
4747
@Stateless
4848
public class AccountSessionBean {
4949

50-
public float withdraw() {
51-
System.out.println("withdraw");
52-
53-
return (float)0.0;
50+
public String withdraw(float amount) {
51+
return "Withdrawn: " + amount;
5452
}
5553

56-
public void deposit(float amount) {
57-
System.out.println("deposit");
54+
public String deposit(float amount) {
55+
return "Deposited: " + amount;
5856
}
5957
}

ejb/stateless/src/main/java/org/javaee7/ejb/stateless/TestServlet.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
7676
out.println("<body>");
7777
out.println("<h1>Stateless Bean (No Interface)</h1>");
7878
out.println("<h2>Withdraw and Deposit</h2>");
79-
bean.deposit((float)10.0);
80-
out.println("Withdrawn : " + bean.withdraw());
79+
out.println(bean.deposit((float)5.0));
80+
out.println(bean.withdraw((float)5.0));
8181
out.println("</body>");
8282
out.println("</html>");
8383
}

ejb/stateless/src/main/java/org/javaee7/ejb/stateless/remote/Account.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
@Remote
4848
public interface Account {
4949

50-
public float withdraw();
50+
public String withdraw(float amount);
5151

52-
public void deposit(float amount);
52+
public String deposit(float amount);
5353

5454
}

ejb/stateless/src/main/java/org/javaee7/ejb/stateless/remote/AccountSessionBean.java renamed to ejb/stateless/src/main/java/org/javaee7/ejb/stateless/remote/AccountSessionBeanWithInterface.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,15 @@
4545
* @author Arun Gupta
4646
*/
4747
@Stateless
48-
public class AccountSessionBean implements Account {
48+
public class AccountSessionBeanWithInterface implements Account {
4949

5050
@Override
51-
public float withdraw() {
52-
System.out.println("withdraw");
53-
return (float)0.0;
51+
public String withdraw(float amount) {
52+
return "Withdrawn: " + amount;
5453
}
5554

5655
@Override
57-
public void deposit(float amount) {
58-
System.out.println("deposit: " + amount);
56+
public String deposit(float amount) {
57+
return "Deposited: " + amount;
5958
}
6059
}

ejb/stateless/src/main/java/org/javaee7/ejb/stateless/remote/TestServlet.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,9 +78,9 @@ protected void processRequest(HttpServletRequest request, HttpServletResponse re
7878
out.println("</head>");
7979
out.println("<body>");
8080
out.println("<h1>Stateless Bean (with Interface)</h1>");
81-
out.println("<h2>Withdraw/Deposit</h2>");
82-
bean.deposit((float) 10.0);
83-
out.println("Withdrawn : " + bean.withdraw());
81+
out.println("<h2>Withdraw and Deposit</h2>");
82+
out.println(bean.deposit((float) 5.0));
83+
out.println(bean.withdraw((float) 5.0));
8484
out.println("</body>");
8585
out.println("</html>");
8686
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package org.javaee7.ejb.stateless;
8+
9+
import javax.ejb.EJB;
10+
import org.jboss.arquillian.container.test.api.Deployment;
11+
import org.jboss.arquillian.container.test.api.TargetsContainer;
12+
import org.jboss.arquillian.junit.Arquillian;
13+
import org.jboss.shrinkwrap.api.ShrinkWrap;
14+
import org.jboss.shrinkwrap.api.spec.WebArchive;
15+
import org.junit.Test;
16+
import static org.junit.Assert.*;
17+
import org.junit.runner.RunWith;
18+
19+
/**
20+
* @author Arun Gupta
21+
*/
22+
@RunWith(Arquillian.class)
23+
public class AccountSessionBeanTest {
24+
@EJB AccountSessionBean bean;
25+
26+
/**
27+
* Arquillian specific method for creating a file which can be deployed
28+
* while executing the test.
29+
*
30+
* @return a war file
31+
*/
32+
@Deployment
33+
@TargetsContainer("wildfly-arquillian")
34+
public static WebArchive createDeployment() {
35+
WebArchive war = ShrinkWrap.create(WebArchive.class).
36+
addClass(AccountSessionBean.class);
37+
System.out.println(war.toString(true));
38+
return war;
39+
}
40+
41+
/**
42+
* Test of withdraw method, of class AccountSessionBean.
43+
*/
44+
@Test
45+
public void testWithdraw() {
46+
System.out.println("withdraw");
47+
String result = bean.withdraw((float)5.0);
48+
assertEquals("Withdrawn: 5.0", result);
49+
}
50+
51+
/**
52+
* Test of deposit method, of class AccountSessionBean.
53+
*/
54+
@Test
55+
public void testDeposit() {
56+
System.out.println("deposit");
57+
String result = bean.withdraw((float)10.0);
58+
assertEquals("Deposited: 10.0", result);
59+
}
60+
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
7+
package org.javaee7.ejb.stateless;
8+
9+
import javax.ejb.EJB;
10+
import org.javaee7.ejb.stateless.remote.Account;
11+
import org.jboss.arquillian.container.test.api.Deployment;
12+
import org.jboss.arquillian.container.test.api.TargetsContainer;
13+
import org.jboss.arquillian.junit.Arquillian;
14+
import org.jboss.shrinkwrap.api.ShrinkWrap;
15+
import org.jboss.shrinkwrap.api.spec.WebArchive;
16+
import org.junit.Test;
17+
import static org.junit.Assert.*;
18+
import org.junit.runner.RunWith;
19+
20+
/**
21+
* @author Arun Gupta
22+
*/
23+
@RunWith(Arquillian.class)
24+
public class AccountSessionBeanWithInterfaceTest {
25+
@EJB Account bean;
26+
27+
/**
28+
* Arquillian specific method for creating a file which can be deployed
29+
* while executing the test.
30+
*
31+
* @return a war file
32+
*/
33+
@Deployment
34+
@TargetsContainer("wildfly-arquillian")
35+
public static WebArchive createDeployment() {
36+
WebArchive war = ShrinkWrap.create(WebArchive.class).
37+
addClass(AccountSessionBean.class);
38+
System.out.println(war.toString(true));
39+
return war;
40+
}
41+
42+
/**
43+
* Test of withdraw method, of class AccountSessionBean.
44+
*/
45+
@Test
46+
public void testWithdraw() {
47+
System.out.println("withdraw");
48+
String result = bean.withdraw((float)5.0);
49+
assertEquals("Withdrawn: 5.0", result);
50+
}
51+
52+
/**
53+
* Test of deposit method, of class AccountSessionBean.
54+
*/
55+
@Test
56+
public void testDeposit() {
57+
System.out.println("deposit");
58+
String result = bean.withdraw((float)10.0);
59+
assertEquals("Deposited: 10.0", result);
60+
}
61+
62+
}

0 commit comments

Comments
 (0)