1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 package net.smartlab.web;
24
25 import java.rmi.RemoteException;
26
27 import javax.ejb.CreateException;
28 import javax.ejb.EJBException;
29 import javax.ejb.EJBHome;
30 import javax.ejb.SessionContext;
31
32 import junit.framework.TestCase;
33
34
35
36
37
38 public class EnterpriseDomainTest extends TestCase {
39
40
41
42
43 public static class Mock extends EnterpriseDomain {
44
45 private static final long serialVersionUID = 1L;
46
47 private String surname = "";
48
49 public void ejbActivate() throws EJBException, RemoteException {
50 System.out.println("ejbActivate()");
51 }
52
53 public void ejbPassivate() throws EJBException, RemoteException {
54 System.out.println("ejbPassivate()");
55 }
56
57 public void ejbRemove() throws EJBException, RemoteException {
58 System.out.println("ejbRemove()");
59 }
60
61 public void ejbCreate() throws CreateException, RemoteException {
62 System.out.println("ejbCreate()");
63 }
64
65 public void ejbCreate(String surname) throws CreateException, RemoteException {
66 System.out.println("ejbCreate(" + surname + ")");
67 this.surname = surname;
68 }
69
70 public void setSessionContext(SessionContext context) throws EJBException, RemoteException {
71 System.out.println("setSessionContext(context)");
72 }
73
74 public String father() {
75 return "father" + surname;
76 }
77
78 public String mother() {
79 return "mother" + surname;
80 }
81
82 public String brother(String name, int age) {
83 return "brother(" + name + surname + ") - " + age;
84 }
85
86 public String sister(String name, int age) throws BusinessException {
87 throw new BusinessException(name + surname);
88 }
89
90
91
92
93 public static interface Interface extends EnterpriseDomain.Remote {
94
95 public String father();
96
97 public String mother();
98
99 public String brother(String name, int age);
100
101 public String sister(String name, int age) throws BusinessException;
102 }
103
104 public static interface Home extends EJBHome {
105 public Interface create();
106
107 public Interface create(String surname);
108 }
109 }
110
111
112 private EnterpriseDomain.RequestContext context = new EnterpriseDomain.RequestContext();
113
114
115
116
117
118
119
120 public void testExecute() throws Exception {
121 EnterpriseDomain mock = new Mock();
122 super.assertEquals("father", mock.execute("father", null, null, context));
123 super.assertEquals("mother", mock.execute("mother", null, null, context));
124 super.assertEquals("brother(paul) - 35", mock.execute("brother", new Object[] {"paul", new Integer(35)}, new String[] {"java.lang.String", "int"},
125 context));
126 try {
127 mock.execute("sister", new Object[] {"claire", new Integer(7)}, new String[] {"java.lang.String", "int"}, context);
128 super.fail();
129 } catch (Exception e) {
130
131 }
132 }
133 }