bump product version to 4.1.6.2
[LibreOffice.git] / qadevOOo / runner / base / java_fat_service.java
blob2e507ff1e7f4e4daa24ea2dc3084230632a767a1
1 /*
2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 package base;
22 import java.io.PrintWriter;
24 import lib.TestParameters;
25 import lib.TestCase;
26 import lib.MultiMethodTest;
27 import lib.TestEnvironment;
28 import util.DynamicClassLoader;
30 import share.DescEntry;
31 import share.DescGetter;
32 import helper.APIDescGetter;
34 import share.LogWriter;
35 import stats.Summarizer;
37 /**
38 * this class handles tests written in java and running on a fat Office
39 * with the runner as a service.
41 public class java_fat_service implements TestBase {
43 static protected boolean debug = false;
44 protected LogWriter log = null;
46 public boolean executeTest(lib.TestParameters param) {
47 DynamicClassLoader dcl = new DynamicClassLoader();
48 log = (LogWriter)dcl.getInstance((String)param.get("LogWriter"));
49 debug = ((Boolean) param.get("DebugIsActive")).booleanValue();
51 DescGetter dg = new APIDescGetter();
52 String job = (String) param.get("TestJob");
53 boolean retValue = true;
55 //get Job-Descriptions
56 log.println("Getting Descriptions for Job: "+job);
57 DescEntry[] entries = dg.getDescriptionFor(job,
58 (String) param.get("DescriptionPath"),debug);
60 if (entries == null ) {
61 log.println("Couldn't get Description for Job");
62 return false;
65 param.get("ConnectionString");
67 param.getMSF();
69 for (int l=0;l<entries.length;l++) {
71 if (entries[l] == null ) {
72 continue;
75 if (entries[l].hasErrorMsg) {
76 log.println(entries[l].ErrorMsg);
77 continue;
80 DescEntry entry = entries[l];
82 //get some helper classes
83 Summarizer sumIt = new Summarizer();
85 TestCase tCase = null;
86 try {
87 tCase = (TestCase)
88 dcl.getInstance("mod._"+entry.entryName);
89 } catch (java.lang.IllegalArgumentException ie) {
90 entry.ErrorMsg=ie.getMessage();
91 entry.hasErrorMsg=true;
94 if (tCase == null) {
95 Summarizer.summarizeDown(entry,entry.ErrorMsg);
96 LogWriter sumObj = (LogWriter)dcl.getInstance(
97 (String)param.get("OutProducer"));
98 sumObj.initialize(entry,true);
99 entry.UserDefinedParams = param;
100 sumObj.summary(entry);
101 continue;
104 log.println("Creating: "+tCase.getObjectName());
106 log.initialize(entry,true);
107 entry.UserDefinedParams = param;
108 TestEnvironment tEnv = null;
109 try {
110 tCase.setLogWriter((PrintWriter) log);
111 tCase.initializeTestCase(param);
112 tEnv = tCase.getTestEnvironment(param);
113 } catch (Exception e) {
114 log.println("Exception while creating "+tCase.getObjectName());
115 log.println("Exception: " + e);
116 log.println("Message "+e.getMessage());
117 tEnv = null;
119 if (tEnv == null) {
120 Summarizer.summarizeDown(entry,"Couldn't create "+tCase.getObjectName());
121 LogWriter sumObj = (LogWriter)dcl.getInstance(
122 (String)param.get("OutProducer"));
123 sumObj.initialize(entry,true);
124 entry.UserDefinedParams = param;
125 sumObj.summary(entry);
126 continue;
128 log.println("Created "+tCase.getObjectName()+"\n");
130 for (int j=0;j<entry.SubEntryCount;j++) {
131 if (!entry.SubEntries[j].isToTest) {
132 Summarizer.summarizeDown(entry.SubEntries[j],"not part of the job");
133 continue;
136 log.println("running: "+entry.SubEntries[j].entryName);
138 LogWriter ifclog = (LogWriter)dcl.getInstance(
139 (String)param.get("LogWriter"));
141 ifclog.initialize(entry.SubEntries[j],true);
142 entry.SubEntries[j].UserDefinedParams = param;
143 entry.SubEntries[j].Logger = ifclog;
145 if (tEnv == null || tEnv.isDisposed()) {
146 tEnv = getEnv(entry,param);
149 MultiMethodTest ifc = null;
150 lib.TestResult res = null;
151 try {
152 ifc = (MultiMethodTest) dcl.getInstance(
153 entry.SubEntries[j].entryName);
154 res = ifc.run(entry.SubEntries[j],tEnv,param);
155 } catch (IllegalArgumentException iae) {
156 log.println("Couldn't load class "+entry.SubEntries[j].entryName);
157 log.println("**** "+iae.getMessage()+" ****");
158 Summarizer.summarizeDown(entry.SubEntries[j],iae.getMessage());
159 } catch (java.lang.RuntimeException e) {
160 tEnv = getEnv(entry,param);
161 ifc = (MultiMethodTest) dcl.getInstance(
162 entry.SubEntries[j].entryName);
163 if ((tEnv != null) && (ifc != null)) {
164 res = ifc.run(entry.SubEntries[j],tEnv,param);
166 else
168 res = null;
171 if (res != null) {
172 for (int k=0;k<entry.SubEntries[j].SubEntryCount;k++) {
173 if (res.hasMethod(entry.SubEntries[j].SubEntries[k].entryName)) {
174 entry.SubEntries[j].SubEntries[k].State=
175 res.getStatusFor(entry.SubEntries[j].SubEntries[k].entryName).toString();
179 sumIt.summarizeUp(entry.SubEntries[j]);
181 LogWriter sumIfc = (LogWriter)dcl.getInstance(
182 (String)param.get("OutProducer"));
184 sumIfc.initialize(entry.SubEntries[j],true);
185 entry.SubEntries[j].UserDefinedParams = param;
186 sumIfc.summary(entry.SubEntries[j]);
188 try {
189 tCase.cleanupTestCase(param);
190 } catch (Exception e) {
191 e.printStackTrace((PrintWriter)log);
193 sumIt.summarizeUp(entry);
194 LogWriter sumObj = (LogWriter)dcl.getInstance(
195 (String)param.get("OutProducer"));
196 sumObj.initialize(entry,true);
197 sumObj.summary(entry);
199 if (entries.length > 1) {
200 log.println("");
201 int counter = 0;
202 log.println("Failures that appeared during scenario execution:");
203 for (int i=0;i<entries.length;i++) {
204 if (! entries[i].State.endsWith("OK")) {
205 log.println("\t "+entries[i].longName);
206 counter++;
209 log.println(counter +" of "+entries.length + " tests failed" );
212 return retValue;
215 protected TestEnvironment getEnv(DescEntry entry, TestParameters param) {
216 DynamicClassLoader dcl = new DynamicClassLoader();
217 log = (LogWriter)dcl.getInstance((String)param.get("LogWriter"));
218 param.getMSF();
220 TestCase tCase = null;
224 tCase = (TestCase) dcl.getInstance("mod._"+entry.entryName);
226 catch (java.lang.IllegalArgumentException ie)
228 entry.ErrorMsg=ie.getMessage();
229 entry.hasErrorMsg=true;
232 log.println("Creating: "+tCase.getObjectName());
233 // LogWriter log = (LogWriter)dcl.getInstance( (String)param.get("LogWriter"));
234 log.initialize(entry,true);
235 entry.UserDefinedParams = param;
236 tCase.setLogWriter((PrintWriter) log);
237 TestEnvironment tEnv = null;
240 tCase.initializeTestCase(param);
241 tEnv = tCase.getTestEnvironment(param);
243 catch (com.sun.star.lang.DisposedException de)
245 log.println("Office disposed");
247 return tEnv;
250 // protected void shortWait(int millis) {
251 // try {
252 // Thread.sleep(millis);
253 // } catch (java.lang.InterruptedException ie) {}
254 // }