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 .
22 import java
.io
.PrintWriter
;
24 import lib
.TestParameters
;
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
;
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 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");
65 for (int l
=0;l
<entries
.length
;l
++) {
67 if (entries
[l
] == null ) {
71 if (entries
[l
].hasErrorMsg
) {
72 log
.println(entries
[l
].ErrorMsg
);
76 DescEntry entry
= entries
[l
];
78 //get some helper classes
79 Summarizer sumIt
= new Summarizer();
81 TestCase tCase
= null;
84 dcl
.getInstance("mod._"+entry
.entryName
);
85 } catch (java
.lang
.IllegalArgumentException ie
) {
86 entry
.ErrorMsg
=ie
.getMessage();
87 entry
.hasErrorMsg
=true;
91 Summarizer
.summarizeDown(entry
,entry
.ErrorMsg
);
92 LogWriter sumObj
= (LogWriter
)dcl
.getInstance(
93 (String
)param
.get("OutProducer"));
94 sumObj
.initialize(entry
,true);
95 entry
.UserDefinedParams
= param
;
96 sumObj
.summary(entry
);
100 log
.println("Creating: "+tCase
.getObjectName());
102 log
.initialize(entry
,true);
103 entry
.UserDefinedParams
= param
;
104 TestEnvironment tEnv
= null;
106 tCase
.setLogWriter((PrintWriter
) log
);
107 tCase
.initializeTestCase(param
);
108 tEnv
= tCase
.getTestEnvironment(param
);
109 } catch (Exception e
) {
110 log
.println("Exception while creating "+tCase
.getObjectName());
111 log
.println("Exception: " + e
);
112 log
.println("Message "+e
.getMessage());
116 Summarizer
.summarizeDown(entry
,"Couldn't create "+tCase
.getObjectName());
117 LogWriter sumObj
= (LogWriter
)dcl
.getInstance(
118 (String
)param
.get("OutProducer"));
119 sumObj
.initialize(entry
,true);
120 entry
.UserDefinedParams
= param
;
121 sumObj
.summary(entry
);
124 log
.println("Created "+tCase
.getObjectName()+"\n");
126 for (int j
=0;j
<entry
.SubEntryCount
;j
++) {
127 if (!entry
.SubEntries
[j
].isToTest
) {
128 Summarizer
.summarizeDown(entry
.SubEntries
[j
],"not part of the job");
132 log
.println("running: "+entry
.SubEntries
[j
].entryName
);
134 LogWriter ifclog
= (LogWriter
)dcl
.getInstance(
135 (String
)param
.get("LogWriter"));
137 ifclog
.initialize(entry
.SubEntries
[j
],true);
138 entry
.SubEntries
[j
].UserDefinedParams
= param
;
139 entry
.SubEntries
[j
].Logger
= ifclog
;
141 if (tEnv
== null || tEnv
.isDisposed()) {
142 tEnv
= getEnv(entry
,param
);
145 MultiMethodTest ifc
= null;
146 lib
.TestResult res
= null;
148 ifc
= (MultiMethodTest
) dcl
.getInstance(
149 entry
.SubEntries
[j
].entryName
);
150 res
= ifc
.run(entry
.SubEntries
[j
],tEnv
,param
);
151 } catch (IllegalArgumentException iae
) {
152 log
.println("Couldn't load class "+entry
.SubEntries
[j
].entryName
);
153 log
.println("**** "+iae
.getMessage()+" ****");
154 Summarizer
.summarizeDown(entry
.SubEntries
[j
],iae
.getMessage());
155 } catch (java
.lang
.RuntimeException e
) {
156 tEnv
= getEnv(entry
,param
);
157 ifc
= (MultiMethodTest
) dcl
.getInstance(
158 entry
.SubEntries
[j
].entryName
);
159 if ((tEnv
!= null) && (ifc
!= null)) {
160 res
= ifc
.run(entry
.SubEntries
[j
],tEnv
,param
);
168 for (int k
=0;k
<entry
.SubEntries
[j
].SubEntryCount
;k
++) {
169 if (res
.hasMethod(entry
.SubEntries
[j
].SubEntries
[k
].entryName
)) {
170 entry
.SubEntries
[j
].SubEntries
[k
].State
=
171 res
.getStatusFor(entry
.SubEntries
[j
].SubEntries
[k
].entryName
).toString();
175 sumIt
.summarizeUp(entry
.SubEntries
[j
]);
177 LogWriter sumIfc
= (LogWriter
)dcl
.getInstance(
178 (String
)param
.get("OutProducer"));
180 sumIfc
.initialize(entry
.SubEntries
[j
],true);
181 entry
.SubEntries
[j
].UserDefinedParams
= param
;
182 sumIfc
.summary(entry
.SubEntries
[j
]);
185 tCase
.cleanupTestCase(param
);
186 } catch (Exception e
) {
187 e
.printStackTrace((PrintWriter
)log
);
189 sumIt
.summarizeUp(entry
);
190 LogWriter sumObj
= (LogWriter
)dcl
.getInstance(
191 (String
)param
.get("OutProducer"));
192 sumObj
.initialize(entry
,true);
193 sumObj
.summary(entry
);
195 if (entries
.length
> 1) {
198 log
.println("Failures that appeared during scenario execution:");
199 for (int i
=0;i
<entries
.length
;i
++) {
200 if (! entries
[i
].State
.endsWith("OK")) {
201 log
.println("\t "+entries
[i
].longName
);
205 log
.println(counter
+" of "+entries
.length
+ " tests failed" );
211 protected TestEnvironment
getEnv(DescEntry entry
, TestParameters param
) {
212 DynamicClassLoader dcl
= new DynamicClassLoader();
213 log
= (LogWriter
)dcl
.getInstance((String
)param
.get("LogWriter"));
215 TestEnvironment tEnv
= null;
218 TestCase tCase
= (TestCase
) dcl
.getInstance("mod._"+entry
.entryName
);
219 log
.println("Creating: " + tCase
.getObjectName());
220 log
.initialize(entry
, true);
221 entry
.UserDefinedParams
= param
;
222 tCase
.setLogWriter((PrintWriter
) log
);
224 tCase
.initializeTestCase(param
);
225 tEnv
= tCase
.getTestEnvironment(param
);
226 } catch (com
.sun
.star
.lang
.DisposedException de
) {
227 log
.println("Office disposed");
229 } catch (java
.lang
.Exception ie
) {
230 entry
.ErrorMsg
=ie
.getMessage();
231 entry
.hasErrorMsg
=true;