1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 package base;
28 
29 import complexlib.ComplexTestCase;
30 import util.DynamicClassLoader;
31 import share.DescGetter;
32 import stats.OutProducerFactory;
33 import helper.ComplexDescGetter;
34 import helper.AppProvider;
35 import helper.CfgParser;
36 import share.DescEntry;
37 import share.LogWriter;
38 import stats.Summarizer;
39 import lib.TestParameters;
40 import util.PropertyName;
41 
42 /**
43  * Test base for executing a java complex test.
44  * @see base.TestBase
45  */
46 public class java_complex implements TestBase
47 {
48 
49     /**
50      * This function executes the complex tests given as parameter "-o" or "TestJob". It querys for the correspond class
51      * and crates the JobDescription.
52      * @param param
53      * @return true of all tests run successfuly, esle false
54      */
55     public boolean executeTest(TestParameters param)
56     {
57 
58         // is there an ini file for the complex tests defined?
59         String complexIniFileName = ((String) param.get("ComplexIni"));
60         if (complexIniFileName != null)
61         {
62             CfgParser ini = new CfgParser(complexIniFileName);
63             ini.getIniParameters(param);
64         }
65 
66         // get the test job
67         String testJob = ((String) param.get("TestJob"));
68 
69         DescGetter descGetter = new ComplexDescGetter();
70         // get the test jobs
71         DescEntry[] entries = descGetter.getDescriptionFor(testJob, null, true);
72         return executeTest(param, entries);
73 
74     }
75 
76     /**
77      * This function run the given DescEntry[] as ComplexTest
78      * @param param
79      * @param entries
80      * @return true of all tests run successfuly, esle false
81      */
82     public boolean executeTest(TestParameters param, DescEntry[] entries)
83     {
84         // is there an ini file for the complex tests defined?
85         String complexIniFileName = ((String) param.get("ComplexIni"));
86         if (complexIniFileName != null)
87         {
88             CfgParser ini = new CfgParser(complexIniFileName);
89             ini.getIniParameters(param);
90         }
91 
92         DynamicClassLoader dcl = new DynamicClassLoader();
93         ComplexTestCase testClass = null;
94         boolean returnVal = true;
95 
96 //        the concept of the TimeOut depends on runner logs. If the runner log,
97 //        for exmaple to start a test method, the timeout was restet. This is not
98 //        while the test itself log something like "open docuent...".
99 //        An property of complex test could be that it have only one test method
100 //        which works for serveral minutes. Ih this case the TimeOut get not trigger
101 //        and the office was killed.
102 //        In complex tests just use "ThreadTimeOut" as timout.
103 
104         // param.put("TimeOut", new Integer(0));
105 
106         for (int i = 0; i < entries.length; i++)
107         {
108 
109             if (entries[i] == null)
110             {
111                 continue;
112             }
113             String iniName = entries[i].longName;
114             iniName = iniName.replace('.', '/');
115             CfgParser ini = new CfgParser(iniName + ".props");
116             ini.getIniParameters(param);
117 
118             LogWriter log = (LogWriter) dcl.getInstance((String) param.get("LogWriter"));
119 
120             AppProvider office = null;
121             if (!param.getBool("NoOffice"))
122             {
123                 try
124                 {
125                     office = (AppProvider) dcl.getInstance("helper.OfficeProvider");
126                     Object msf = office.getManager(param);
127                     if (msf == null)
128                     {
129                         returnVal = false;
130                         continue;
131                     }
132                     param.put("ServiceFactory", msf);
133                 }
134                 catch (IllegalArgumentException e)
135                 {
136                     office = null;
137                 }
138             }
139             log.initialize(entries[i], param.getBool(PropertyName.LOGGING_IS_ACTIVE));
140             entries[i].Logger = log;
141 
142             // create an instance
143             try
144             {
145                 testClass = (ComplexTestCase) dcl.getInstance(entries[i].longName);
146             }
147             catch (java.lang.Exception e)
148             {
149                 e.printStackTrace();
150                 return false;
151             }
152             testClass.executeMethods(entries[i], param);
153 
154             Summarizer sum = new Summarizer();
155             sum.summarizeUp(entries[i]);
156 
157             if (office != null)
158             {
159                 office.closeExistingOffice(param, false);
160             }
161 
162             LogWriter out = OutProducerFactory.createOutProducer(param);
163 
164             out.initialize(entries[i], true);
165             out.summary(entries[i]);
166             returnVal &= entries[i].State.endsWith("OK");
167         }
168         return returnVal;
169     }
170 }
171