merge the formfield patch from ooo-build
[ooovba.git] / qadevOOo / runner / base / java_fat_service.java
blobfe3716a63975e6934f10830c6c16303c09892a08
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: java_fat_service.java,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package base;
34 import java.io.PrintWriter;
36 import lib.TestParameters;
37 import lib.TestCase;
38 import lib.MultiMethodTest;
39 import lib.TestEnvironment;
40 import util.DynamicClassLoader;
42 import com.sun.star.lang.XMultiServiceFactory;
44 import share.DescEntry;
45 import share.DescGetter;
46 import helper.APIDescGetter;
47 import base.TestBase;
49 import share.LogWriter;
50 import stats.Summarizer;
52 /**
53 * this class handles tests written in java and running on a fat Office
54 * with the runner as a service.
56 public class java_fat_service implements TestBase {
58 static protected boolean debug = false;
59 protected LogWriter log = null;
61 public boolean executeTest(lib.TestParameters param) {
62 DynamicClassLoader dcl = new DynamicClassLoader();
63 log = (LogWriter)dcl.getInstance((String)param.get("LogWriter"));
64 debug = ((Boolean) param.get("DebugIsActive")).booleanValue();
66 DescGetter dg = new APIDescGetter();
67 String job = (String) param.get("TestJob");
68 boolean retValue = true;
70 //get Job-Descriptions
71 log.println("Getting Descriptions for Job: "+job);
72 DescEntry[] entries = dg.getDescriptionFor(job,
73 (String) param.get("DescriptionPath"),debug);
75 if (entries == null ) {
76 log.println("Couldn't get Description for Job");
77 return false;
80 String conStr = (String) param.get("ConnectionString");
82 XMultiServiceFactory msf = (XMultiServiceFactory)param.getMSF();
84 for (int l=0;l<entries.length;l++) {
86 if (entries[l] == null ) {
87 continue;
90 if (entries[l].hasErrorMsg) {
91 log.println(entries[l].ErrorMsg);
92 continue;
95 DescEntry entry = entries[l];
97 //get some helper classes
98 Summarizer sumIt = new Summarizer();
100 TestCase tCase = null;
101 try {
102 tCase = (TestCase)
103 dcl.getInstance("mod._"+entry.entryName);
104 } catch (java.lang.IllegalArgumentException ie) {
105 entry.ErrorMsg=ie.getMessage();
106 entry.hasErrorMsg=true;
109 if (tCase == null) {
110 sumIt.summarizeDown(entry,entry.ErrorMsg);
111 LogWriter sumObj = (LogWriter)dcl.getInstance(
112 (String)param.get("OutProducer"));
113 sumObj.initialize(entry,true);
114 entry.UserDefinedParams = param;
115 sumObj.summary(entry);
116 continue;
119 log.println("Creating: "+tCase.getObjectName());
121 log.initialize(entry,true);
122 entry.UserDefinedParams = param;
123 TestEnvironment tEnv = null;
124 try {
125 tCase.setLogWriter((PrintWriter) log);
126 tCase.initializeTestCase(param);
127 tEnv = tCase.getTestEnvironment(param);
128 } catch (Exception e) {
129 log.println("Exception while creating "+tCase.getObjectName());
130 log.println("Exception: " + e);
131 log.println("Message "+e.getMessage());
132 tEnv = null;
134 if (tEnv == null) {
135 sumIt.summarizeDown(entry,"Couldn't create "+tCase.getObjectName());
136 LogWriter sumObj = (LogWriter)dcl.getInstance(
137 (String)param.get("OutProducer"));
138 sumObj.initialize(entry,true);
139 entry.UserDefinedParams = param;
140 sumObj.summary(entry);
141 continue;
143 log.println("Created "+tCase.getObjectName()+"\n");
145 for (int j=0;j<entry.SubEntryCount;j++) {
146 if (!entry.SubEntries[j].isToTest) {
147 Summarizer.summarizeDown(entry.SubEntries[j],"not part of the job");
148 continue;
151 log.println("running: "+entry.SubEntries[j].entryName);
153 LogWriter ifclog = (LogWriter)dcl.getInstance(
154 (String)param.get("LogWriter"));
156 ifclog.initialize(entry.SubEntries[j],true);
157 entry.SubEntries[j].UserDefinedParams = param;
158 entry.SubEntries[j].Logger = ifclog;
160 if (tEnv == null || tEnv.isDisposed()) {
161 tEnv = getEnv(entry,param);
164 MultiMethodTest ifc = null;
165 lib.TestResult res = null;
166 try {
167 ifc = (MultiMethodTest) dcl.getInstance(
168 entry.SubEntries[j].entryName);
169 res = ifc.run(entry.SubEntries[j],tEnv,param);
170 } catch (IllegalArgumentException iae) {
171 log.println("Couldn't load class "+entry.SubEntries[j].entryName);
172 log.println("**** "+iae.getMessage()+" ****");
173 Summarizer.summarizeDown(entry.SubEntries[j],iae.getMessage());
174 } catch (java.lang.RuntimeException e) {
175 tEnv = getEnv(entry,param);
176 ifc = (MultiMethodTest) dcl.getInstance(
177 entry.SubEntries[j].entryName);
178 if ((tEnv != null) && (ifc != null)) {
179 res = ifc.run(entry.SubEntries[j],tEnv,param);
180 } else res = null;
182 if (res != null) {
183 for (int k=0;k<entry.SubEntries[j].SubEntryCount;k++) {
184 if (res.hasMethod(entry.SubEntries[j].SubEntries[k].entryName)) {
185 entry.SubEntries[j].SubEntries[k].State=
186 res.getStatusFor(entry.SubEntries[j].SubEntries[k].entryName).toString();
190 sumIt.summarizeUp(entry.SubEntries[j]);
192 LogWriter sumIfc = (LogWriter)dcl.getInstance(
193 (String)param.get("OutProducer"));
195 sumIfc.initialize(entry.SubEntries[j],true);
196 entry.SubEntries[j].UserDefinedParams = param;
197 sumIfc.summary(entry.SubEntries[j]);
199 try {
200 tCase.cleanupTestCase(param);
201 } catch (Exception e) {
202 e.printStackTrace((PrintWriter)log);
204 sumIt.summarizeUp(entry);
205 LogWriter sumObj = (LogWriter)dcl.getInstance(
206 (String)param.get("OutProducer"));
207 sumObj.initialize(entry,true);
208 sumObj.summary(entry);
210 if (entries.length > 1) {
211 log.println("");
212 int counter = 0;
213 log.println("Failures that appeared during scenario execution:");
214 for (int i=0;i<entries.length;i++) {
215 if (! entries[i].State.endsWith("OK")) {
216 log.println("\t "+entries[i].longName);
217 counter++;
220 log.println(counter +" of "+entries.length + " tests failed" );
223 return retValue;
226 protected TestEnvironment getEnv(DescEntry entry, TestParameters param) {
227 DynamicClassLoader dcl = new DynamicClassLoader();
228 log = (LogWriter)dcl.getInstance((String)param.get("LogWriter"));
229 XMultiServiceFactory msf = (XMultiServiceFactory)param.getMSF();
231 TestCase tCase = null;
233 try {
234 tCase = (TestCase)
235 dcl.getInstance("mod._"+entry.entryName);
236 } catch (java.lang.IllegalArgumentException ie) {
237 entry.ErrorMsg=ie.getMessage();
238 entry.hasErrorMsg=true;
241 log.println("Creating: "+tCase.getObjectName());
242 LogWriter log = (LogWriter)dcl.getInstance(
243 (String)param.get("LogWriter"));
244 log.initialize(entry,true);
245 entry.UserDefinedParams = param;
246 tCase.setLogWriter((PrintWriter) log);
247 TestEnvironment tEnv = null;
248 try {
249 tCase.initializeTestCase(param);
250 tEnv = tCase.getTestEnvironment(param);
251 } catch (com.sun.star.lang.DisposedException de) {
252 log.println("Office disposed");
254 return tEnv;
257 protected void shortWait(int millis) {
258 try {
259 Thread.sleep(millis);
260 } catch (java.lang.InterruptedException ie) {}