1   package com.sourceforge.jpatterns.core.configuration;
2   
3   import com.sourceforge.jpatterns.core.JPConstants;
4   import com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException;
5   import com.sourceforge.jpatterns.core.configuration.model.IJPatternsConfigBeansBuilder;
6   import com.sourceforge.jpatterns.core.configuration.model.JPatternsConfigBeansBuilderImpl;
7   import com.sourceforge.jpatterns.core.configuration.model.JPatternsConfigBeansBuilderMockImpl;
8   import com.sourceforge.jpatterns.utils.JPatternsPropsUtils;
9   import com.sourceforge.jpatterns.utils.junit.JPatternsTestUtils;
10  import com.zmicer.utils.LoggingUtils;
11  import com.zmicer.utils.ReflexionUtils;
12  import junit.framework.Test;
13  import junit.framework.TestCase;
14  import junit.framework.TestSuite;
15  import org.apache.log4j.Logger;
16  
17  import java.util.Set;
18  
19  /**
20   * Please be noticed the "testdata/jpatterns_custom.properties" is used as the custom jpatterns framework properties for the tests.
21   *
22   * $Author:: zmicer             $<br/>
23   * $Rev:: 67                    $<br/> * $Date:: 2007-08-28 21:37:07 #$<br/>
24   * $Date:: 2007-08-28 21:37:07 #$<br/>
25   */
26  public class PropertiesManagerImplTest extends TestCase
27  {
28      /**
29       * Logger instance.
30       */
31      final private static Logger LOG = Logger.getLogger(PropertiesManagerImplTest.class);
32  
33      /**
34       * Instance of the class to be checked.
35       */
36      private IPropertiesManager m_propertiesManager = PropertiesBasedFactory.getInstance().getPropertiesManager();
37  
38      /**
39       * KEY_FOR_TEST - this key would be always at the properties file we would use for this test
40       */
41      final private static String KEY_FOR_TEST = ReflexionUtils.getBaseName(IJPatternsConfigBeansBuilder.class);
42  
43      /**
44       * Value for test
45       */
46      final private static String VALUE_FOR_TEST = JPatternsConfigBeansBuilderImpl.class.getName();
47  
48      /**
49       * Overriden value for test
50       */
51      final private static String OVERRIDEN_VALUE_FOR_TEST = JPatternsConfigBeansBuilderMockImpl.class.getName();
52  
53      /**
54       * Interface defining the cases to be used
55       */
56      interface Cases
57      {
58          String ALL_PROPS = "allPropertiesCase";
59          String CUSTOM_PROP = "customPropertyCase";
60          String DEFAULT_PROP = "defaultPropertyCase";
61          String NO_PROPS = "noPropertiesCase";
62      }
63  
64      /**
65       * Contructor with name of test attribute.
66       *
67       * @param name name of the test
68       */
69      public PropertiesManagerImplTest(String name)
70      {
71          super(name);
72      }
73  
74      /**
75       * Perform the set up functionality for the test.
76       *
77       * @throws Exception may occur in the case of some problems
78       */
79      public void setUp() throws Exception
80      {
81          super.setUp();
82      }
83  
84      /**
85       * Perform the tear down functionality for the test
86       *
87       * @throws Exception may occur in the case of some problems
88       */
89      public void tearDown() throws Exception
90      {
91          super.tearDown();
92      }
93  
94      /**
95       * Test suite method
96       *
97       * @return the built test suite
98       */
99      public static Test suite()
100     {
101         return new TestSuite(PropertiesManagerImplTest.class);
102     }
103 
104     /**
105      * Tests {@link PropertiesManagerImpl#customConfigPresents}
106      *
107      * @throws Exception in the case smth. wrong occuried.
108      * @forversion 1.0
109      */
110     public void testCustomConfigPresents() throws Exception
111     {
112         JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
113         assertTrue(m_propertiesManager.customConfigPresents());
114         JPatternsTestUtils.resetJVMProps();
115 
116         /**
117          * not existed
118          */
119         JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.DEFAULT_PROP, null, "not_existed", true);
120         assertFalse(m_propertiesManager.customConfigPresents());
121         JPatternsTestUtils.resetJVMProps();
122     }
123 
124     /**
125      * Tests {@link PropertiesManagerImpl#defaultConfigPresents}
126      *
127      * @throws Exception in the case smth. wrong occuried.
128      * @forversion 1.0
129      */
130     public void testDefaultConfigPresents() throws Exception
131     {
132         JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
133         assertTrue(m_propertiesManager.defaultConfigPresents());
134         JPatternsTestUtils.resetJVMProps();
135 
136         JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.DEFAULT_PROP, null, null, true);
137         assertTrue(m_propertiesManager.defaultConfigPresents());
138         JPatternsTestUtils.resetJVMProps();
139 
140         // failed sub-case: exception occuried: default property is not specified.
141         try
142         {
143             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.CUSTOM_PROP, null, null, true);
144 
145             fail("Exception should have been occuried before this line.");
146         }
147         catch (Exception ex)
148         {
149             assertTrue(ex instanceof JPInitializationException);
150         }
151         finally
152         {
153             JPatternsTestUtils.resetJVMProps();
154         }
155     }
156 
157     /**
158      * Tests {@link PropertiesManagerImpl#initConfigs}
159      *
160      * @throws Exception in the case smth. wrong occuried.
161      * @forversion 1.0
162      */
163     public void testInitConfigs() throws Exception
164     {
165         // normal sub-case: no exception: all the bundles were found and loaded.
166         try
167         {
168             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
169 
170             assertTrue(m_propertiesManager.customConfigPresents());
171             assertTrue(m_propertiesManager.defaultConfigPresents());
172 
173             assertTrue(JPatternsPropsUtils.getDefaultBundleName().contains(
174                 JPConstants.PropertiesConfigFilesConstants.DEFAULT_PROPERTIES_BASE_NAME));
175             assertTrue(JPatternsPropsUtils.getCustomBundleName().contains(
176                 JPConstants.PropertiesConfigFilesConstants.CUSTOM_PROPERTIES_BASE_NAME));
177 
178             assertNotNull(m_propertiesManager.getBundle(KEY_FOR_TEST));
179             assertEquals(m_propertiesManager.getBundle(KEY_FOR_TEST), OVERRIDEN_VALUE_FOR_TEST);
180             assertNotNull(m_propertiesManager.getDefaultBundle(KEY_FOR_TEST));
181             assertEquals(m_propertiesManager.getDefaultBundle(KEY_FOR_TEST), VALUE_FOR_TEST);
182 
183             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, null,
184                 "PropertiesManagerTest_default", "PropertiesManagerTest_custom", true);
185             assertNotNull(m_propertiesManager.getBundle(KEY_FOR_TEST));
186             assertEquals(m_propertiesManager.getBundle(KEY_FOR_TEST), OVERRIDEN_VALUE_FOR_TEST);
187             assertNotNull(m_propertiesManager.getDefaultBundle(KEY_FOR_TEST));
188             assertEquals(m_propertiesManager.getDefaultBundle(KEY_FOR_TEST), VALUE_FOR_TEST);
189         }
190         catch (Exception ex)
191         {
192             LoggingUtils.logException(LOG, ex, null, null);
193             fail("Exception should not occur for that case params" + ex.getMessage());
194         }
195         finally
196         {
197             JPatternsTestUtils.resetJVMProps();
198         }
199     }
200 
201     /**
202      * Tests {@link PropertiesManagerImpl#getDefaultBundle}
203      *
204      * @throws Exception in the case smth. wrong occuried.
205      * @forversion 1.0
206      */
207     public void testGetDefaultBundle() throws Exception
208     {
209         // failed sub-case: exception occuried
210         try
211         {
212             m_propertiesManager.getDefaultBundle(null);
213             fail("Exception should have been occuried before this line.");
214         }
215         catch (Exception ex)
216         {
217             assertTrue(ex instanceof IllegalArgumentException);
218         }
219         // normal sub-case: no exception
220         try
221         {
222             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
223 
224             assertNotNull(m_propertiesManager.getDefaultBundle(KEY_FOR_TEST));
225             assertEquals(m_propertiesManager.getDefaultBundle(KEY_FOR_TEST), VALUE_FOR_TEST);
226 
227             // check the null is retrieved for the incorrect key (which is not present at the properties file)
228             assertNull(m_propertiesManager.getDefaultBundle(KEY_FOR_TEST + "1"));
229         }
230         catch (Exception ex)
231         {
232             LoggingUtils.logException(LOG, ex, null, null);
233             fail("Exception should not occur for that case params" + ex.getMessage());
234         }
235         finally
236         {
237             JPatternsTestUtils.resetJVMProps();
238         }
239         // failed sub-case: exception occuried: no default properties file.
240         try
241         {
242             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.NO_PROPS, null, null, true);
243 
244             fail("Exception should have been occuried before this line.");
245         }
246         catch (Exception ex)
247         {
248             JPatternsTestUtils.resetJVMProps();
249             assertTrue(ex instanceof JPInitializationException);
250         }
251 
252     }
253 
254     /**
255      * Tests {@link PropertiesManagerImpl#getBundle}
256      *
257      * @throws Exception in the case smth. wrong occuried.
258      * @forversion 1.0
259      */
260     public void testGetBundle() throws Exception
261     {
262         // failed sub-case: exception occuried
263         try
264         {
265             m_propertiesManager.getBundle((String) null);
266             fail("Exception should have been occuried before this line.");
267         }
268         catch (Exception ex)
269         {
270             assertTrue(ex instanceof IllegalArgumentException);
271         }
272 
273         // failed sub-case: exception occuried
274         try
275         {
276             m_propertiesManager.getBundle("");
277             fail("Exception should have been occuried before this line.");
278         }
279         catch (Exception ex)
280         {
281             assertTrue(ex instanceof IllegalArgumentException);
282         }
283 
284         // normal sub-case: no exception: no the custom properties.
285         try
286         {
287             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.DEFAULT_PROP, null, null, true);
288 
289             assertFalse(m_propertiesManager.customConfigPresents());
290 
291             // note: potentially we could insert here the checking logging was performed.
292             assertNull(m_propertiesManager.getCustomBundle(KEY_FOR_TEST));
293             final String result = m_propertiesManager.getDefaultBundle(KEY_FOR_TEST);
294             assertNotNull(result);
295             assertEquals(result, VALUE_FOR_TEST);
296             assertEquals(result, m_propertiesManager.getBundle(KEY_FOR_TEST));
297 
298             JPatternsTestUtils.resetJVMProps();
299         }
300         catch (Exception ex)
301         {
302             LoggingUtils.logException(LOG, ex, null, null);
303             fail("Exception should not occur for that case params" + ex.getMessage());
304         }
305 
306         // normal sub-case: no exception
307         try
308         {
309             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
310             assertNotNull(m_propertiesManager.getBundle(KEY_FOR_TEST));
311             assertEquals(m_propertiesManager.getBundle(KEY_FOR_TEST), OVERRIDEN_VALUE_FOR_TEST);
312         }
313         catch (Exception ex)
314         {
315             LoggingUtils.logException(LOG, ex, null, null);
316             fail("Exception should not occur for that case params" + ex.getMessage());
317         }
318         finally
319         {
320             JPatternsTestUtils.resetJVMProps();
321         }
322     }
323 
324     /**
325      * Tests {@link PropertiesManagerImpl#getBundle(Class)}
326      *
327      * @throws Exception in the case smth. wrong occuried.
328      * @forversion 1.0
329      */
330     public void testGetBundleByClass() throws Exception
331     {
332         // failed sub-case: exception occuried
333         try
334         {
335             m_propertiesManager.getBundle((Class) null);
336             fail("Exception should have been occuried before this line.");
337         }
338         catch (Exception ex)
339         {
340             assertTrue(ex instanceof IllegalArgumentException);
341         }
342         try
343         {
344             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
345 
346             assertNotNull(m_propertiesManager.getBundle(IJPatternsConfigBeansBuilder.class));
347             assertEquals(m_propertiesManager.getBundle(IJPatternsConfigBeansBuilder.class), OVERRIDEN_VALUE_FOR_TEST);
348             assertEquals(m_propertiesManager.getBundle(KEY_FOR_TEST), OVERRIDEN_VALUE_FOR_TEST);
349 
350             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.DEFAULT_PROP, null, null, true);
351 
352             assertNotNull(m_propertiesManager.getBundle(IJPatternsConfigBeansBuilder.class));
353             assertEquals(m_propertiesManager.getBundle(IJPatternsConfigBeansBuilder.class), VALUE_FOR_TEST);
354             assertEquals(m_propertiesManager.getBundle(KEY_FOR_TEST), VALUE_FOR_TEST);
355         }
356         catch (Exception ex)
357         {
358             LoggingUtils.logException(LOG, ex, null, null);
359             fail("Exception should not occur for that case params" + ex.getMessage());
360         }
361         finally
362         {
363             JPatternsTestUtils.resetJVMProps();
364         }
365 
366         // normal sub-case: no exception: check this for the default properties.
367         try
368         {
369             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.DEFAULT_PROP, null, null, true);
370 
371             assertNotNull(m_propertiesManager.getBundle(IJPatternsConfigBeansBuilder.class));
372             assertEquals(m_propertiesManager.getBundle(IJPatternsConfigBeansBuilder.class), VALUE_FOR_TEST);
373             assertEquals(m_propertiesManager.getBundle(KEY_FOR_TEST), VALUE_FOR_TEST);
374 
375             JPatternsTestUtils.resetJVMProps();
376         }
377         catch (Exception ex)
378         {
379             LoggingUtils.logException(LOG, ex, null, null);
380             fail("Exception should not occur for that case params" + ex.getMessage());
381         }
382 
383     }
384 
385     /**
386      * Tests {@link PropertiesManagerImpl#getInstance}
387      *
388      * @throws Exception in the case smth. wrong occuried.
389      * @forversion 1.0
390      */
391     public void testGetInstance() throws Exception
392     {
393         assertNotNull(m_propertiesManager);
394     }
395 
396     /**
397      * Tests {@link PropertiesManagerImpl#getCustomBundle}
398      *
399      * @throws Exception in the case smth. wrong occuried.
400      * @forversion 1.0
401      */
402     public void testGetCustomBundle() throws Exception
403     {
404         // 00: failed sub-case: exception occuried
405         try
406         {
407             m_propertiesManager.getDefaultBundle(null);
408             fail("Exception should have been occuried before this line.");
409         }
410         catch (Exception ex)
411         {
412             assertTrue(ex instanceof IllegalArgumentException);
413         }
414         // 01 : failed sub-case: exception occuried
415         try
416         {
417             m_propertiesManager.getDefaultBundle("");
418             fail("Exception should have been occuried before this line.");
419         }
420         catch (Exception ex)
421         {
422             assertTrue(ex instanceof IllegalArgumentException);
423         }
424         // 02: normal sub-case: no exception: just get the value from the custom properties which is exists.
425         try
426         {
427             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
428             final String value = m_propertiesManager.getCustomBundle(KEY_FOR_TEST);
429             assertNotNull(value);
430             assertEquals(value, OVERRIDEN_VALUE_FOR_TEST);
431         }
432         catch (Exception ex)
433         {
434             LoggingUtils.logException(LOG, ex, null, null);
435             fail("Exception should not occur for that case params" + ex.getMessage());
436         }
437         finally
438         {
439             JPatternsTestUtils.resetJVMProps();
440         }
441         // 03: normal sub-case: no exception: no the value for the key we would use
442         try
443         {
444             assertNull(m_propertiesManager.getCustomBundle(KEY_FOR_TEST + "notexistedkey"));
445         }
446         catch (Exception ex)
447         {
448             LoggingUtils.logException(LOG, ex, null, null);
449             fail("Exception should not occur for that case params" + ex.getMessage());
450         }
451         // 04: normal sub-case: no exception: check the case when there is not custom properties file. We would use JVM param.
452         try
453         {
454             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.DEFAULT_PROP, null, null, true);
455 
456             // note: potentially we could insert here the checking logging was performed.
457             assertNull(m_propertiesManager.getCustomBundle(KEY_FOR_TEST));
458 
459             JPatternsTestUtils.resetJVMProps();
460         }
461         catch (Exception ex)
462         {
463             LoggingUtils.logException(LOG, ex, null, null);
464             fail("Exception should not occur for that case params" + ex.getMessage());
465         }
466     }
467 
468     /**
469      * Tests {@link PropertiesManagerImpl#getBundledObject}
470      *
471      * @throws Exception in the case smth. wrong occuried.
472      * @forversion 1.0
473      */
474     public void testGetBundledObject() throws Exception
475     {
476         // failed sub-case: exception occuried
477         try
478         {
479             m_propertiesManager.getBundledObject((Class) null);
480             fail("Exception should have been occuried before this line.");
481         }
482         catch (Exception ex)
483         {
484             assertTrue(ex instanceof IllegalArgumentException);
485         }
486 
487         // failed sub-case: exception occuried
488         try
489         {
490             m_propertiesManager.getBundledObject((String) null);
491             fail("Exception should have been occuried before this line.");
492         }
493         catch (Exception ex)
494         {
495             assertTrue(ex instanceof IllegalArgumentException);
496         }
497 
498         // failed sub-case: exception occuried: no such value for this key
499         try
500         {
501             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
502             m_propertiesManager.getBundledObject(PropertiesManagerImplTest.class);
503             fail("Exception should have been occuried before this line.");
504         }
505         catch (Exception ex)
506         {
507             assertTrue(ex instanceof JPInitializationException);
508         }
509         finally
510         {
511             JPatternsTestUtils.resetJVMProps();
512         }
513         // failed sub-case: exception occuried: the case when the object can not be instantiated.
514         try
515         {
516             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
517             m_propertiesManager.getBundledObject(TestCase.class);
518             fail("Exception should have been occuried before this line.");
519         }
520         catch (Exception ex)
521         {
522             assertTrue(ex instanceof JPInitializationException);
523         }
524         finally
525         {
526             JPatternsTestUtils.resetJVMProps();
527         }
528         // failed sub-case: exception occuried: private constructor.
529         try
530         {
531             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
532             m_propertiesManager.getBundledObject(PropertiesBasedFactory.class);
533             fail("Exception should have been occuried before this line.");
534         }
535         catch (Exception ex)
536         {
537             assertTrue(ex instanceof JPInitializationException);
538         }
539         finally
540         {
541             JPatternsTestUtils.resetJVMProps();
542         }
543 
544         // normal sub-case: no exception: the mock implementation on default
545         try
546         {
547             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
548             final Object object = m_propertiesManager.getBundledObject(IJPatternsConfigBeansBuilder.class);
549             assertNotNull(object);
550             assertTrue(object instanceof JPatternsConfigBeansBuilderMockImpl);
551         }
552         catch (Exception ex)
553         {
554             LoggingUtils.logException(LOG, ex, null, null);
555             fail("Exception should not occur for that case params" + ex.getMessage());
556         }
557         finally
558         {
559             JPatternsTestUtils.resetJVMProps();
560         }
561         // normal sub-case: no exception: check the default implementation instantiation.
562         try
563         {
564             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
565             final Object object = m_propertiesManager.getBundledObject(IJPatternsConfigBeansBuilder.class);
566             assertNotNull(object);
567             assertTrue(object instanceof JPatternsConfigBeansBuilderMockImpl);
568         }
569         catch (Exception ex)
570         {
571             LoggingUtils.logException(LOG, ex, null, null);
572             fail("Exception should not occur for that case params" + ex.getMessage());
573         }
574         finally
575         {
576             JPatternsTestUtils.resetJVMProps();
577         }
578     }
579 
580     /**
581      * Tests {@link PropertiesManagerImpl#getMergedKeys}
582      *
583      * @throws Exception in the case smth. wrong occuried.
584      * @forversion 1.0
585      */
586     public void testGetMergedKeys() throws Exception
587     {
588         // normal sub-case: no exception: just checking the keys were merged.
589         try
590         {
591             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
592 
593             final Set<String> keys = m_propertiesManager.getMergedKeys();
594             assertNotNull(keys);
595             // not checking the size cause the custom property may be extended later.
596             assertTrue(keys.contains(KEY_FOR_TEST));
597             assertTrue(keys.contains(ReflexionUtils.getBaseName(TestCase.class)));
598             assertTrue(keys.contains(ReflexionUtils.getBaseName(PropertiesBasedFactory.class)));
599 
600             JPatternsTestUtils.resetJVMProps();
601         }
602         catch (Exception ex)
603         {
604             LoggingUtils.logException(LOG, ex, null, null);
605             fail("Exception should not occur for that case params" + ex.getMessage());
606         }
607 
608         // normal sub-case: no exception: the case of working with only default
609         try
610         {
611             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.DEFAULT_PROP, null, null, true);
612 
613             final Set<String> keys = m_propertiesManager.getMergedKeys();
614             assertNotNull(keys);
615             // not checking the size cause the custom property may be extended later.
616             assertTrue(keys.contains(KEY_FOR_TEST));
617             assertFalse(keys.contains(ReflexionUtils.getBaseName(TestCase.class)));
618             assertFalse(keys.contains(ReflexionUtils.getBaseName(PropertiesBasedFactory.class)));
619 
620             JPatternsTestUtils.resetJVMProps();
621         }
622         catch (Exception ex)
623         {
624             LoggingUtils.logException(LOG, ex, null, null);
625             fail("Exception should not occur for that case params" + ex.getMessage());
626         }
627 
628         // failed sub-case: exception occuried: the default configuration should be present anyway
629         try
630         {
631             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.CUSTOM_PROP, null, null, true);
632             final Set<String> keys = m_propertiesManager.getMergedKeys();
633             fail("Exception should have been occuried before this line.");
634         }
635         catch (Exception ex)
636         {
637             JPatternsTestUtils.resetJVMProps();
638             assertTrue(ex instanceof JPInitializationException);
639         }
640     }
641 
642     /**
643      * Tests {@link PropertiesManagerImpl#initUseOnlyCustomConfigIfPresent}
644      *
645      * @throws Exception in the case smth. wrong occuried.
646      * @forversion 1.0
647      */
648     public void testInitUseOnlyCustomConfigIfPresent() throws Exception
649     {
650         // normal sub-case: no exception: check the default case - the value if false
651         try
652         {
653             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
654 
655             ((PropertiesManagerImpl) m_propertiesManager).initUseOnlyCustomConfigIfPresent();
656             assertFalse(m_propertiesManager.useOnlyCustomConfigIfPresent());
657             // both properties presents
658             // from the default
659             String result = m_propertiesManager.getBundle(ReflexionUtils.getBaseName(IJPatternsConfigBeansBuilder.class));
660             assertNotNull(result);
661             assertEquals(result, JPatternsConfigBeansBuilderMockImpl.class.getName());
662 
663             // from the custom, overriden
664             result = m_propertiesManager.getDefaultBundle(ReflexionUtils.getBaseName(IJPatternsConfigBeansBuilder.class));
665             assertNotNull(result);
666             assertEquals(result, JPatternsConfigBeansBuilderImpl.class.getName());
667 
668             JPatternsTestUtils.resetJVMProps();
669         }
670         catch (Exception ex)
671         {
672             LoggingUtils.logException(LOG, ex, null, null);
673             fail("Exception should not occur for that case params" + ex.getMessage());
674         }
675         // normal sub-case: no exception: check the case when this property is true.
676         try
677         {
678             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, null,
679                 "PropertiesManagerTest_default", "PropertiesManagerTest_custom", true);
680 
681             // default is not playing
682             String result = m_propertiesManager.getDefaultBundle(ReflexionUtils.getBaseName(IJPatternsConfigBeansBuilder.class));
683             assertNotNull(result);
684             assertEquals(result, JPatternsConfigBeansBuilderImpl.class.getName());
685 
686             // from the custom, overriden
687             result = m_propertiesManager.getBundle(ReflexionUtils.getBaseName(IJPatternsConfigBeansBuilder.class));
688             assertNotNull(result);
689             assertEquals(result, JPatternsConfigBeansBuilderMockImpl.class.getName());
690         }
691         catch (Exception ex)
692         {
693             LoggingUtils.logException(LOG, ex, null, null);
694             fail("Exception should not occur for that case params" + ex.getMessage());
695         }
696 
697 
698     }
699 
700     /**
701      * Tests {@link PropertiesManagerImpl#useOnlyCustomConfigIfPresent}
702      *
703      * @throws Exception in the case smth. wrong occuried.
704      * @forversion 1.0
705      */
706     public void testUseOnlyCustomConfigIfPresent() throws Exception
707     {
708         // normal sub-case: no exception:
709         try
710         {
711             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
712             assertFalse(m_propertiesManager.useOnlyCustomConfigIfPresent());
713             JPatternsTestUtils.resetJVMProps();
714         }
715         catch (Exception ex)
716         {
717             LoggingUtils.logException(LOG, ex, null, null);
718             fail("Exception should not occur for that case params" + ex.getMessage());
719         }
720 
721     }
722 
723     /**
724      * Tests {@link PropertiesManagerImpl#checkIsInitialized}
725      *
726      * @throws Exception in the case smth. wrong occuried.
727      * @forversion 1.0
728      */
729     public void testCheckIsInitialized() throws Exception
730     {
731         // normal sub-case: no exception: just to call it.
732         try
733         {
734             JPatternsTestUtils.setJVMPropsParams(PropertiesManagerImplTest.class, false, Cases.ALL_PROPS, null, null, true);
735             assertTrue(m_propertiesManager.customConfigPresents());
736             ((PropertiesManagerImpl) m_propertiesManager).checkIsInitialized();
737         }
738         catch (Exception ex)
739         {
740             LoggingUtils.logException(LOG, ex, null, null);
741             fail("Exception should not occur for that case params" + ex.getMessage());
742         }
743 
744     }
745 }