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