1
2
3
4
5
6
7
8
9
10
11 package org.mule.extras.hivemind;
12
13 import org.mule.tck.model.AbstractContainerContextTestCase;
14 import org.mule.tck.testmodels.fruit.Apple;
15 import org.mule.tck.testmodels.fruit.FruitBowl;
16 import org.mule.umo.manager.ObjectNotFoundException;
17 import org.mule.umo.manager.UMOContainerContext;
18
19
20
21
22
23
24
25 public class HiveMindContextTestCase extends AbstractContainerContextTestCase
26 {
27 HiveMindContext context;
28
29 protected void doSetUp() throws Exception
30 {
31 context = new HiveMindContext();
32 context.initialise();
33 }
34
35
36
37
38
39
40 public UMOContainerContext getContainerContext()
41 {
42 return context;
43 }
44
45
46
47
48
49
50 public void testContainerNotNull() throws Exception
51 {
52 assertNotNull(getContainerContext());
53 }
54
55
56
57
58 public void testRegistryNotNull()
59 {
60 assertNotNull(context.getRegistry());
61 }
62
63
64
65
66 public void testIllegalState()
67 {
68 try
69 {
70 HiveMindContext ctx = new HiveMindContext();
71 ctx.getComponent(new Object());
72 fail();
73 }
74 catch (IllegalStateException ise)
75 {
76
77 }
78 catch (ObjectNotFoundException obfe)
79 {
80 fail("Should throw a IllegalStateExeption instead of ObjectNotFoundException");
81 }
82 }
83
84
85
86
87 public void testObjectNotFound()
88 {
89 try
90 {
91 context.getComponent(new String("Not present").getClass());
92 fail("Should have thrown ObjectNotFoundException");
93 }
94 catch (ObjectNotFoundException onfe)
95 {
96
97 }
98 }
99
100
101
102
103 public void testObjectNotFoundByKeyType()
104 {
105 try
106 {
107 context.getComponent(new FruitBowl());
108 fail("Should have thrown ObjectNotFoundException");
109 }
110 catch (ObjectNotFoundException onfe)
111 {
112
113 }
114 }
115
116
117
118
119
120
121 public void testDispose() throws Exception
122 {
123 HiveMindContext context = new HiveMindContext();
124 context.initialise();
125 context.dispose();
126
127 try
128 {
129 context.getComponent(Class.class);
130 fail("Shouldn't be possibile to get a component after disposing the container");
131 }
132 catch (NullPointerException npe)
133 {
134
135 }
136 }
137
138
139
140
141
142
143 public void testFruitBowl() throws Exception
144 {
145 FruitBowl result = null;
146 try
147 {
148 result = (FruitBowl)context.getComponent(FruitBowl.class.getName());
149 assertNotNull("Component FruitBwol should exist in container", result);
150 Apple apple = result.getApple();
151 assertNotNull("Component Apple should be in FruitBowl", apple);
152 }
153 catch (ObjectNotFoundException e)
154 {
155 fail("Component should exist in the container");
156 }
157 }
158
159 }