1 package com.sourceforge.jpatterns.core.configuration.model;
2
3 import com.sourceforge.jpatterns.schema.CastorNameScopePriorityType;
4 import com.sourceforge.jpatterns.schema.CastorSectionType;
5 import com.zmicer.utils.LoggingUtils;
6 import junit.framework.Test;
7 import junit.framework.TestCase;
8 import junit.framework.TestSuite;
9 import org.apache.log4j.Logger;
10
11 import java.util.HashMap;
12 import java.util.List;
13 import java.util.Map;
14
15
16
17
18
19
20 public class JPatternsConfigBaseBeanTest extends TestCase
21 {
22
23
24
25 final public static Logger LOG = Logger.getLogger(JPatternsConfigBaseBeanTest.class);
26
27
28
29
30 private JPatternsConfigBaseBean m_jPatternsConfigBaseBean;
31
32
33
34
35
36
37 public JPatternsConfigBaseBeanTest(String name)
38 {
39 super(name);
40 }
41
42
43
44
45
46
47 public void setUp() throws Exception
48 {
49 super.setUp();
50 m_jPatternsConfigBaseBean = new JPatternsConfigBaseBean();
51 }
52
53
54
55
56
57
58 public void tearDown() throws Exception
59 {
60 super.tearDown();
61 }
62
63
64
65
66
67
68 public static Test suite()
69 {
70 return new TestSuite(JPatternsConfigBaseBeanTest.class);
71 }
72
73
74
75
76
77
78
79 public void testSetGetBusinessItems() throws Exception
80 {
81
82 try
83 {
84 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItems());
85 assertEquals(m_jPatternsConfigBaseBean.getBusinessItems().size(), 0);
86 }
87 catch (Exception ex)
88 {
89 LoggingUtils.logException(LOG, ex, null, null);
90 fail("Exception should not occur for that case params" + ex.getMessage());
91 }
92
93
94 try
95 {
96 m_jPatternsConfigBaseBean.setBusinessItems(null);
97 fail("Exception should have been occuried before this line.");
98 }
99 catch (Exception ex)
100 {
101 assertTrue(ex instanceof IllegalArgumentException);
102 }
103
104
105 try
106 {
107 final Map<String, Map<String, Map<String, Map<String, CastorNameScopePriorityType>>>> mapForTest =
108 new HashMap<String, Map<String, Map<String, Map<String, CastorNameScopePriorityType>>>>();
109 m_jPatternsConfigBaseBean.setBusinessItems(mapForTest);
110 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItems());
111 assertEquals(m_jPatternsConfigBaseBean.getBusinessItems(), mapForTest);
112 }
113 catch (Exception ex)
114 {
115 LoggingUtils.logException(LOG, ex, null, null);
116 fail("Exception should not occur for that case params" + ex.getMessage());
117 }
118 }
119
120
121
122
123
124
125
126 public void testSetGetSectionItems() throws Exception
127 {
128
129 try
130 {
131 assertNotNull(m_jPatternsConfigBaseBean.getSectionItems());
132 assertEquals(m_jPatternsConfigBaseBean.getSectionItems().size(), 0);
133 }
134 catch (Exception ex)
135 {
136 LoggingUtils.logException(LOG, ex, null, null);
137 fail("Exception should not occur for that case params" + ex.getMessage());
138 }
139
140
141 try
142 {
143 m_jPatternsConfigBaseBean.setSectionItems(null);
144 fail("Exception should have been occuried before this line.");
145 }
146 catch (Exception ex)
147 {
148 assertTrue(ex instanceof IllegalArgumentException);
149 }
150
151
152 try
153 {
154 final Map<String, Map<String, CastorSectionType>> mapForTest = new HashMap<String, Map<String, CastorSectionType>>();
155 m_jPatternsConfigBaseBean.setSectionItems(mapForTest);
156 assertNotNull(m_jPatternsConfigBaseBean.getSectionItems());
157 assertEquals(m_jPatternsConfigBaseBean.getSectionItems(), mapForTest);
158 }
159 catch (Exception ex)
160 {
161 LoggingUtils.logException(LOG, ex, null, null);
162 fail("Exception should not occur for that case params" + ex.getMessage());
163 }
164 }
165
166
167
168
169
170
171
172 public void testCheck() throws Exception
173 {
174
175
176 try
177 {
178 assertTrue(m_jPatternsConfigBaseBean.check());
179 }
180 catch (Exception ex)
181 {
182 LoggingUtils.logException(LOG, ex, null, null);
183 fail("Exception should not occur for that case params" + ex.getMessage());
184 }
185
186 }
187
188
189
190
191
192
193
194 public void testSetGetBusinessItem() throws Exception
195 {
196
197 assertSetIncorrectBusinessItem(null, null, null);
198 assertSetIncorrectBusinessItem(null, "temp", new CastorNameScopePriorityType());
199 assertSetIncorrectBusinessItem("temp", null, new CastorNameScopePriorityType());
200 assertSetIncorrectBusinessItem("temp", "temp", null);
201 assertSetIncorrectBusinessItem("", "temp", new CastorNameScopePriorityType());
202 assertSetIncorrectBusinessItem("temp", "", new CastorNameScopePriorityType());
203 assertSetIncorrectBusinessItem("", "", new CastorNameScopePriorityType());
204
205
206 try
207 {
208
209 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItems());
210 assertEquals(m_jPatternsConfigBaseBean.getBusinessItems().size(), 0);
211
212 final String name1 = "name1";
213 final String name2 = "name2";
214 final String scope1 = "scope1";
215 final String scope2 = "scope2";
216 final CastorNameScopePriorityType castorNameScopePriorityType1 = new CastorNameScopePriorityType();
217 castorNameScopePriorityType1.setName(name1);
218 castorNameScopePriorityType1.setScope(scope1);
219 m_jPatternsConfigBaseBean.setBusinessItem("scope", "section", castorNameScopePriorityType1);
220 assertEquals(m_jPatternsConfigBaseBean.getBusinessItems().size(), 1);
221 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItems().get("scope"));
222 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItems().get("scope").get("section"));
223 assertEquals(m_jPatternsConfigBaseBean.getBusinessItems().get("scope").get("section").size(), 1);
224 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope1, name1));
225 assertEquals(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope1, name1), castorNameScopePriorityType1);
226
227 final CastorNameScopePriorityType castorNameScopePriorityType2 = new CastorNameScopePriorityType();
228 castorNameScopePriorityType2.setName(name2);
229 castorNameScopePriorityType2.setScope(scope2);
230 m_jPatternsConfigBaseBean.setBusinessItem("scope", "section", castorNameScopePriorityType2);
231 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope2, name2));
232 assertEquals(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope2, name2), castorNameScopePriorityType2);
233
234 final CastorNameScopePriorityType castorNameScopePriorityType3 = new CastorNameScopePriorityType();
235 castorNameScopePriorityType3.setName(name1);
236 castorNameScopePriorityType3.setScope(scope1);
237 m_jPatternsConfigBaseBean.setBusinessItem("scope", "section", castorNameScopePriorityType3);
238 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope1, name1));
239
240 assertEquals(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope1, name1), castorNameScopePriorityType3);
241
242
243 final CastorNameScopePriorityType castorNameScopePriorityType4 = new CastorNameScopePriorityType();
244 castorNameScopePriorityType4.setName(name1);
245 castorNameScopePriorityType4.setScope(scope2);
246 m_jPatternsConfigBaseBean.setBusinessItem("scope", "section", castorNameScopePriorityType4);
247 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope1, name1));
248 assertNotNull(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope2, name1));
249 assertNotSame(m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope1, name1),
250 m_jPatternsConfigBaseBean.getBusinessItem("scope", "section", scope2, name1));
251 }
252 catch (Exception ex)
253 {
254 LoggingUtils.logException(LOG, ex, null, null);
255 fail("Exception should not occur for that case params" + ex.getMessage());
256 }
257 }
258
259
260
261
262
263
264
265
266
267 private void assertSetIncorrectBusinessItem(final String scope, final String sectionName, final CastorNameScopePriorityType item)
268 {
269 try
270 {
271 m_jPatternsConfigBaseBean.setBusinessItem(scope, sectionName, item);
272 fail("Exception should have been occuried before this line.");
273 }
274 catch (Exception ex)
275 {
276 assertTrue(ex instanceof IllegalArgumentException);
277 }
278 }
279
280
281
282
283
284
285
286 public void testSetGetSection() throws Exception
287 {
288
289 assertSetIncorrectSection(null, null);
290 assertSetIncorrectSection(null, new CastorSectionType());
291 assertSetIncorrectSection("", new CastorSectionType());
292 assertSetIncorrectSection("temp", null);
293
294
295 try
296 {
297
298 assertNotNull(m_jPatternsConfigBaseBean.getSectionItems());
299 assertEquals(m_jPatternsConfigBaseBean.getSectionItems().size(), 0);
300
301 final String name1 = "name1";
302 final String name2 = "name2";
303 final CastorSectionType castorSectionType1 = new CastorSectionType();
304 castorSectionType1.setName(name1);
305 m_jPatternsConfigBaseBean.setSection("scope", castorSectionType1);
306 assertNotNull(m_jPatternsConfigBaseBean.getSection("scope", name1));
307 assertEquals(m_jPatternsConfigBaseBean.getSection("scope", name1), castorSectionType1);
308
309 final CastorSectionType castorSectionType2 = new CastorSectionType();
310 castorSectionType2.setName(name2);
311 m_jPatternsConfigBaseBean.setSection("scope", castorSectionType2);
312 assertNotNull(m_jPatternsConfigBaseBean.getSection("scope", name2));
313 assertEquals(m_jPatternsConfigBaseBean.getSection("scope", name2), castorSectionType2);
314
315 final CastorSectionType castorSectionType3 = new CastorSectionType();
316 castorSectionType3.setName(name1);
317 m_jPatternsConfigBaseBean.setSection("scope", castorSectionType3);
318 assertNotNull(m_jPatternsConfigBaseBean.getSection("scope", name1));
319 assertEquals(m_jPatternsConfigBaseBean.getSection("scope", name1), castorSectionType3);
320 }
321 catch (Exception ex)
322 {
323 LoggingUtils.logException(LOG, ex, null, null);
324 fail("Exception should not occur for that case params" + ex.getMessage());
325 }
326
327 }
328
329
330
331
332
333
334
335 private void assertSetIncorrectSection(final String scope, final CastorSectionType section)
336 {
337 try
338 {
339 m_jPatternsConfigBaseBean.setSection(scope, section);
340 fail("Exception should have been occuried before this line.");
341 }
342 catch (Exception ex)
343 {
344 assertTrue(ex instanceof IllegalArgumentException);
345 }
346 }
347
348
349
350
351
352
353
354 public void testGetListOfSectionItems() throws Exception
355 {
356
357 try
358 {
359 final CastorSectionType section1 = new CastorSectionType();
360 section1.setScope("scope1");
361 section1.setName("name1");
362 section1.setPriority("-1");
363 final CastorSectionType section2 = new CastorSectionType();
364 section2.setScope("scope2");
365 section2.setName("name2");
366 section2.setPriority("1");
367 m_jPatternsConfigBaseBean.setSection("scope1", section1);
368 m_jPatternsConfigBaseBean.setSection("scope2", section2);
369 final List<CastorSectionType> result = m_jPatternsConfigBaseBean.getListOfSectionItems();
370 assertNotNull(result);
371 assertEquals(result.size(), 2);
372 }
373 catch (Exception ex)
374 {
375 LoggingUtils.logException(LOG, ex, null, null);
376 fail("Exception should not occur for that case " + ex.getMessage());
377 }
378 }
379 }