1   package com.sourceforge.jpatterns.core.configuration;
2   
3   import com.sourceforge.jpatterns.core.JPConstants;
4   import com.sourceforge.jpatterns.core.configuration.model.JPatternsConfigBean;
5   import com.sourceforge.jpatterns.core.configuration.model.JPatternsConfigsBean;
6   import com.sourceforge.jpatterns.schema.CastorNameScopePriorityType;
7   import com.sourceforge.jpatterns.schema.JPatternsConfig;
8   import com.sourceforge.jpatterns.utils.junit.JPatternsTestUtils;
9   import com.zmicer.utils.ClassPathUtils;
10  import com.zmicer.utils.FileUtils;
11  import com.zmicer.utils.LoggingUtils;
12  import com.zmicer.utils.MagicNumbers;
13  import com.zmicer.utils.ReflexionUtils;
14  import com.zmicer.utils.junit.ZmicerTestUtils;
15  import junit.framework.Test;
16  import junit.framework.TestCase;
17  import junit.framework.TestSuite;
18  import org.apache.log4j.Logger;
19  
20  import java.io.File;
21  import java.util.List;
22  
23  /**
24   * $Author:: zmicer             $<br/>
25   * $Rev:: 67                    $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
26   * $Date:: 2007-08-28 21:37:07 #$<br/>
27   */
28  public class JPConfiguratorImplTest extends TestCase
29  {
30      /**
31       * Logger instance.
32       */
33      final public static Logger LOG = Logger.getLogger(JPConfiguratorImplTest.class);
34  
35      /**
36       * Instance of the covered class to be used below in the tests
37       */
38      private JPConfiguratorImpl m_jpConfiguratorImpl;
39  
40      /**
41       * Instance of the class to be checked.
42       */
43      private IPropertiesManager m_propertiesManager = PropertiesBasedFactory.getInstance().getPropertiesManager();
44  
45      /**
46       * The base name of this test (it could be used as identifier for this test case related folder)
47       */
48      private static String baseName = ReflexionUtils.getBaseName(JPConfiguratorImplTest.class);
49  
50      
51      /**
52       * Method should be used to get something like this: jpatterns_1.properties, jpatterns_22.properties,
53       * i.e. jpatterns_number.properties.
54       * Using only for official purposes.
55       * @param number to be inserted into file name;
56       * @return String name of file with inserted number;
57       */
58      String getFullNumberedXMLOrPropertyFileName(int number, boolean isProperty, boolean isDefault)
59      {
60          String name;
61          if (isProperty)
62          {
63              if (isDefault)
64              {
65                  name = JPConstants.PropertiesConfigFilesConstants.DEFAULT_PROPERTIES_BASE_NAME;
66              }
67              else
68              {
69                  name = JPConstants.PropertiesConfigFilesConstants.CUSTOM_PROPERTIES_BASE_NAME;
70              }
71              //we need only file name, without extention
72              return name + "_" + number;
73          }
74          else
75          {
76              if (isDefault)
77              {
78                  StringBuffer strBuffName = new StringBuffer(
79                          JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME);
80                  strBuffName.insert(strBuffName.length()-MagicNumbers.FOUR, "_" + number);
81                  name = strBuffName.toString();
82              }
83              else
84              {
85                  StringBuffer strBuffName = new StringBuffer(
86                          JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME);
87                  strBuffName.insert(strBuffName.length()-MagicNumbers.FOUR, "_" + number);
88                  name = strBuffName.toString();
89              }
90          }
91          return name;
92      }
93  
94  
95      /**
96       * Interface defining the cases to be used
97       */
98      interface Cases
99      {
100         String ALL_PROPS = "allPropertiesCase";
101         String CUSTOM_XML = "customXML";
102         String NO_PROVIDED_DEFAULT_FILE_NAME = "noProvidedDefaultFileName";
103         String LIST_OF_FILES_CASE1 = "listOfFilesCase\\subcase1";
104         String LIST_OF_FILES_CASE2 = "listOfFilesCase\\subcase2";
105         String LIST_OF_FILES_CASE3 = "listOfFilesCase\\subcase3";
106         String INIT_CONFIGURATION_CASE1 = "InitConfiguration\\subcase1";
107         String INIT_CONFIGURATION_CASE2 = "InitConfiguration\\subcase2";
108 
109     }
110 
111     /**
112      * Contructor with name of test attribute.
113      *
114      * @param name name of the test
115      */
116     public JPConfiguratorImplTest(String name)
117     {
118         super(name);
119     }
120 
121     /**
122      * Perform the set up functionality for the test.
123      *
124      * @throws Exception may occur in the case of some problems
125      */
126     public void setUp() throws Exception
127     {
128         super.setUp();
129         JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, null, true);
130         JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, false);
131         m_jpConfiguratorImpl = new JPConfiguratorImpl();
132         JPatternsTestUtils.resetJVMProps();
133         JPatternsTestUtils.resetJVMXmlParams();
134     }
135 
136     /**
137      * Perform the tear down functionality for the test
138      *
139      * @throws Exception may occur in the case of some problems
140      */
141     public void tearDown() throws Exception
142     {
143         super.tearDown();
144     }
145 
146     /**
147      * Test suite method
148      *
149      * @return the built test suite
150      */
151     public static Test suite()
152     {
153         return new TestSuite(JPConfiguratorImplTest.class);
154     }
155 
156     /**
157      * Tests {@link JPConfiguratorImpl#JPConfiguratorImpl()}
158      *
159      * @throws Exception in the case smth. wrong occuried.
160      * @forversion 1.0
161      */
162     public void testCreation() throws Exception
163     {
164         assertNotNull(m_jpConfiguratorImpl);
165     }
166 
167     /**
168      * Tests {@link JPConfiguratorImpl#initConfiguration()}
169      *
170      * @throws Exception in the case smth. wrong occuried.
171      * @forversion 1.0
172      */
173     public void testInitConfiguration() throws Exception
174     {
175         // normal sub-case: no exception:
176         try
177         {
178             //get property and XML file names in first subcase folder
179             String propertyFileNameCase1 = getFullNumberedXMLOrPropertyFileName(MagicNumbers.ONE,true,true);
180             String XMLConfigFileNameCase1 = getFullNumberedXMLOrPropertyFileName(MagicNumbers.ONE,false,true);
181 
182             //get property and XML file names in second subcase folder
183             String propertyFileNameCase2 = getFullNumberedXMLOrPropertyFileName(MagicNumbers.TWO,true,true);
184             String XMLConfigFileNameCase2 = getFullNumberedXMLOrPropertyFileName(MagicNumbers.TWO,false,true);
185 
186             //setting correct folder: subcase1 folder and initializing config. 
187             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.INIT_CONFIGURATION_CASE1,
188                     propertyFileNameCase1, null, true);
189             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.INIT_CONFIGURATION_CASE1,
190                     XMLConfigFileNameCase1, false);
191             m_jpConfiguratorImpl.initConfiguration();
192 
193             //getting configurations that stored by our assuming in subcase1 folder and items from this configurations 
194             JPatternsConfigsBean frameworkConfig = m_jpConfiguratorImpl.getJPatternsFrameworkConfiguration();
195             JPatternsConfigsBean consumerConfig = m_jpConfiguratorImpl.getJPatternsConsumerConfiguration();
196             CastorNameScopePriorityType itemFromFirstConfigFramework =  frameworkConfig.getBusinessItem(
197                     "test_scope", "JPatternsGlobalConfiguration_framework", "test_scope", "case");
198             assertNotNull(itemFromFirstConfigFramework);
199 
200             CastorNameScopePriorityType itemFromFirstConfigConsumer = consumerConfig.getBusinessItem(
201                     "test_scope", "JPatternsGlobalConfiguration_consumer", "test_scope", "case");
202             assertNotNull(itemFromFirstConfigConsumer);
203 
204             //just setting correct folder: subcase2 folder
205             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.INIT_CONFIGURATION_CASE2,
206                     propertyFileNameCase2, null, false);
207             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.INIT_CONFIGURATION_CASE2,
208                     XMLConfigFileNameCase2, false);
209 
210             //getting configurations from configurator
211             frameworkConfig = m_jpConfiguratorImpl.getJPatternsFrameworkConfiguration();
212             consumerConfig = m_jpConfiguratorImpl.getJPatternsConsumerConfiguration();
213             CastorNameScopePriorityType itemFromFirstConfigFrameworkBeforeInit =  frameworkConfig.getBusinessItem(
214                     "test_scope", "JPatternsGlobalConfiguration_framework", "test_scope", "case");
215             assertNotNull(itemFromFirstConfigFrameworkBeforeInit);
216 
217             CastorNameScopePriorityType itemFromFirstConfigConsumerBeforeInit =  consumerConfig.getBusinessItem(
218                     "test_scope", "JPatternsGlobalConfiguration_consumer", "test_scope", "case");
219             assertNotNull(itemFromFirstConfigConsumerBeforeInit);
220 
221             //assuming that items from previous and current configs are equals
222             assertTrue(itemFromFirstConfigFramework.equals(itemFromFirstConfigFrameworkBeforeInit));
223             assertTrue(itemFromFirstConfigConsumer.equals(itemFromFirstConfigConsumerBeforeInit));
224 
225 
226             m_jpConfiguratorImpl.initConfiguration();
227 
228             //getting configs again -- after initialization
229             frameworkConfig = m_jpConfiguratorImpl.getJPatternsFrameworkConfiguration();
230             consumerConfig = m_jpConfiguratorImpl.getJPatternsConsumerConfiguration();
231             //getting items from new configs
232             CastorNameScopePriorityType itemFromSecondConfigFramework =  frameworkConfig.getBusinessItem(
233                     "test_scope", "JPatternsGlobalConfiguration_framework", "test_scope", "case");
234             CastorNameScopePriorityType itemFromSecondConfigConsumer =  consumerConfig.getBusinessItem(
235                     "test_scope", "JPatternsGlobalConfiguration_consumer", "test_scope", "case");
236 
237             //assuming that items from first and from last configs are differs
238             assertFalse(itemFromFirstConfigFramework.equals(itemFromSecondConfigFramework));
239             assertFalse(itemFromFirstConfigConsumer.equals(itemFromSecondConfigConsumer));
240         }
241         catch (Exception ex)
242         {
243             LoggingUtils.logException(LOG, ex, null, null);
244             fail("Exception should not occur for that case " + ex.getMessage());
245         }
246         finally
247         {
248             JPatternsTestUtils.resetJVMProps();
249             JPatternsTestUtils.resetJVMXmlParams();
250         }
251     }
252     
253 
254     /**
255      * Tests {@link JPConfiguratorImpl#getJPatternsFrameworkConfigurationFileName}
256      *
257      * @throws Exception in the case smth. wrong occuried.
258      * @forversion 1.0
259      */
260     public void testGetJPatternsFrameworkConfigurationFileName() throws Exception
261     {
262         // normal sub-case: no exception
263         try
264         {
265             // Not JVM param still properties define the name.
266             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.NO_PROVIDED_DEFAULT_FILE_NAME, null, null, true);
267             assertNotNull(
268                 m_propertiesManager.getBundle(JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME_PROPS_PARAM));
269             String name = m_jpConfiguratorImpl.getJPatternsFrameworkConfigurationFileName();
270             assertNotNull(name);
271             assertEquals(name, "jpatterns_framework_default.xml");
272             JPatternsTestUtils.resetJVMProps();
273 
274             // No JVM parameter and props parameters are passed. Just constant is returned.
275             name = m_jpConfiguratorImpl.getJPatternsFrameworkConfigurationFileName();
276             assertNotNull(name);
277             assertEquals(name, JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME);
278 
279             // the JVM is set
280             System.setProperty(JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME_JVM_PARAM,
281                 JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME + "_");
282             name = m_jpConfiguratorImpl.getJPatternsFrameworkConfigurationFileName();
283             assertNotNull(name);
284             assertEquals(name, JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME + "_");
285 
286             JPatternsTestUtils.resetJVMProps();
287         }
288         catch (Exception ex)
289         {
290             LoggingUtils.logException(LOG, ex, null, null);
291             fail("Exception should not occur for that case params" + ex.getMessage());
292         }
293     }
294 
295     /**
296      * Tests {@link JPConfiguratorImpl#getJPatternsFrameworkCustomConfigurationFileName}
297      *
298      * @throws Exception in the case smth. wrong occuried.
299      * @forversion 1.0
300      */
301     public void testGetJPatternsFrameworkCustomConfigurationFileName() throws Exception
302     {
303         // normal sub-case: no exception
304         try
305         {
306             // Not JVM param still properties define the name.
307             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, null, true);
308             JPatternsTestUtils.resetJVMXmlParams();
309             assertNotNull(
310                 m_propertiesManager.getBundle(JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME_PROPS_PARAM));
311             String name = m_jpConfiguratorImpl.getJPatternsFrameworkCustomConfigurationFileName();
312             assertNotNull(name);
313             assertEquals(name, "jpatterns_framework_custom2.xml");
314             JPatternsTestUtils.resetJVMProps();
315 
316             // No JVM parameter passed. Just constant is returned.
317             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.NO_PROVIDED_DEFAULT_FILE_NAME, null, null, true);
318             JPatternsTestUtils.resetJVMXmlParams();
319             name = m_jpConfiguratorImpl.getJPatternsFrameworkCustomConfigurationFileName();
320             assertNotNull(name);
321             assertEquals(name, JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME);
322             JPatternsTestUtils.resetJVMProps();
323 
324             // the JVM is set
325             System.setProperty(JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME_JVM_PARAM,
326                 JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME + "_");
327             name = m_jpConfiguratorImpl.getJPatternsFrameworkCustomConfigurationFileName();
328             assertNotNull(name);
329             assertEquals(name, JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME + "_");
330 
331             JPatternsTestUtils.resetJVMProps();
332         }
333         catch (Exception ex)
334         {
335             LoggingUtils.logException(LOG, ex, null, null);
336             fail("Exception should not occur for that case params" + ex.getMessage());
337         }
338     }
339 
340     /**
341      * Test {@link JPConfiguratorImpl#getJPatternsConsumerConfigurationFiles()}
342      *
343      * @throws Exception in the case smth. wrong occurred.
344      * @author Silent
345      * @forversion 1.0
346      */
347     public void testGetJPatternsConsumerConfigurationFiles() throws Exception
348     {
349         // normal sub-case: no exception:
350         try
351         {
352             //case 1: all 3 consumer files in the same directory
353             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.LIST_OF_FILES_CASE1, null, false);
354             m_jpConfiguratorImpl.initConsumerConfiguration();
355             List<File> fileList = m_jpConfiguratorImpl.getJPatternsConsumerConfigurationFiles();
356             assertNotNull(fileList);
357             assertEquals(MagicNumbers.THREE, fileList.size());
358             //JPatternsTestUtils.resetJVMProps();
359             JPatternsTestUtils.resetJVMXmlParams();
360         }
361         catch (Exception ex)
362         {
363             LoggingUtils.logException(LOG, ex, null, null);
364             fail("Exception should not occur for that case " + ex.getMessage());
365         }
366 
367         //failed sub-case2 (folder is empty) -  exception occuried: IllegalStateException 
368         JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.LIST_OF_FILES_CASE2, null, false);
369         try
370         {
371             m_jpConfiguratorImpl.initConsumerConfiguration();
372             fail("Exception should have been occuried before this line.");
373         }
374         catch (Exception ex)
375         {
376             assertTrue (ex instanceof IllegalStateException);
377         }
378         finally
379         {
380             JPatternsTestUtils.resetJVMXmlParams();                            
381         }
382 
383         //normal subcase 3: All consumer files are scattered into subfolders
384         try
385         {
386             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.LIST_OF_FILES_CASE3, null, false);
387             m_jpConfiguratorImpl.initConsumerConfiguration();
388             List<File> fileList2 = m_jpConfiguratorImpl.getJPatternsConsumerConfigurationFiles();
389             assertNotNull(fileList2);
390             assertEquals("count of consumer files in \'" + Cases.LIST_OF_FILES_CASE1 + "\' directory", MagicNumbers.FOUR, fileList2.size());
391             JPatternsTestUtils.resetJVMProps();
392             JPatternsTestUtils.resetJVMXmlParams();
393         }
394         catch (Exception ex)
395         {
396             LoggingUtils.logException(LOG, ex, null, null);
397             fail("Exception should not occur for that case " + ex.getMessage());
398         }
399     }
400 
401 
402     /**
403      * Tests {@link JPConfiguratorImpl#JPConfiguratorImpl}
404      *
405      * @throws Exception in the case smth. wrong occurred.
406      * @forversion 1.0
407      */
408     public void testJPConfiguratorImpl() throws Exception
409     {
410         assertNotNull(m_jpConfiguratorImpl);
411     }
412 
413     /**
414      * Tests {@link JPConfiguratorImpl#obtainJPatternsConfig}
415      *
416      * @throws Exception in the case smth. wrong occuried.
417      * @forversion 1.0
418      */
419     public void testObtainJPatternsConfig() throws Exception
420     {
421         // failed sub-case: exception occuried
422         try
423         {
424             m_jpConfiguratorImpl.obtainJPatternsConfig(null);
425             fail("Exception should have been occuried before this line.");
426         }
427         catch (Exception ex)
428         {
429             assertTrue(ex instanceof IllegalArgumentException);
430         }
431         // normal sub-case: no exception
432         try
433         {
434             final String fullFileName =
435                 ZmicerTestUtils.getFullTestDataFileName(JPConfiguratorImplTest.class, false, null, "jpatterns_framework.xml", true);
436             JPatternsConfigBean configBean =
437                 m_jpConfiguratorImpl.obtainJPatternsConfig(fullFileName);
438             assertNotNull(configBean);
439         }
440         catch (Exception ex)
441         {
442             LoggingUtils.logException(LOG, ex, null, null);
443             fail("Exception should not occur for that case params" + ex.getMessage());
444         }
445         // normal sub-case: no exception: the full file name
446         try
447         {
448             final String fullFileName =
449                 ZmicerTestUtils.getFullTestDataFileName(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, "jpatterns_framework.xml", true);
450             assertNotNull(fullFileName);
451             assertNotNull(m_jpConfiguratorImpl.obtainJPatternsConfig(fullFileName));
452         }
453         catch (Exception ex)
454         {
455             LoggingUtils.logException(LOG, ex, null, null);
456             fail("Exception should not occur for that case " + ex.getMessage());
457         }
458     }
459 
460     /**
461      * Tests {@link JPConfiguratorImpl#defaultJPatternsFrameworkConfigurationPresents}
462      *
463      * @throws Exception in the case smth. wrong occuried.
464      * @forversion 1.0
465      */
466     public void testDefaultJPatternsFrameworkConfigurationPresents() throws Exception
467     {
468         // normal sub-case: no exception
469         try
470         {
471             assertTrue(m_jpConfiguratorImpl.defaultJPatternsFrameworkConfigurationPresents());
472         }
473         catch (Exception ex)
474         {
475             LoggingUtils.logException(LOG, ex, null, null);
476             fail("Exception should not occur for that case params" + ex.getMessage());
477         }
478     }
479 
480     /**
481      * Tests {@link JPConfiguratorImpl#customJPatternsFrameworkConfigurationPresents}
482      *
483      * @throws Exception in the case smth. wrong occuried.
484      * @forversion 1.0
485      */
486     public void testCustomJPatternsFrameworkConfigurationPresents() throws Exception
487     {
488         // normal sub-case: no exception
489         try
490         {
491             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, null, true);
492             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, false);
493             m_jpConfiguratorImpl.initConfiguration();
494             assertTrue(m_jpConfiguratorImpl.customJPatternsFrameworkConfigurationPresents());
495             JPatternsTestUtils.resetJVMProps();
496             JPatternsTestUtils.resetJVMXmlParams();
497         }
498         catch (Exception ex)
499         {
500             LoggingUtils.logException(LOG, ex, null, null);
501             fail("Exception should not occur for that case params" + ex.getMessage());
502         }
503     }
504 
505     /**
506      * Tests {@link JPConfiguratorImpl#obtainJPatternsConfigs}
507      *
508      * @throws Exception in the case smth. wrong occuried.
509      * @forversion 1.0
510      */
511     public void testObtainJPatternsConfigs() throws Exception
512     {
513         // failed sub-case: exception occuried
514         try
515         {
516             m_jpConfiguratorImpl.obtainJPatternsConfigs(null);
517             fail("Exception should have been occuried before this line.");
518         }
519         catch (Exception ex)
520         {
521             assertTrue(ex instanceof IllegalArgumentException);
522         }
523 
524         // normal sub-case: no exception
525         try
526         {
527             // 00: init the consumer default configuration (was found at the classpath)
528             final List<String> classPathesStrings = ClassPathUtils.getClassPathes();
529             if (null == classPathesStrings || classPathesStrings.isEmpty())
530             {
531                 throw new IllegalStateException("The class path is not set correctly.");
532             }
533             classPathesStrings.add(ZmicerTestUtils.getFolderWithTestData());
534             final List<File> files = FileUtils.findFilesByREInClassPath(classPathesStrings, JPConstants.PATTERN);
535             assertNotNull(files);
536             final int filesCntr = files.size();
537             assertTrue(filesCntr > 0);
538             final List<JPatternsConfig> configs = m_jpConfiguratorImpl.obtainJPatternsConfigs(files);
539             assertNotNull(configs);
540             assertEquals(filesCntr, configs.size());
541         }
542         catch (Exception ex)
543         {
544             LoggingUtils.logException(LOG, ex, null, null);
545             fail("Exception should not occur for that case params" + ex.getMessage());
546         }
547     }
548 
549     /**
550      * Tests {@link JPConfiguratorImpl#mergeFrameworkConfigurations}
551      *
552      * @throws Exception in the case smth. wrong occuried.
553      * @forversion 1.0
554      */
555     public void testMergeFrameworkConfigurations() throws Exception
556     {
557         // normal sub-case: no exception: 1
558         try
559         {
560             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, null, true);
561             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, false);
562             m_jpConfiguratorImpl.initFrameworkConfiguration();
563             final JPatternsConfigsBean bean = m_jpConfiguratorImpl.getJPatternsFrameworkConfiguration();
564             assertNotNull(bean);
565             assertNotNull(bean.getListOfSectionItems());
566             // the bean is filled - it means the default configuration is used
567             assertFalse(bean.getListOfSectionItems().isEmpty());
568             // but the custom data is null - all is correct
569             assertNull(bean.getSection("NOT_DEFAULT_SCOPE", "JPatternsGlobalConfiguration"));
570             assertNull(bean.getBusinessItem("NOT_DEFAULT_SCOPE", "JPatternsGlobalConfiguration",
571                 "NOT_DEFAULT_SCOPE", "JPatternsConfigurationFactory"));
572             assertNotNull(bean.getSection("JPConfiguratorImplTest", "GlobalSection1"));
573             JPatternsTestUtils.resetJVMProps();
574             JPatternsTestUtils.resetJVMXmlParams();
575         }
576         catch (Exception ex)
577         {
578             LoggingUtils.logException(LOG, ex, null, null);
579             fail("Exception should not occur for that case " + ex.getMessage());
580         }
581         // failed sub-case: exception occuried: default configuration is not set too: 2
582         try
583         {
584             System.setProperty(JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME_JVM_PARAM,
585                 JPConstants.XMLConfigFilesConstants.DEFAULT_XML_FRAMEWORK_CONFIG_FILE_NAME + "_");
586             System.setProperty(JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME_JVM_PARAM,
587                 JPConstants.XMLConfigFilesConstants.CUSTOM_XML_FRAMEWORK_CONFIG_FILE_NAME + "_");
588             m_jpConfiguratorImpl.initFrameworkConfiguration();
589 
590             fail("Exception should have been occuried before this line.");
591         }
592         catch (Exception ex)
593         {
594             JPatternsTestUtils.resetJVMProps();
595             assertTrue(ex instanceof IllegalStateException);
596         }
597         // normal sub-case: no exception: the case 3
598         try
599         {
600             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.CUSTOM_XML, null, null, true);
601             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.CUSTOM_XML, null, false);
602             JPConfiguratorImpl.setUseOnlyCustomFrameworkConfigIfPresent(true);
603             m_jpConfiguratorImpl.initFrameworkConfiguration();
604             final JPatternsConfigsBean bean = m_jpConfiguratorImpl.getJPatternsFrameworkConfiguration();
605             assertNotNull(bean);
606             assertNotNull(bean.getListOfSectionItems());
607             assertFalse(bean.getListOfSectionItems().isEmpty());
608             // this check that only this configuration is set here.
609             assertEquals(bean.getListOfSectionItems().size(), 1);
610             // the custom configuration is set
611             assertNotNull(bean.getSection("DEFAULT_SCOPE", "JPatternsGlobalConfiguration"));
612             assertNotNull(bean.getBusinessItem("DEFAULT_SCOPE", "JPatternsGlobalConfiguration",
613                 "DEFAULT_SCOPE", "JPatternsConfigurationFactory"));
614             assertNull(bean.getSection("JPConfiguratorImplTest", "GlobalSection1"));
615             JPatternsTestUtils.resetJVMProps();
616             JPatternsTestUtils.resetJVMXmlParams();
617         }
618         catch (Exception ex)
619         {
620             LoggingUtils.logException(LOG, ex, null, null);
621             fail("Exception should not occur for that case " + ex.getMessage());
622         }
623         // normal sub-case: no exception: 4,5
624         try
625         {
626             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.CUSTOM_XML, null, null, true);
627             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.CUSTOM_XML, null, false);
628             JPConfiguratorImpl.setUseOnlyCustomFrameworkConfigIfPresent(false);
629             m_jpConfiguratorImpl.initFrameworkConfiguration();
630             final JPatternsConfigsBean bean = m_jpConfiguratorImpl.getJPatternsFrameworkConfiguration();
631             assertNotNull(bean);
632             assertNotNull(bean.getListOfSectionItems());
633             assertFalse(bean.getListOfSectionItems().isEmpty());
634             // this check that only this configuration is set here.
635             assertTrue(bean.getListOfSectionItems().size() > 1);
636             // the custom configuration is set
637             assertNotNull(bean.getSection("DEFAULT_SCOPE", "JPatternsGlobalConfiguration"));
638             assertNotNull(bean.getBusinessItem("DEFAULT_SCOPE", "JPatternsGlobalConfiguration",
639                 "DEFAULT_SCOPE", "JPatternsConfigurationFactory"));
640             assertNotNull(bean.getSection("JPConfiguratorImplTest", "GlobalSection1"));
641             JPatternsTestUtils.resetJVMProps();
642             JPatternsTestUtils.resetJVMXmlParams();
643         }
644         catch (Exception ex)
645         {
646             LoggingUtils.logException(LOG, ex, null, null);
647             fail("Exception should not occur for that case " + ex.getMessage());
648         }
649     }
650 
651     /**
652      * Tests {@link JPConfiguratorImpl#initFrameworkConfiguration}
653      *
654      * @throws Exception in the case smth. wrong occuried.
655      * @forversion 1.0
656      */
657     public void testInitFrameworkConfiguration() throws Exception
658     {
659         // normal sub-case: no exception: just check the merged configuration is not null
660         try
661         {
662             JPatternsTestUtils.setJVMPropsParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, null, true);
663             JPatternsTestUtils.setJVMXmlParams(JPConfiguratorImplTest.class, false, Cases.ALL_PROPS, null, false);
664             m_jpConfiguratorImpl.initFrameworkConfiguration();
665             final JPatternsConfigsBean bean = m_jpConfiguratorImpl.getJPatternsFrameworkConfiguration();
666             assertNotNull(bean);
667             JPatternsTestUtils.resetJVMProps();
668             JPatternsTestUtils.resetJVMXmlParams();
669         }
670         catch (Exception ex)
671         {
672             LoggingUtils.logException(LOG, ex, null, null);
673             fail("Exception should not occur for that case " + ex.getMessage());
674         }
675     }
676 }