1   package com.sourceforge.jpatterns.core.configuration.model;
2   
3   import com.sourceforge.jpatterns.core.JPConstants;
4   import com.sourceforge.jpatterns.core.configuration.PropertiesProvider;
5   import com.sourceforge.jpatterns.core.configuration.exceptions.JPConfigException;
6   import com.sourceforge.jpatterns.schema.CastorConfigType;
7   import com.sourceforge.jpatterns.schema.CastorItemType;
8   import com.sourceforge.jpatterns.schema.CastorNameScopePriorityType;
9   import com.sourceforge.jpatterns.schema.CastorSectionType;
10  import com.sourceforge.jpatterns.schema.Item;
11  import com.sourceforge.jpatterns.schema.JPatternsConfig;
12  import com.sourceforge.jpatterns.utils.CastorUtils;
13  import com.sourceforge.jpatterns.utils.junit.JPatternsTestUtils;
14  import com.zmicer.utils.InputArgumentUtils;
15  import com.zmicer.utils.LoggingUtils;
16  import junit.framework.Test;
17  import junit.framework.TestCase;
18  import junit.framework.TestSuite;
19  import org.apache.log4j.Logger;
20  
21  import java.util.ArrayList;
22  import java.util.List;
23  
24  /**
25   * $Author:: zmicer             $<br/>
26   * $Rev:: 67                    $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
27   * $Date:: 2007-08-28 21:37:07 #$<br/>
28   */
29  public class JPatternsConfigBeansBuilderImplTest extends TestCase
30  {
31      /**
32       * Logger instance.
33       */
34      final public static Logger LOG = Logger.getLogger(JPatternsConfigBeansBuilderImplTest.class);
35  
36      /**
37       * Instance of the covered class to be used below in the tests
38       */
39      private JPatternsConfigBeansBuilderImpl m_builder = new JPatternsConfigBeansBuilderImpl();
40  
41      /**
42       * This interface contains configs for the test.
43       */
44      public interface ConfigsForTest
45      {
46          /**
47           * config file name 1
48           */
49          String CONFIG_1 = "jpatterns_framework1.xml";
50  
51          /**
52           * config file name 2
53           */
54          String CONFIG_2 = "jpatterns_framework2.xml";
55      }
56  
57      /**
58       * Contructor with name of test attribute.
59       *
60       * @param name name of the test
61       */
62      public JPatternsConfigBeansBuilderImplTest(String name)
63      {
64          super(name);
65      }
66  
67      /**
68       * Perform the set up functionality for the test.
69       *
70       * @throws Exception may occur in the case of some problems
71       */
72      public void setUp() throws Exception
73      {
74          super.setUp();
75      }
76  
77      /**
78       * Perform the tear down functionality for the test
79       *
80       * @throws Exception may occur in the case of some problems
81       */
82      public void tearDown() throws Exception
83      {
84          super.tearDown();
85      }
86  
87      /**
88       * Test suite method
89       *
90       * @return the built test suite
91       */
92      public static Test suite()
93      {
94          return new TestSuite(JPatternsConfigBeansBuilderImplTest.class);
95      }
96  
97      /**
98       * Tests {@link JPatternsConfigBeansBuilderImpl#set/getOverridingDepth}
99       *
100      * @throws Exception in the case smth. wrong occuried.
101      * @forversion 1.0
102      */
103     public void testSetGetOverridingDepth() throws Exception
104     {
105         // normal sub-case: no exception: check default value
106         try
107         {
108             assertNotNull(JPatternsConfigBeansBuilderImpl.getOverridingDepth());
109         }
110         catch (Exception ex)
111         {
112             LoggingUtils.logException(LOG, ex, null, null);
113             fail("Exception should not occur for that case " + ex.getMessage());
114         }
115         // failed sub-case: exception occuried: null param
116         try
117         {
118             JPatternsConfigBeansBuilderImpl.setOverridingDepth(null);
119             fail("Exception should have been occuried before this line.");
120         }
121         catch (Exception ex)
122         {
123             assertTrue(ex instanceof IllegalArgumentException);
124         }
125         // normal sub-case: no exception: all is correct
126         try
127         {
128             JPatternsConfigBeansBuilderImpl.setOverridingDepth(PropertiesProvider.OverridingDepths.OVERRIDING_LEVEL_ITEM.toString());
129             assertEquals(JPatternsConfigBeansBuilderImpl.getOverridingDepth(),
130                 PropertiesProvider.OverridingDepths.OVERRIDING_LEVEL_ITEM.toString());
131             JPatternsConfigBeansBuilderImpl.setOverridingDepth(PropertiesProvider.OverridingDepths.OVERRIDING_LEVEL_SECTION.toString());
132             assertEquals(JPatternsConfigBeansBuilderImpl.getOverridingDepth(),
133                 PropertiesProvider.OverridingDepths.OVERRIDING_LEVEL_SECTION.toString());
134         }
135         catch (Exception ex)
136         {
137             LoggingUtils.logException(LOG, ex, null, null);
138             fail("Exception should not occur for that case " + ex.getMessage());
139         }
140     }
141 
142     /**
143      * Tests {@link JPatternsConfigBeansBuilderImpl#set/getOverrideNotDependingOnPriority}
144      *
145      * @throws Exception in the case smth. wrong occuried.
146      * @forversion 1.0
147      */
148     public void testSetGetOverrideNotDependingOnPriority() throws Exception
149     {
150         // normal sub-case: no exception: default value is true following the default properties jpatterns.properties
151         try
152         {
153             assertTrue(JPatternsConfigBeansBuilderImpl.getOverrideNotDependingOnPriority());
154             JPatternsConfigBeansBuilderImpl.setOverrideNotDependingOnPriority(false);
155             assertFalse(JPatternsConfigBeansBuilderImpl.getOverrideNotDependingOnPriority());
156             JPatternsConfigBeansBuilderImpl.setOverrideNotDependingOnPriority(true);
157             assertTrue(JPatternsConfigBeansBuilderImpl.getOverrideNotDependingOnPriority());
158         }
159         catch (Exception ex)
160         {
161             LoggingUtils.logException(LOG, ex, null, null);
162             fail("Exception should not occur for that case " + ex.getMessage());
163         }
164     }
165 
166     /**
167      * Tests {@link JPatternsConfigBeansBuilderImpl#choiceOrMergeCastorNameScopePriorityTypes}
168      *
169      * @throws Exception in the case smth. wrong occuried.
170      * @forversion 1.0
171      */
172     public void testChoiceOrMergeCastorNameScopePriorityTypes() throws Exception
173     {
174         // failed sub-case: exception occuried: null input argument
175         try
176         {
177             m_builder.choiceOrMergeCastorNameScopePriorityTypes(null, null);
178             fail("Exception should have been occuried before this line.");
179         }
180         catch (Exception ex)
181         {
182             assertTrue(ex instanceof IllegalArgumentException);
183         }
184         // failed sub-case: exception occuried: null input argument
185         try
186         {
187             m_builder.choiceOrMergeCastorNameScopePriorityTypes(null, new CastorSectionType());
188             fail("Exception should have been occuried before this line.");
189         }
190         catch (Exception ex)
191         {
192             assertTrue(ex instanceof IllegalArgumentException);
193         }
194         // failed sub-case: exception occuried: not filled with the required attributes
195         try
196         {
197             m_builder.choiceOrMergeCastorNameScopePriorityTypes(new CastorSectionType(), new CastorSectionType());
198             fail("Exception should have been occuried before this line.");
199         }
200         catch (Exception ex)
201         {
202             assertTrue(ex instanceof IllegalArgumentException);
203         }
204         // failed sub-case: exception occuried: different types
205         try
206         {
207             m_builder.choiceOrMergeCastorNameScopePriorityTypes(new CastorItemType(), new CastorSectionType());
208             fail("Exception should have been occuried before this line.");
209         }
210         catch (Exception ex)
211         {
212             assertTrue(ex instanceof IllegalArgumentException);
213         }
214         // failed sub-case: exception occuried: pathes are not equals
215         try
216         {
217             m_builder.choiceOrMergeCastorNameScopePriorityTypes(buildConfigSection("scope", "name", "-1"),
218                 buildItem("scope", "name_", "-1"));
219             fail("Exception should have been occuried before this line.");
220         }
221         catch (Exception ex)
222         {
223             assertTrue(ex instanceof IllegalArgumentException);
224         }
225 
226         // failed sub-case: exception occuried: two items with identical pathes and priorities
227         try
228         {
229             m_builder.choiceOrMergeCastorNameScopePriorityTypes(buildItem("scope", "name", "-1"), buildItem("scope", "name", "-1"));
230             fail("Exception should have been occuried before this line.");
231         }
232         catch (Exception ex)
233         {
234             assertTrue(ex instanceof JPConfigException);
235         }
236         // failed sub-case: exception occuried: two identical sections + depth = section
237         try
238         {
239             JPatternsConfigBeansBuilderImpl.setOverridingDepth(PropertiesProvider.OverridingDepths.OVERRIDING_LEVEL_SECTION.toString());
240             m_builder.choiceOrMergeCastorNameScopePriorityTypes(buildConfigSection("scope", "name", "-1"),
241                 buildConfigSection("scope", "name", "-1"));
242             fail("Exception should have been occuried before this line.");
243         }
244         catch (Exception ex)
245         {
246             assertTrue(ex instanceof JPConfigException);
247         }
248         // normal sub-case: no exception: two identical sections, but the depth is item
249         try
250         {
251             JPatternsConfigBeansBuilderImpl.setOverridingDepth(PropertiesProvider.OverridingDepths.OVERRIDING_LEVEL_ITEM.toString());
252             final CastorConfigType section1 = buildConfigSection("scope", "name", "-1");
253             final Item item1 = new Item();
254             section1.addItem(item1);
255             final CastorConfigType section2 = buildConfigSection("scope", "name", "-1");
256             final Item item2 = new Item();
257             section2.addItem(item2);
258             final CastorNameScopePriorityType castorNameScopePriorityType =
259                 m_builder.choiceOrMergeCastorNameScopePriorityTypes(section1, section2);
260             assertNotNull(castorNameScopePriorityType);
261             assertTrue(castorNameScopePriorityType instanceof CastorSectionType);
262             assertEquals(((CastorConfigType) castorNameScopePriorityType).getItem().length, 2);
263         }
264         catch (Exception ex)
265         {
266             LoggingUtils.logException(LOG, ex, null, null);
267             fail("Exception should not occur for that case " + ex.getMessage());
268         }
269         // normal sub-case: no exception: different priorities: all the cases
270         try
271         {
272             // A: not prioritized
273             CastorNameScopePriorityType object1 = build("scope", "name", "-1");
274             CastorNameScopePriorityType object2 = build("scope", "name", "1");
275             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object2);
276             object1 = build("scope", "name", "1");
277             object2 = build("scope", "name", "-1");
278             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object1);
279             // B: both prioritized
280             object1 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "-1");
281             object2 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "1");
282             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object2);
283             object1 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "1");
284             object2 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "-1");
285             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object1);
286             // C: only one is prioritized: two possible cases depending on the property
287             // C:a
288             JPatternsConfigBeansBuilderImpl.setOverrideNotDependingOnPriority(false);
289             object1 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "10");
290             object2 = build("scope", "name", "1");
291             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object1);
292             object1 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "1");
293             object2 = build("scope", "name", "10");
294             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object2);
295             // C:b
296             JPatternsConfigBeansBuilderImpl.setOverrideNotDependingOnPriority(true);
297             object1 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "10");
298             object2 = build("scope", "name", "1");
299             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object1);
300             object1 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "1");
301             object2 = build("scope", "name", "10");
302             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object1);
303             // C:c
304             JPatternsConfigBeansBuilderImpl.setOverrideNotDependingOnPriority(false);
305             object1 = build("scope", "name", "1");
306             object2 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "10");
307             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object2);
308             object1 = build("scope", "name", "10");
309             object2 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "1");
310             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object1);
311             // C:d
312             JPatternsConfigBeansBuilderImpl.setOverrideNotDependingOnPriority(true);
313             object1 = build("scope", "name", "10");
314             object2 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "1");
315             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object2);
316             object1 = build("scope", "name", "1");
317             object2 = build("scope", "name", JPConstants.PRIORITIZED_PRIOTITY_PREFIX + "10");
318             assertEquals(m_builder.choiceOrMergeCastorNameScopePriorityTypes(object1, object2), object2);
319         }
320         catch (Exception ex)
321         {
322             LoggingUtils.logException(LOG, ex, null, null);
323             fail("Exception should not occur for that case " + ex.getMessage());
324         }
325     }
326 
327     /**
328      * Build CastorSectionType object from the provided simple data.
329      *
330      * @param scope    scope name
331      * @param name     section name
332      * @param priority priority to be set
333      *
334      * @return the target CastorSectionType object
335      */
336     private CastorConfigType buildConfigSection(final String scope, final String name, final String priority)
337     {
338         InputArgumentUtils.checkStrings(true, scope, name, priority);
339         final CastorConfigType result = new CastorConfigType();
340         result.setScope(scope);
341         result.setName(name);
342         result.setPriority(priority);
343 
344         return result;
345     }
346 
347     /**
348      * Build CastorItemType object from the provided simple data.
349      *
350      * @param scope    scope name
351      * @param name     section name
352      * @param priority priority to be set
353      *
354      * @return the target CastorItemType object
355      */
356     private CastorItemType buildItem(final String scope, final String name, final String priority)
357     {
358         InputArgumentUtils.checkStrings(true, scope, name, priority);
359         final CastorItemType result = new CastorItemType();
360         result.setScope(scope);
361         result.setName(name);
362         result.setPriority(priority);
363 
364         return result;
365     }
366 
367     /**
368      * Build CastorNameScopePriorityType object from the provided simple data.
369      *
370      * @param scope    scope name
371      * @param name     section name
372      * @param priority priority to be set
373      *
374      * @return the target CastorItemType object
375      */
376     private CastorNameScopePriorityType build(final String scope, final String name, final String priority)
377     {
378         InputArgumentUtils.checkStrings(true, scope, name, priority);
379         final CastorNameScopePriorityType result = new CastorNameScopePriorityType();
380         result.setScope(scope);
381         result.setName(name);
382         result.setPriority(priority);
383 
384         return result;
385     }
386 
387     /**
388      * Tests {@link JPatternsConfigBeansBuilderImpl#fill}
389      *
390      * @throws Exception in the case smth. wrong occuried.
391      * @forversion 1.0
392      */
393     public void testFill() throws Exception
394     {
395         // failed sub-case: exception occuried: check the null inputs
396         try
397         {
398             m_builder.fill(null, null);
399             fail("Exception should have been occuried before this line.");
400         }
401         catch (Exception ex)
402         {
403             assertTrue(ex instanceof IllegalArgumentException);
404         }
405         // failed sub-case: exception occuried: check the null inputs
406         try
407         {
408             m_builder.fill(new JPatternsConfigBaseBean(), null);
409             fail("Exception should have been occuried before this line.");
410         }
411         catch (Exception ex)
412         {
413             assertTrue(ex instanceof IllegalArgumentException);
414         }
415         // failed sub-case: exception occuried: check the null inputs
416         try
417         {
418             m_builder.fill(null, new ArrayList<CastorSectionType>());
419             fail("Exception should have been occuried before this line.");
420         }
421         catch (Exception ex)
422         {
423             assertTrue(ex instanceof IllegalArgumentException);
424         }
425 
426         // normal sub-case: no exception: working with JPatternsConfigBeansBuilderImplTest.ConfigsForTest.CONFIG_1
427         try
428         {
429             final JPatternsConfig config = JPatternsTestUtils.getConfig(JPatternsConfigBeansBuilderImplTest.class, null,
430                 ConfigsForTest.CONFIG_1);
431             CastorUtils.validateAndNormalizeScopesPriorities(config);
432             final List<CastorSectionType> sections = CastorUtils.extractCastorSectionTypeObjects(config);
433             final JPatternsConfigBaseBean bean = new JPatternsConfigBaseBean();
434             m_builder.fill(bean, sections);
435             String scopeName = JPConstants.DEFAULT_SCOPE_NAME;
436             // A: check that ordinary not scoped and not prioritized elements are parsed correctly.
437             // check sections
438             assertNotNull(bean.getSection(scopeName, "GlobalSection1"));
439             assertNotNull(bean.getSection(scopeName, "GlobalSection2"));
440             assertNotNull(bean.getSection(scopeName, "GlobalSection3"));
441 
442             // check business items
443             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection1", scopeName, "GlobalSectionItem1"));
444             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem1"));
445             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem2"));
446             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", scopeName, "GlobalSectionItem1"));
447             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", scopeName, "GlobalSectionItem2"));
448 
449             // B: check that in the case sections are without scope and items are scoped it works fine
450             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", "GlobalItemScope1", "GlobalSectionItem2"));
451             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", "GlobalItemScope2", "GlobalSectionItem2"));
452             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", "GlobalItemScope2", "GlobalSectionItem3"));
453 
454             // C: check the scoped sections
455             scopeName = "GlobalScope1";
456             // check sections
457             assertNotNull(bean.getSection(scopeName, "GlobalSection1"));
458             assertNotNull(bean.getSection(scopeName, "GlobalSection2"));
459             assertNotNull(bean.getSection(scopeName, "GlobalSection3"));
460 
461             // check business items
462             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection1", scopeName, "GlobalSectionItem1"));
463             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection1", "GlobalItemScope1", "GlobalSectionItem1"));
464             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem1"));
465             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem2"));
466             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", scopeName, "GlobalSectionItem1"));
467             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", scopeName, "GlobalSectionItem2"));
468 
469             // D: check priorities work properly for sections
470             scopeName = JPConstants.DEFAULT_SCOPE_NAME;
471             CastorSectionType section = bean.getSection(scopeName, "GlobalSection4");
472             assertNotNull(section);
473             assertEquals(section.getPriority(), "1");
474             assertNull(bean.getBusinessItem(scopeName, "GlobalSection4", scopeName, "GlobalSectionItem4"));
475             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection4", scopeName, "GlobalSectionItem4_1"));
476             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection4", "GlobalItemScope4", "GlobalSectionItem4_2"));
477             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection4", "GlobalItemScope5", "GlobalSectionItem4_2"));
478         }
479         catch (Exception ex)
480         {
481             LoggingUtils.logException(LOG, ex, null, null);
482             fail("Exception should not occur for that case " + ex.getMessage());
483         }
484     }
485 
486     /**
487      * Tests {@link JPatternsConfigBeansBuilderImpl#build}
488      *
489      * @throws Exception in the case smth. wrong occuried.
490      * @forversion 1.0
491      */
492     public void testBuild() throws Exception
493     {
494         // failed sub-case: exception occuried: null inputs
495         try
496         {
497             m_builder.build((JPatternsConfig) null);
498             fail("Exception should have been occuried before this line.");
499         }
500         catch (Exception ex)
501         {
502             assertTrue(ex instanceof IllegalArgumentException);
503         }
504         // normal sub-case: no exception: check it works properly.
505         try
506         {
507             final JPatternsConfig config = JPatternsTestUtils.getConfig(JPatternsConfigBeansBuilderImplTest.class, null,
508                 ConfigsForTest.CONFIG_1);
509             final JPatternsConfigBean bean = m_builder.build(config);
510             assertNotNull(bean);
511             // check the additional info
512             assertEquals(bean.getCastorConfig(), config);
513             assertEquals(bean.getDefaultScope(), JPConstants.DEFAULT_SCOPE_NAME);
514 
515             // check the maps we would use later
516             assertNotNull(bean.getSection(JPConstants.DEFAULT_SCOPE_NAME, "GlobalSection1"));
517             assertNotNull(bean.getSection("GlobalScope1", "GlobalSection1"));
518             assertNotNull(bean.getBusinessItem(JPConstants.DEFAULT_SCOPE_NAME, "GlobalSection1",
519                 JPConstants.DEFAULT_SCOPE_NAME, "GlobalSectionItem1"));
520             assertNotNull(bean.getBusinessItem(JPConstants.DEFAULT_SCOPE_NAME, "GlobalSection2",
521                 JPConstants.DEFAULT_SCOPE_NAME, "GlobalSectionItem1"));
522             assertNotNull(bean.getBusinessItem("GlobalScope1", "GlobalSection1", "GlobalScope1", "GlobalSectionItem1"));
523             assertNotNull(bean.getBusinessItem("GlobalScope1", "GlobalSection1", "GlobalItemScope1", "GlobalSectionItem1"));
524             assertNotNull(bean.getBusinessItem("GlobalScope1", "GlobalSection2", "GlobalScope1", "GlobalSectionItem1"));
525             assertNotNull(bean.getBusinessItem("GlobalScope1", "GlobalSection2", "GlobalScope1", "GlobalSectionItem2"));
526         }
527         catch (Exception ex)
528         {
529             LoggingUtils.logException(LOG, ex, null, null);
530             fail("Exception should not occur for that case " + ex.getMessage());
531         }
532     }
533 
534     /**
535      * Tests {@link JPatternsConfigBeansBuilderImpl#build}
536      *
537      * @throws Exception in the case smth. wrong occuried.
538      * @forversion 1.0
539      */
540     public void testBuildConfigsBean() throws Exception
541     {
542         // failed sub-case: exception occuried: null inputs
543         try
544         {
545             m_builder.build((List<JPatternsConfigBaseBean>) null);
546             fail("Exception should have been occuried before this line.");
547         }
548         catch (Exception ex)
549         {
550             assertTrue(ex instanceof IllegalArgumentException);
551         }
552         // normal sub-case: no exception: check it works properly: please review the structure of appropriate JPatterns castor config files
553         // for the details.
554         try
555         {
556             final JPatternsConfig config1 = JPatternsTestUtils.getConfig(JPatternsConfigBeansBuilderImplTest.class, null,
557                 ConfigsForTest.CONFIG_1);
558             final JPatternsConfigBean bean1 = m_builder.build(config1);
559             assertNotNull(bean1);
560             final JPatternsConfig config2 = JPatternsTestUtils.getConfig(JPatternsConfigBeansBuilderImplTest.class, null,
561                 ConfigsForTest.CONFIG_2);
562             final JPatternsConfigBean bean2 = m_builder.build(config2);
563             assertNotNull(bean2);
564             final List<JPatternsConfigBaseBean> list = new ArrayList<JPatternsConfigBaseBean>();
565             list.add(bean1);
566             list.add(bean2);
567             final JPatternsConfigsBean bean = m_builder.build(list);
568             assertNotNull(bean);
569 
570             // A. global section 1
571             String scopeName = JPConstants.DEFAULT_SCOPE_NAME;
572             assertNotNull(bean.getSection(scopeName, "GlobalSection1"));
573             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection1", scopeName, "GlobalSectionItem1"));
574             scopeName = "DEFAULT_SCOPE_2";
575             assertNotNull(bean.getSection(scopeName, "GlobalSection1"));
576             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection1", scopeName, "GlobalSectionItem1"));
577 
578             // B. global section 2
579             scopeName = JPConstants.DEFAULT_SCOPE_NAME;
580             assertNotNull(bean.getSection(scopeName, "GlobalSection2"));
581             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem10"));
582             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem20"));
583             // !!! null as it was overriden.
584             assertNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem1"));
585             assertNull(bean.getBusinessItem(scopeName, "GlobalSection2", scopeName, "GlobalSectionItem2"));
586 
587             // C. global section 2
588             scopeName = "GlobalScope1";
589             assertNotNull(bean.getSection(scopeName, "GlobalSection3"));
590             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", scopeName, "GlobalSectionItem1"));
591             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection3", scopeName, "GlobalSectionItem2"));
592             // !!! 
593             assertNotNull(bean.getBusinessItem(JPConstants.DEFAULT_SCOPE_NAME, "GlobalSection3",
594                 JPConstants.DEFAULT_SCOPE_NAME, "GlobalSectionItem1"));
595             assertNotNull(bean.getBusinessItem(JPConstants.DEFAULT_SCOPE_NAME, "GlobalSection3",
596                 JPConstants.DEFAULT_SCOPE_NAME, "GlobalSectionItem1"));
597             assertNotNull(bean.getBusinessItem(JPConstants.DEFAULT_SCOPE_NAME, "GlobalSection3", "GlobalItemScope1", "GlobalSectionItem2"));
598             assertNotNull(bean.getBusinessItem(JPConstants.DEFAULT_SCOPE_NAME, "GlobalSection3",
599                 JPConstants.DEFAULT_SCOPE_NAME, "GlobalSectionItem2"));
600 
601             // D. global section 5
602             scopeName = JPConstants.DEFAULT_SCOPE_NAME;
603             assertNotNull(bean.getSection(scopeName, "GlobalSection5"));
604             assertNotNull(bean.getBusinessItem(scopeName, "GlobalSection5", scopeName, "GlobalSectionItem5"));
605             assertNull(bean.getBusinessItem(scopeName, "GlobalSection5", scopeName, "GlobalSectionItem5_2"));
606         }
607         catch (Exception ex)
608         {
609             LoggingUtils.logException(LOG, ex, null, null);
610             fail("Exception should not occur for that case " + ex.getMessage());
611         }
612     }
613 }