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 javax.naming.Context;
26 import javax.naming.InitialContext;
27
28 import junit.framework.TestCase;
29
30 import org.mockejb.MockContainer;
31 import org.mockejb.SessionBeanDescriptor;
32 import org.mockejb.jndi.MockContextFactory;
33
34
35
36
37 public class EnterpriseDomainBuilderTest extends TestCase {
38
39 private Context context;
40
41
42
43
44
45 protected void setUp() throws Exception {
46 MockContextFactory.setAsInitial();
47 this.context = new InitialContext();
48 MockContainer mockContainer = new MockContainer(context);
49 SessionBeanDescriptor mock = new SessionBeanDescriptor("mock", EnterpriseDomainTest.Mock.Home.class, EnterpriseDomainTest.Mock.Interface.class, new EnterpriseDomainTest.Mock());
50
51 mockContainer.deploy(mock);
52 }
53
54
55
56
57
58
59 public void testGetInstanceStringClass() {
60 Object object = EnterpriseDomainBuilder.getInstance("mock", EnterpriseDomainTest.Mock.Interface.class);
61 super.assertNotNull(object);
62 super.assertTrue(object instanceof EnterpriseDomainTest.Mock.Interface);
63 super.assertEquals("father", ((EnterpriseDomainTest.Mock.Interface)object).father());
64 super.assertEquals("mother", ((EnterpriseDomainTest.Mock.Interface)object).mother());
65 super.assertEquals("brother(paul) - 35", ((EnterpriseDomainTest.Mock.Interface)object).brother("paul", 35));
66 try {
67 ((EnterpriseDomainTest.Mock.Interface)object).sister("claire", 7);
68 super.fail("exception expected");
69 } catch (Exception e) {
70 super.assertEquals(BusinessException.class, e.getClass());
71 super.assertEquals("claire", e.getMessage());
72 }
73 }
74
75
76
77
78
79
80 public void testGetInstanceStringClassContext() {
81 Object object = EnterpriseDomainBuilder.getInstance("mock", EnterpriseDomainTest.Mock.Interface.class, context);
82 super.assertNotNull(object);
83 super.assertTrue(object instanceof EnterpriseDomainTest.Mock.Interface);
84 super.assertEquals("father", ((EnterpriseDomainTest.Mock.Interface)object).father());
85 super.assertEquals("mother", ((EnterpriseDomainTest.Mock.Interface)object).mother());
86 super.assertEquals("brother(paul) - 35", ((EnterpriseDomainTest.Mock.Interface)object).brother("paul", 35));
87 try {
88 ((EnterpriseDomainTest.Mock.Interface)object).sister("claire", 7);
89 super.fail("exception expected");
90 } catch (Exception e) {
91 super.assertEquals(BusinessException.class, e.getClass());
92 super.assertEquals("claire", e.getMessage());
93 }
94 }
95
96
97
98
99
100
101 public void testGetInstanceStringClassContextObjectArray() {
102 Object object = EnterpriseDomainBuilder.getInstance("mock", EnterpriseDomainTest.Mock.Interface.class, context, new Object[] {"family"});
103 super.assertNotNull(object);
104 super.assertTrue(object instanceof EnterpriseDomainTest.Mock.Interface);
105 super.assertEquals("fatherfamily", ((EnterpriseDomainTest.Mock.Interface)object).father());
106 super.assertEquals("motherfamily", ((EnterpriseDomainTest.Mock.Interface)object).mother());
107 super.assertEquals("brother(paulfamily) - 35", ((EnterpriseDomainTest.Mock.Interface)object).brother("paul", 35));
108 try {
109 ((EnterpriseDomainTest.Mock.Interface)object).sister("claire", 7);
110 super.fail("exception expected");
111 } catch (Exception e) {
112 super.assertEquals(BusinessException.class, e.getClass());
113 super.assertEquals("clairefamily", e.getMessage());
114 }
115 }
116 }