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: basic_fat.java,v $
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 ************************************************************************/
34 import basicrunner
.BasicIfcTest
;
35 import basicrunner
.BasicTestCase
;
37 import com
.sun
.star
.lang
.XMultiServiceFactory
;
39 import helper
.APIDescGetter
;
40 import helper
.AppProvider
;
41 import helper
.OfficeProvider
;
42 import helper
.OfficeWatcher
;
44 import java
.io
.BufferedReader
;
45 import java
.io
.FileReader
;
46 import java
.io
.PrintWriter
;
48 import java
.util
.Vector
;
51 import lib
.TestEnvironment
;
52 import lib
.TestParameters
;
54 import share
.DescEntry
;
55 import share
.DescGetter
;
56 import share
.LogWriter
;
58 import stats
.OutProducerFactory
;
59 import stats
.Summarizer
;
61 import util
.DynamicClassLoader
;
64 * The testbase for executing basic tests.
67 public class basic_fat
implements TestBase
70 public static boolean debug
= false;
74 * @param param The test parameters.
75 * @param return True, if the test was executed.
77 public boolean executeTest(TestParameters param
)
79 DescGetter dg
= new APIDescGetter();
80 String job
= (String
) param
.get("TestJob");
81 OfficeProvider office
= null;
82 debug
= param
.getBool("DebugIsActive");
85 //get Job-Descriptions
86 System
.out
.print("Getting Descriptions for Job: " + job
+ " from ");
88 DescEntry
[] entries
= dg
.getDescriptionFor(job
,
95 System
.out
.println("Couldn't get Description for Job");
100 String ExclusionFile
= (String
) param
.get("ExclusionList");
101 Vector exclusions
= null;
103 if (ExclusionFile
!= null)
105 exclusions
= getExclusionList(ExclusionFile
, debug
);
108 String conStr
= (String
) param
.get("ConnectionString");
109 System
.out
.println("");
110 System
.out
.print("> Connecting the Office ");
111 System
.out
.println("With " + conStr
);
113 for (int l
= 0; l
< entries
.length
; l
++)
115 if (entries
[l
].hasErrorMsg
)
117 System
.out
.println(entries
[l
].ErrorMsg
);
122 office
= new OfficeProvider();
124 XMultiServiceFactory msf
= (XMultiServiceFactory
) office
.getManager(
132 param
.put("ServiceFactory", msf
);
134 DescEntry entry
= entries
[l
];
136 //get some helper classes
137 Summarizer sumIt
= new Summarizer();
138 DynamicClassLoader dcl
= new DynamicClassLoader();
140 TestCase tCase
= null;
142 tCase
= (TestCase
) new BasicTestCase(entry
);
146 sumIt
.summarizeDown(entry
, entry
.ErrorMsg
);
148 LogWriter sumObj
= OutProducerFactory
.createOutProducer(param
);
149 sumObj
.initialize(entry
, true);
150 sumObj
.summary(entry
);
155 System
.out
.println("Creating: " + tCase
.getObjectName());
157 LogWriter log
= (LogWriter
) dcl
.getInstance(
158 (String
) param
.get("LogWriter"));
159 log
.initialize(entry
, true);
160 entry
.UserDefinedParams
= param
;
161 tCase
.setLogWriter((PrintWriter
) log
);
165 tCase
.initializeTestCase(param
);
167 catch (RuntimeException e
)
169 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) param
.get(
174 OfficeWatcher ow
= (OfficeWatcher
) param
.get("Watcher");
176 if ((ow
!= null) && ow
.isAlive())
188 TestEnvironment tEnv
= tCase
.getTestEnvironment(param
);
192 sumIt
.summarizeDown(entry
, "Unable to create testcase");
194 LogWriter sumObj
= OutProducerFactory
.createOutProducer(param
);
195 sumObj
.initialize(entry
, true);
196 sumObj
.summary(entry
);
198 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) param
.get(
203 OfficeWatcher ow
= (OfficeWatcher
) param
.get("Watcher");
205 if ((ow
!= null) && ow
.isAlive())
217 System
.out
.println("created " + tCase
.getObjectName());
219 for (int j
= 0; j
< entry
.SubEntryCount
; j
++)
221 if (!entry
.SubEntries
[j
].isToTest
)
223 Summarizer
.summarizeDown(entry
.SubEntries
[j
],
224 "not part of the job");
229 if ((exclusions
!= null) &&
230 (exclusions
.contains(entry
.SubEntries
[j
].longName
)))
232 Summarizer
.summarizeDown(entry
.SubEntries
[j
],
238 System
.out
.println("running: " +
239 entry
.SubEntries
[j
].entryName
);
241 LogWriter ifclog
= (LogWriter
) dcl
.getInstance(
242 (String
) param
.get("LogWriter"));
243 ifclog
.initialize(entry
.SubEntries
[j
], true);
244 entry
.SubEntries
[j
].UserDefinedParams
= param
;
245 entry
.SubEntries
[j
].Logger
= ifclog
;
247 if ((tEnv
== null) || tEnv
.isDisposed())
249 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) param
.get(
254 office
.closeExistingOffice(param
, true);
258 tEnv
= getEnv(entry
, param
);
261 BasicIfcTest ifc
= null;
262 lib
.TestResult res
= null;
263 ifc
= new BasicIfcTest(entry
.SubEntries
[j
].longName
);
264 res
= ifc
.run(entry
.SubEntries
[j
], tEnv
, param
);
266 sumIt
.summarizeUp(entry
.SubEntries
[j
]);
268 LogWriter sumIfc
= OutProducerFactory
.createOutProducer(param
);
270 sumIfc
.initialize(entry
.SubEntries
[j
], true);
271 sumIfc
.summary(entry
.SubEntries
[j
]);
276 tCase
.cleanupTestCase(param
);
280 log
.println("TestCase already gone");
282 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) param
.get(
287 office
.closeExistingOffice(param
, true);
292 sumIt
.summarizeUp(entry
);
294 LogWriter sumObj
= OutProducerFactory
.createOutProducer(param
);
295 sumObj
.initialize(entry
, true);
296 sumObj
.summary(entry
);
299 if (entries
.length
> 1)
301 System
.out
.println();
305 "Failures that appeared during scenario execution:");
307 for (int i
= 0; i
< entries
.length
; i
++)
309 if (!entries
[i
].State
.endsWith("OK"))
311 System
.out
.println("\t " + entries
[i
].longName
);
316 System
.out
.println(counter
+ " of " + entries
.length
+
320 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) param
.get(
325 office
.closeExistingOffice(param
, true);
331 protected TestEnvironment
getEnv(DescEntry entry
, TestParameters param
)
333 DynamicClassLoader dcl
= new DynamicClassLoader();
334 String officeProviderName
= (String
) param
.get("OfficeProvider");
335 AppProvider office
= (AppProvider
) dcl
.getInstance(officeProviderName
);
339 System
.out
.println("ERROR: Wrong parameter 'OfficeProvider', " +
340 " it cannot be instantiated.");
344 XMultiServiceFactory msf
= (XMultiServiceFactory
) office
.getManager(
352 param
.put("ServiceFactory", msf
);
354 TestCase tCase
= (TestCase
) new BasicTestCase(entry
);
356 System
.out
.println("Creating: " + tCase
.getObjectName());
358 LogWriter log
= (LogWriter
) dcl
.getInstance(
359 (String
) param
.get("LogWriter"));
360 log
.initialize(entry
, true);
361 entry
.UserDefinedParams
= param
;
362 tCase
.setLogWriter((PrintWriter
) log
);
364 TestEnvironment tEnv
= null;
368 tCase
.initializeTestCase(param
);
369 tEnv
= tCase
.getTestEnvironment(param
);
371 catch (java
.lang
.RuntimeException e
)
373 System
.out
.println(e
.getMessage());
375 helper
.ProcessHandler ph
= (helper
.ProcessHandler
) param
.get(
380 office
.closeExistingOffice(param
, true);
384 entry
.ErrorMsg
= e
.getMessage();
385 entry
.hasErrorMsg
= true;
391 protected void shortWait(int millis
)
395 Thread
.sleep(millis
);
397 catch (java
.lang
.InterruptedException ie
)
402 protected Vector
getExclusionList(String url
, boolean debug
)
404 Vector entryList
= new Vector();
406 BufferedReader exclusion
= null;
410 exclusion
= new BufferedReader(new FileReader(url
));
412 catch (java
.io
.FileNotFoundException fnfe
)
416 System
.out
.println("Couldn't find file " + url
);
426 if (!line
.startsWith("#"))
431 line
= exclusion
.readLine();
433 catch (java
.io
.IOException ioe
)
438 "Exception while reading exclusion list");
449 catch (java
.io
.IOException ioe
)
453 System
.out
.println("Couldn't close file " + url
);