1   package com.sourceforge.jpatterns.junit;
2   
3   import com.sourceforge.jpatterns.core.IJPEngine;
4   import com.sourceforge.jpatterns.core.JPConstants;
5   import com.sourceforge.jpatterns.core.JPEngineFactory;
6   import com.sourceforge.jpatterns.core.configuration.exceptions.JPInitializationException;
7   import com.sourceforge.jpatterns.patterns.factory.IJPFactory;
8   import com.sourceforge.jpatterns.utils.junit.JPatternsTestUtils;
9   import com.zmicer.utils.LoggingUtils;
10  import junit.framework.Test;
11  import junit.framework.TestCase;
12  import junit.framework.TestSuite;
13  import org.apache.log4j.Logger;
14  
15  /**
16   * $Author::                    $<br/>
17   * $Rev::                       $<br/>
18   * $Date::                      $<br/>
19   *
20   */
21  public class JPatternsSystemTests extends TestCase
22  {
23      /**
24       * Logger instance.
25       */
26      final public static Logger LOG = Logger.getLogger(JPatternsSystemTests.class);
27  
28      private void setDefaultJVMParams(boolean reloadPropManager)
29      {
30          JPatternsTestUtils.setJVMPropsParams(this.getClass(), true, null, null, null, reloadPropManager);
31          JPatternsTestUtils.setJVMXmlParams(this.getClass(), true, null, null, false);        
32      }
33  
34      /**
35       * Contructor with name of test attribute.
36       *
37       * @param name name of the test
38       */
39      public JPatternsSystemTests(String name)
40      {
41          super(name);
42      }
43  
44      /**
45       * Perform the set up functionality for the test.
46       *
47       * @throws Exception may occur in the case of some problems
48       */
49      public void setUp() throws Exception
50      {
51          super.setUp();
52          //JPatternsTestUtils.resetAll();
53      }
54  
55      /**
56       * Perform the tear down functionality for the test
57       *
58       * @throws Exception may occur in the case of some problems
59       */
60      public void tearDown() throws Exception
61      {
62          super.tearDown();
63      }
64  
65      /**
66       * Test suite method
67       *
68       * @return the built test suite
69       */
70      public static Test suite()
71      {
72          return new TestSuite(JPatternsSystemTests.class);
73      }
74  
75  
76  
77      public void testCase1() throws Exception
78      {
79          // normal sub-case: no exception:
80          try
81          {
82              setDefaultJVMParams(false);
83              IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
84          }
85         catch (Exception ex)
86          {
87              assertTrue(ex instanceof JPInitializationException);
88          }
89          finally
90          {
91              JPatternsTestUtils.resetAll();
92          }        
93      }
94  
95      public void testCase2() throws Exception{
96          // failed sub-case: exception occuried:
97          try
98          {
99              JPatternsTestUtils.resetAll();
100             setDefaultJVMParams(true);
101             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
102             //engine.getFactory("testFactory",null);
103             fail("Exception should have been occuried before this line.");
104         }
105         catch (Exception ex)
106         {
107             LoggingUtils.logException(LOG, ex, null, this.getClass());
108             assertTrue(ex instanceof JPInitializationException);
109         }
110         finally
111         {
112             JPatternsTestUtils.resetAll();
113         }        
114     }
115 
116     public void testCase3() throws Exception
117     {
118         // failed sub-case: exception occuried: JPInitializationException
119         try
120         {
121             setDefaultJVMParams(false);
122             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
123             IJPFactory factory = engine.getFactory("absentFactory", "absentScoupe");
124             fail("Exception should have been occuried before this line.");
125         }
126         catch (Exception ex)
127         {
128             LoggingUtils.logException(LOG, ex, null, this.getClass());
129             assertTrue(ex instanceof JPInitializationException);
130         }
131         finally
132         {
133             JPatternsTestUtils.resetAll();
134         }        
135     }
136 
137     public void testCase4() throws Exception
138     {
139         // failed sub-case: exception occuried: JPInitializationException 
140         try
141         {
142             setDefaultJVMParams(false);
143             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
144             IJPFactory factory = engine.getFactory("absentFactory", "absentScoupe");
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.resetAll();
154         }        
155     }
156 
157     public void testCase5() throws Exception
158     {
159         // failed sub-case: exception occuried: IllegalStateException
160         try
161         {
162             setDefaultJVMParams(false);
163             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
164             IJPFactory factory = engine.getFactory("notexists", null);
165             fail("Exception should have been occuried before this line.");    
166         }
167         catch (Exception ex)
168         {
169             assertTrue(ex instanceof JPInitializationException);
170         }
171         finally
172         {
173             JPatternsTestUtils.resetAll();
174         }        
175     }
176 
177     public void testCase6() throws Exception
178     {
179         // failed sub-case: exception occuried:
180         try
181         {
182             setDefaultJVMParams(false);
183             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
184             IJPFactory factory = engine.getFactory("notexists", null);
185             fail("Exception should have been occuried before this line.");
186         }
187         catch (Exception ex)
188         {
189             assertTrue(ex instanceof JPInitializationException);
190         }        
191     }
192 
193 
194     public void testCase7() throws Exception
195     {
196         // normal sub-case: no exception: 
197         try
198         {
199             setDefaultJVMParams(false);
200             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
201             IJPFactory factory = engine.getFactory("FactorySection_case7", "FactoryScope_systemtests");
202             
203             assertNotNull(factory);
204             Object item = factory.getImplementation("item1", null);
205             assertNotNull(item);
206         }
207         catch (Exception ex)
208         {
209             LoggingUtils.logException(LOG, ex, null, this.getClass());
210             fail("Exception should not occur for that case " + ex.getMessage());
211         }
212         finally
213         {
214             JPatternsTestUtils.resetAll();
215         }        
216     }
217     
218     public void testCase8() throws Exception
219     {
220         // normal sub-case: no exception: 
221         try
222         {
223             setDefaultJVMParams(false);
224             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
225             IJPFactory factory = engine.getFactory("FactorySection_case8", "FactoryScope_systemtests");
226             assertNotNull(factory);
227             Object item = factory.getImplementation("item1", null);
228             assertNotNull(item);               
229         }
230         catch (Exception ex)
231         {
232             LoggingUtils.logException(LOG, ex, null, this.getClass());
233             fail("Exception should not occur for that case " + ex.getMessage());
234         }
235         finally
236         {
237             JPatternsTestUtils.resetAll();
238         }
239     }
240 
241     public void testCase9() throws Exception
242     {
243         //failed sub-case: exception occuried:
244         try
245         {
246             setDefaultJVMParams(true);
247             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
248             fail("Exception should have been occuried before this line.");
249         }
250         catch (Exception ex)
251         {
252             LoggingUtils.logException(LOG, ex, null, this.getClass());
253             assertTrue(ex instanceof JPInitializationException);
254         }
255         finally
256         {
257             JPatternsTestUtils.resetAll();
258         }        
259     }
260 
261     public void testCase10() throws Exception
262     {
263         //failed sub-case: exception occuried:
264         try
265         {
266             setDefaultJVMParams(false);
267             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
268             IJPFactory factory = engine.getFactory("FactorySection_case10", "FactoryScope_systemtests");
269             assertNotNull(factory);
270             Object item = factory.getImplementation("item1", null);
271             assertNotNull(item);
272             fail("Exception should have been occuried before this line.");
273         }
274         catch (Exception ex)
275         {
276             assertTrue(ex instanceof JPInitializationException);
277         }
278         finally
279         {
280             JPatternsTestUtils.resetAll();
281         }        
282     }
283 
284     public void testCase11() throws Exception
285     {
286         //failed sub-case: exception occuried:
287         try
288         {
289             setDefaultJVMParams(true);
290             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
291             fail("Exception should have been occuried before this line.");
292         }
293         catch (Exception ex)
294         {
295             assertTrue(ex instanceof JPInitializationException);
296         }
297         finally
298         {
299             JPatternsTestUtils.resetAll();
300         }
301     }
302 
303     public void xtestCase12() throws Exception
304     {
305         //failed sub-case: exception occuried:
306         try
307         {
308             setDefaultJVMParams(true);
309             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.CONSUMER);
310             fail("Exception should have been occuried before this line.");
311         }
312         catch (Exception ex)
313         {
314             assertTrue(ex instanceof JPInitializationException);
315         }
316         finally
317         {
318             JPatternsTestUtils.resetAll();
319         }
320     }
321 
322     public void xtestCase13() throws Exception
323     {
324         //failed sub-case: exception occuried:
325         try
326         {
327             setDefaultJVMParams(true);
328             IJPEngine engine = JPEngineFactory.getJPEngine(JPConstants.EngineConfigCaregory.FRAMEWORK);
329             engine.getFactory("notexists_factory","notexists_scope");
330             fail("Exception should have been occuried before this line.");
331         }
332         catch (Exception ex)
333         {
334             throw ex;
335             //LoggingUtils.logException(LOG, ex, null, this.getClass());
336             //assertTrue(ex instanceof JPInitializationException);
337         }
338         finally
339         {
340             JPatternsTestUtils.resetAll();
341         }
342     }
343 
344 }