1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: java_fat.java,v $
10 * $Revision: 1.15.2.1 $
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 ************************************************************************/
32 import com
.sun
.star
.lang
.XMultiServiceFactory
;
34 import helper
.APIDescGetter
;
35 import helper
.AppProvider
;
37 import java
.io
.BufferedReader
;
38 import java
.io
.FileReader
;
39 import java
.io
.PrintWriter
;
41 import java
.util
.Vector
;
43 import lib
.MultiMethodTest
;
45 import lib
.TestEnvironment
;
46 import lib
.TestParameters
;
47 import lib
.TestResult
;
49 import share
.DescEntry
;
50 import share
.DescGetter
;
51 import share
.LogWriter
;
53 import stats
.OutProducerFactory
;
54 import stats
.Summarizer
;
56 import util
.DynamicClassLoader
;
60 * this class handles tests written in java and running on a fat Office
62 public class java_fat
implements TestBase
65 private static boolean debug
= false;
66 private static boolean keepdocument
= false;
67 private static boolean logging
= true;
68 private static boolean newOffice
= false;
69 private DynamicClassLoader dcl
= null;
71 private lib
.TestParameters m_aParams
;
72 private AppProvider m_aOffice
;
74 public boolean executeTest(lib
.TestParameters param
)
78 dcl
= new DynamicClassLoader();
80 DescGetter dg
= new APIDescGetter();
81 String job
= (String
) param
.get("TestJob");
82 String ExclusionFile
= (String
) param
.get("ExclusionList");
83 Vector exclusions
= null;
84 boolean retValue
= true;
85 debug
= param
.getBool("DebugIsActive");
86 logging
= param
.getBool("LoggingIsActive");
87 keepdocument
= param
.getBool("KeepDocument");
88 newOffice
= param
.getBool(util
.PropertyName
.NEW_OFFICE_INSTANCE
);
91 System
.setProperty("KeepDocument", "true");
93 if (ExclusionFile
!= null)
95 exclusions
= getExclusionList(ExclusionFile
, debug
);
97 //get Job-Descriptions
98 System
.out
.println("Getting Descriptions for Job: " + job
);
100 String sDescriptionPath
= (String
) param
.get("DescriptionPath");
101 DescEntry
[] entries
= dg
.getDescriptionFor(job
, sDescriptionPath
, debug
);
103 // System.out.println();
107 System
.out
.println("Couldn't get Description for Job: " + job
);
112 // String officeProviderName = (String) param.get("OfficeProvider");
113 // AppProvider office = (AppProvider) dcl.getInstance(officeProviderName);
115 // if (office == null) {
116 // System.out.println("ERROR: Wrong parameter 'OfficeProvider', " +
117 // " it cannot be instantiated.");
121 m_aOffice
= startOffice(param
);
123 boolean firstRun
= true;
125 for (int l
= 0; l
< entries
.length
; l
++)
127 if (entries
[l
] == null)
132 if (entries
[l
].hasErrorMsg
)
134 System
.out
.println(entries
[l
].ErrorMsg
);
139 if (!firstRun
&& newOffice
)
141 if (!m_aOffice
.closeExistingOffice(param
, true))
143 m_aOffice
.disposeManager(param
);
149 // XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(
152 XMultiServiceFactory msf
= (XMultiServiceFactory
) param
.getMSF();
161 // param.put("ServiceFactory", msf);
163 DescEntry entry
= entries
[l
];
165 //get some helper classes
166 Summarizer sumIt
= new Summarizer();
168 TestCase tCase
= null;
172 tCase
= (TestCase
) dcl
.getInstance("mod._" + entry
.entryName
);
174 catch (java
.lang
.IllegalArgumentException ie
)
176 entry
.ErrorMsg
= ie
.getMessage();
177 entry
.hasErrorMsg
= true;
179 catch (java
.lang
.NoClassDefFoundError ie
)
181 entry
.ErrorMsg
= ie
.getMessage();
182 entry
.hasErrorMsg
= true;
187 Summarizer
.summarizeDown(entry
, entry
.ErrorMsg
);
189 LogWriter sumObj
= OutProducerFactory
.createOutProducer(param
);
190 entry
.UserDefinedParams
= param
;
191 sumObj
.initialize(entry
, logging
);
192 sumObj
.summary(entry
);
199 System
.out
.println("sleeping 5 seconds..");
201 util
.utils
.shortWait(5000);
203 System
.out
.println("Creating: " + entry
.entryName
);
205 LogWriter log
= (LogWriter
) dcl
.getInstance((String
) param
.get("LogWriter"));
206 log
.initialize(entry
, logging
);
207 entry
.UserDefinedParams
= param
;
209 TestEnvironment tEnv
= null;
213 tCase
.setLogWriter((PrintWriter
) log
);
214 tCase
.initializeTestCase(param
);
215 tEnv
= tCase
.getTestEnvironment(param
);
219 System
.out
.println("Exception while creating " + tCase
.getObjectName());
220 System
.out
.println("Message " + e
.getMessage());
224 catch (java
.lang
.UnsatisfiedLinkError e
)
226 System
.out
.println("Exception while creating " + tCase
.getObjectName());
227 System
.out
.println("Message " + e
.getMessage());
230 catch (java
.lang
.NoClassDefFoundError e
)
232 System
.out
.println("Exception while creating " + tCase
.getObjectName());
233 System
.out
.println("Message " + e
.getMessage());
239 Summarizer
.summarizeDown(entry
, "Couldn't create " + tCase
.getObjectName());
241 LogWriter sumObj
= OutProducerFactory
.createOutProducer(param
);
242 entry
.UserDefinedParams
= param
;
243 sumObj
.initialize(entry
, logging
);
244 sumObj
.summary(entry
);
249 System
.out
.println(tCase
.getObjectName() + " recreated ");
251 for (int j
= 0; j
< entry
.SubEntryCount
; j
++)
253 DescEntry aSubEntry
= entry
.SubEntries
[j
];
254 if (!aSubEntry
.isToTest
)
256 Summarizer
.summarizeDown(aSubEntry
, "not part of the job");
261 if ((exclusions
!= null) && (exclusions
.contains(aSubEntry
.longName
)))
263 Summarizer
.summarizeDown(aSubEntry
, "known issue");
268 System
.out
.println("running: '" + aSubEntry
.entryName
+ "'");
270 LogWriter ifclog
= (LogWriter
) dcl
.getInstance( (String
) param
.get("LogWriter"));
272 ifclog
.initialize(aSubEntry
, logging
);
273 aSubEntry
.UserDefinedParams
= param
;
274 aSubEntry
.Logger
= ifclog
;
276 if ((tEnv
== null) || tEnv
.isDisposed())
278 closeExistingOffice();
279 tEnv
= getEnv(entry
, param
);
282 // MultiMethodTest ifc = null;
283 lib
.TestResult res
= null;
285 // run the interface test twice if it failed.
286 int countInterfaceTestRun
= 0;
287 boolean finished
= false;
292 countInterfaceTestRun
++;
294 res
= executeInterfaceTest(aSubEntry
, tEnv
, param
);
296 catch (IllegalArgumentException iae
)
298 System
.out
.println("Couldn't load class " + aSubEntry
.entryName
);
299 System
.out
.println("**** " + iae
.getMessage() + " ****");
300 Summarizer
.summarizeDown(aSubEntry
, iae
.getMessage());
302 catch (java
.lang
.NoClassDefFoundError iae
)
304 System
.out
.println("Couldn't load class " + aSubEntry
.entryName
);
305 System
.out
.println("**** " + iae
.getMessage() + " ****");
306 Summarizer
.summarizeDown(aSubEntry
, iae
.getMessage());
308 catch (java
.lang
.RuntimeException e
)
310 closeExistingOffice();
311 tEnv
= getEnv(entry
, param
);
312 if (countInterfaceTestRun
< 2)
318 Summarizer
.summarizeDown(aSubEntry
, e
.toString() + ".FAILED");
322 setState(aSubEntry
, res
);
324 sumIt
.summarizeUp(aSubEntry
);
326 LogWriter sumIfc
= OutProducerFactory
.createOutProducer(param
);
327 aSubEntry
.UserDefinedParams
= param
;
328 sumIfc
.initialize(aSubEntry
, logging
);
329 sumIfc
.summary(aSubEntry
);
336 tCase
.cleanupTestCase(param
);
341 System
.out
.println("couldn't cleanup");
343 catch (java
.lang
.NoClassDefFoundError e
)
345 System
.out
.println("couldn't cleanup");
348 sumIt
.summarizeUp(entry
);
350 LogWriter sumObj
= OutProducerFactory
.createOutProducer(param
);
352 sumObj
.initialize(entry
, logging
);
353 sumObj
.summary(entry
);
356 if (entries
.length
> 0)
358 System
.out
.println();
361 System
.out
.println("Failures that appeared during scenario execution:");
363 for (int i
= 0; i
< entries
.length
; i
++)
365 if (!entries
[i
].State
.endsWith("OK"))
367 System
.out
.println("\t " + entries
[i
].longName
);
372 System
.out
.println(counter
+ " of " + entries
.length
+ " tests failed");
375 closeExistingOffice();
379 private void setState(DescEntry aSubEntry
, lib
.TestResult res
)
383 for (int k
= 0; k
< aSubEntry
.SubEntryCount
; k
++)
385 DescEntry aSubSubEntry
= aSubEntry
.SubEntries
[k
];
386 if (res
.hasMethod( aSubSubEntry
.entryName
))
388 aSubSubEntry
.State
= res
.getStatusFor(aSubSubEntry
.entryName
).toString();
394 private TestEnvironment
getEnv(DescEntry entry
, TestParameters param
)
397 // dcl = new DynamicClassLoader();
398 // String officeProviderName = (String) param.get("OfficeProvider");
399 // AppProvider office = (AppProvider) dcl.getInstance(officeProviderName);
401 // if (office == null) {
402 // System.out.println("ERROR: Wrong parameter 'OfficeProvider', " +
403 // " it cannot be instantiated.");
407 // XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager(
410 // if (msf == null) {
414 // param.put("ServiceFactory", msf);
416 // AppProvider office = startOffice(param);
418 TestCase tCase
= null;
422 tCase
= (TestCase
) dcl
.getInstance("mod._" + entry
.entryName
);
424 catch (java
.lang
.IllegalArgumentException ie
)
426 entry
.ErrorMsg
= ie
.getMessage();
427 entry
.hasErrorMsg
= true;
429 catch (java
.lang
.NoClassDefFoundError ie
)
431 entry
.ErrorMsg
= ie
.getMessage();
432 entry
.hasErrorMsg
= true;
435 System
.out
.println("Creating: " + entry
.entryName
);
437 entry
.UserDefinedParams
= param
;
439 LogWriter log
= (LogWriter
) dcl
.getInstance((String
) param
.get("LogWriter"));
440 log
.initialize(entry
, logging
);
441 tCase
.setLogWriter((PrintWriter
) log
);
443 TestEnvironment tEnv
= null;
447 tCase
.initializeTestCase(param
);
448 tEnv
= tCase
.getTestEnvironment(param
);
450 catch (com
.sun
.star
.lang
.DisposedException de
)
452 System
.out
.println("Office disposed");
453 closeExistingOffice();
455 catch (lib
.StatusException e
)
457 System
.out
.println(e
.getMessage());
459 closeExistingOffice();
461 entry
.ErrorMsg
= e
.getMessage();
462 entry
.hasErrorMsg
= true;
468 private void closeExistingOffice()
470 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) m_aParams
.get("AppProvider");
474 m_aOffice
.closeExistingOffice(m_aParams
, true);
480 private void shortWait(int millis
)
484 Thread
.sleep(millis
);
486 catch (java
.lang
.InterruptedException ie
)
491 private Vector
getExclusionList(String url
, boolean debug
)
493 Vector entryList
= new Vector();
495 BufferedReader exclusion
= null;
499 exclusion
= new BufferedReader(new FileReader(url
));
501 catch (java
.io
.FileNotFoundException fnfe
)
505 System
.out
.println("Couldn't find file " + url
);
515 if (!line
.startsWith("#") && (line
.length() > 1))
517 entryList
.add(line
.trim());
520 line
= exclusion
.readLine();
522 catch (java
.io
.IOException ioe
)
526 System
.out
.println("Exception while reading exclusion list");
537 catch (java
.io
.IOException ioe
)
541 System
.out
.println("Couldn't close file " + url
);
550 private TestResult
executeInterfaceTest(
551 DescEntry entry
, TestEnvironment tEnv
, TestParameters param
)
552 throws IllegalArgumentException
, java
.lang
.NoClassDefFoundError
554 MultiMethodTest ifc
= (MultiMethodTest
) dcl
.getInstance(entry
.entryName
);
555 return ifc
.run(entry
, tEnv
, param
);
558 private AppProvider
startOffice(lib
.TestParameters param
)
563 dcl
= new DynamicClassLoader();
566 String officeProviderName
= (String
) param
.get("OfficeProvider");
567 AppProvider office
= (AppProvider
) dcl
.getInstance(officeProviderName
);
571 System
.out
.println("ERROR: Wrong parameter 'OfficeProvider', " + " it cannot be instantiated.");
575 XMultiServiceFactory msf
= (XMultiServiceFactory
) office
.getManager(param
);
579 param
.put("ServiceFactory", msf
);