1ef39d40dSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3ef39d40dSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4ef39d40dSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5ef39d40dSAndrew Rist  * distributed with this work for additional information
6ef39d40dSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7ef39d40dSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8ef39d40dSAndrew Rist  * "License"); you may not use this file except in compliance
9ef39d40dSAndrew Rist  * with the License.  You may obtain a copy of the License at
10ef39d40dSAndrew Rist  *
11ef39d40dSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12ef39d40dSAndrew Rist  *
13ef39d40dSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14ef39d40dSAndrew Rist  * software distributed under the License is distributed on an
15ef39d40dSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16ef39d40dSAndrew Rist  * KIND, either express or implied.  See the License for the
17ef39d40dSAndrew Rist  * specific language governing permissions and limitations
18ef39d40dSAndrew Rist  * under the License.
19ef39d40dSAndrew Rist  *
20ef39d40dSAndrew Rist  *************************************************************/
21ef39d40dSAndrew Rist 
22ef39d40dSAndrew Rist 
23cdf0e10cSrcweir package base;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir import complexlib.ComplexTestCase;
26cdf0e10cSrcweir import util.DynamicClassLoader;
27cdf0e10cSrcweir import share.DescGetter;
28cdf0e10cSrcweir import stats.OutProducerFactory;
29cdf0e10cSrcweir import helper.ComplexDescGetter;
30cdf0e10cSrcweir import helper.AppProvider;
31cdf0e10cSrcweir import helper.CfgParser;
32cdf0e10cSrcweir import share.DescEntry;
33cdf0e10cSrcweir import share.LogWriter;
34cdf0e10cSrcweir import stats.Summarizer;
35cdf0e10cSrcweir import lib.TestParameters;
36cdf0e10cSrcweir import util.PropertyName;
37cdf0e10cSrcweir 
38cdf0e10cSrcweir /**
39cdf0e10cSrcweir  * Test base for executing a java complex test.
40cdf0e10cSrcweir  * @see base.TestBase
41cdf0e10cSrcweir  */
42cdf0e10cSrcweir public class java_complex implements TestBase
43cdf0e10cSrcweir {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir     /**
46cdf0e10cSrcweir      * This function executes the complex tests given as parameter "-o" or "TestJob". It querys for the correspond class
47cdf0e10cSrcweir      * and crates the JobDescription.
48cdf0e10cSrcweir      * @param param
4930acf5e8Spfg      * @return true of all tests run successfully, else false
50cdf0e10cSrcweir      */
executeTest(TestParameters param)51cdf0e10cSrcweir     public boolean executeTest(TestParameters param)
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir 
54cdf0e10cSrcweir         // is there an ini file for the complex tests defined?
55cdf0e10cSrcweir         String complexIniFileName = ((String) param.get("ComplexIni"));
56cdf0e10cSrcweir         if (complexIniFileName != null)
57cdf0e10cSrcweir         {
58cdf0e10cSrcweir             CfgParser ini = new CfgParser(complexIniFileName);
59cdf0e10cSrcweir             ini.getIniParameters(param);
60cdf0e10cSrcweir         }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir         // get the test job
63cdf0e10cSrcweir         String testJob = ((String) param.get("TestJob"));
64cdf0e10cSrcweir 
65cdf0e10cSrcweir         DescGetter descGetter = new ComplexDescGetter();
66cdf0e10cSrcweir         // get the test jobs
67cdf0e10cSrcweir         DescEntry[] entries = descGetter.getDescriptionFor(testJob, null, true);
68cdf0e10cSrcweir         return executeTest(param, entries);
69cdf0e10cSrcweir 
70cdf0e10cSrcweir     }
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     /**
73cdf0e10cSrcweir      * This function run the given DescEntry[] as ComplexTest
74cdf0e10cSrcweir      * @param param
75cdf0e10cSrcweir      * @param entries
7630acf5e8Spfg      * @return true of all tests run successfully, else false
77cdf0e10cSrcweir      */
executeTest(TestParameters param, DescEntry[] entries)78cdf0e10cSrcweir     public boolean executeTest(TestParameters param, DescEntry[] entries)
79cdf0e10cSrcweir     {
80cdf0e10cSrcweir         // is there an ini file for the complex tests defined?
81cdf0e10cSrcweir         String complexIniFileName = ((String) param.get("ComplexIni"));
82cdf0e10cSrcweir         if (complexIniFileName != null)
83cdf0e10cSrcweir         {
84cdf0e10cSrcweir             CfgParser ini = new CfgParser(complexIniFileName);
85cdf0e10cSrcweir             ini.getIniParameters(param);
86cdf0e10cSrcweir         }
87cdf0e10cSrcweir 
88cdf0e10cSrcweir         DynamicClassLoader dcl = new DynamicClassLoader();
89cdf0e10cSrcweir         ComplexTestCase testClass = null;
90cdf0e10cSrcweir         boolean returnVal = true;
91cdf0e10cSrcweir 
92cdf0e10cSrcweir //        the concept of the TimeOut depends on runner logs. If the runner log,
93bb6af6bcSPedro Giffuni //        for example to start a test method, the timeout was reset. This is not
94cdf0e10cSrcweir //        while the test itself log something like "open docuent...".
95cdf0e10cSrcweir //        An property of complex test could be that it have only one test method
96cdf0e10cSrcweir //        which works for serveral minutes. Ih this case the TimeOut get not trigger
97cdf0e10cSrcweir //        and the office was killed.
98cdf0e10cSrcweir //        In complex tests just use "ThreadTimeOut" as timout.
99cdf0e10cSrcweir 
100cdf0e10cSrcweir         // param.put("TimeOut", new Integer(0));
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         for (int i = 0; i < entries.length; i++)
103cdf0e10cSrcweir         {
104cdf0e10cSrcweir 
105cdf0e10cSrcweir             if (entries[i] == null)
106cdf0e10cSrcweir             {
107cdf0e10cSrcweir                 continue;
108cdf0e10cSrcweir             }
109cdf0e10cSrcweir             String iniName = entries[i].longName;
110cdf0e10cSrcweir             iniName = iniName.replace('.', '/');
111cdf0e10cSrcweir             CfgParser ini = new CfgParser(iniName + ".props");
112cdf0e10cSrcweir             ini.getIniParameters(param);
113cdf0e10cSrcweir 
114cdf0e10cSrcweir             LogWriter log = (LogWriter) dcl.getInstance((String) param.get("LogWriter"));
115cdf0e10cSrcweir 
116cdf0e10cSrcweir             AppProvider office = null;
117cdf0e10cSrcweir             if (!param.getBool("NoOffice"))
118cdf0e10cSrcweir             {
119cdf0e10cSrcweir                 try
120cdf0e10cSrcweir                 {
121cdf0e10cSrcweir                     office = (AppProvider) dcl.getInstance("helper.OfficeProvider");
122cdf0e10cSrcweir                     Object msf = office.getManager(param);
123cdf0e10cSrcweir                     if (msf == null)
124cdf0e10cSrcweir                     {
125cdf0e10cSrcweir                         returnVal = false;
126cdf0e10cSrcweir                         continue;
127cdf0e10cSrcweir                     }
128cdf0e10cSrcweir                     param.put("ServiceFactory", msf);
129cdf0e10cSrcweir                 }
130cdf0e10cSrcweir                 catch (IllegalArgumentException e)
131cdf0e10cSrcweir                 {
132cdf0e10cSrcweir                     office = null;
133cdf0e10cSrcweir                 }
134cdf0e10cSrcweir             }
135cdf0e10cSrcweir             log.initialize(entries[i], param.getBool(PropertyName.LOGGING_IS_ACTIVE));
136cdf0e10cSrcweir             entries[i].Logger = log;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir             // create an instance
139cdf0e10cSrcweir             try
140cdf0e10cSrcweir             {
141cdf0e10cSrcweir                 testClass = (ComplexTestCase) dcl.getInstance(entries[i].longName);
142cdf0e10cSrcweir             }
143cdf0e10cSrcweir             catch (java.lang.Exception e)
144cdf0e10cSrcweir             {
145cdf0e10cSrcweir                 e.printStackTrace();
146cdf0e10cSrcweir                 return false;
147cdf0e10cSrcweir             }
148cdf0e10cSrcweir             testClass.executeMethods(entries[i], param);
149cdf0e10cSrcweir 
150cdf0e10cSrcweir             Summarizer sum = new Summarizer();
151cdf0e10cSrcweir             sum.summarizeUp(entries[i]);
152cdf0e10cSrcweir 
153cdf0e10cSrcweir             if (office != null)
154cdf0e10cSrcweir             {
155cdf0e10cSrcweir                 office.closeExistingOffice(param, false);
156cdf0e10cSrcweir             }
157cdf0e10cSrcweir 
158cdf0e10cSrcweir             LogWriter out = OutProducerFactory.createOutProducer(param);
159cdf0e10cSrcweir 
160cdf0e10cSrcweir             out.initialize(entries[i], true);
161cdf0e10cSrcweir             out.summary(entries[i]);
162cdf0e10cSrcweir             returnVal &= entries[i].State.endsWith("OK");
163cdf0e10cSrcweir         }
164cdf0e10cSrcweir         return returnVal;
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir }
167