1*ef39d40dSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*ef39d40dSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*ef39d40dSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*ef39d40dSAndrew Rist * distributed with this work for additional information 6*ef39d40dSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*ef39d40dSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*ef39d40dSAndrew Rist * "License"); you may not use this file except in compliance 9*ef39d40dSAndrew Rist * with the License. You may obtain a copy of the License at 10*ef39d40dSAndrew Rist * 11*ef39d40dSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*ef39d40dSAndrew Rist * 13*ef39d40dSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*ef39d40dSAndrew Rist * software distributed under the License is distributed on an 15*ef39d40dSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*ef39d40dSAndrew Rist * KIND, either express or implied. See the License for the 17*ef39d40dSAndrew Rist * specific language governing permissions and limitations 18*ef39d40dSAndrew Rist * under the License. 19*ef39d40dSAndrew Rist * 20*ef39d40dSAndrew Rist *************************************************************/ 21*ef39d40dSAndrew Rist 22*ef39d40dSAndrew Rist 23cdf0e10cSrcweir package base; 24cdf0e10cSrcweir 25cdf0e10cSrcweir 26cdf0e10cSrcweir import basicrunner.BasicIfcTest; 27cdf0e10cSrcweir import basicrunner.BasicTestCase; 28cdf0e10cSrcweir 29cdf0e10cSrcweir import com.sun.star.lang.XMultiServiceFactory; 30cdf0e10cSrcweir 31cdf0e10cSrcweir import helper.APIDescGetter; 32cdf0e10cSrcweir import helper.AppProvider; 33cdf0e10cSrcweir import helper.OfficeProvider; 34cdf0e10cSrcweir import helper.OfficeWatcher; 35cdf0e10cSrcweir 36cdf0e10cSrcweir import java.io.BufferedReader; 37cdf0e10cSrcweir import java.io.FileReader; 38cdf0e10cSrcweir import java.io.PrintWriter; 39cdf0e10cSrcweir 40cdf0e10cSrcweir import java.util.Vector; 41cdf0e10cSrcweir 42cdf0e10cSrcweir import lib.TestCase; 43cdf0e10cSrcweir import lib.TestEnvironment; 44cdf0e10cSrcweir import lib.TestParameters; 45cdf0e10cSrcweir 46cdf0e10cSrcweir import share.DescEntry; 47cdf0e10cSrcweir import share.DescGetter; 48cdf0e10cSrcweir import share.LogWriter; 49cdf0e10cSrcweir 50cdf0e10cSrcweir import stats.OutProducerFactory; 51cdf0e10cSrcweir import stats.Summarizer; 52cdf0e10cSrcweir 53cdf0e10cSrcweir import util.DynamicClassLoader; 54cdf0e10cSrcweir 55cdf0e10cSrcweir /** 56cdf0e10cSrcweir * The testbase for executing basic tests. 57cdf0e10cSrcweir * @see lib.TestBase 58cdf0e10cSrcweir */ 59cdf0e10cSrcweir public class basic_fat implements TestBase 60cdf0e10cSrcweir { 61cdf0e10cSrcweir 62cdf0e10cSrcweir public static boolean debug = false; 63cdf0e10cSrcweir 64cdf0e10cSrcweir /** 65cdf0e10cSrcweir * Execute a test. 66cdf0e10cSrcweir * @param param The test parameters. 67cdf0e10cSrcweir * @return True, if the test was executed. 68cdf0e10cSrcweir */ executeTest(TestParameters param)69cdf0e10cSrcweir public boolean executeTest(TestParameters param) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir DescGetter dg = new APIDescGetter(); 72cdf0e10cSrcweir String job = (String) param.get("TestJob"); 73cdf0e10cSrcweir OfficeProvider office = null; 74cdf0e10cSrcweir debug = param.getBool("DebugIsActive"); 75cdf0e10cSrcweir 76cdf0e10cSrcweir 77cdf0e10cSrcweir //get Job-Descriptions 78cdf0e10cSrcweir System.out.print("Getting Descriptions for Job: " + job + " from "); 79cdf0e10cSrcweir 80cdf0e10cSrcweir DescEntry[] entries = dg.getDescriptionFor(job, 81cdf0e10cSrcweir (String) param.get( 82cdf0e10cSrcweir "DescriptionPath"), 83cdf0e10cSrcweir debug); 84cdf0e10cSrcweir 85cdf0e10cSrcweir if (entries == null) 86cdf0e10cSrcweir { 87cdf0e10cSrcweir System.out.println("Couldn't get Description for Job"); 88cdf0e10cSrcweir 89cdf0e10cSrcweir return false; 90cdf0e10cSrcweir } 91cdf0e10cSrcweir 92cdf0e10cSrcweir String ExclusionFile = (String) param.get("ExclusionList"); 93cdf0e10cSrcweir Vector exclusions = null; 94cdf0e10cSrcweir 95cdf0e10cSrcweir if (ExclusionFile != null) 96cdf0e10cSrcweir { 97cdf0e10cSrcweir exclusions = getExclusionList(ExclusionFile, debug); 98cdf0e10cSrcweir } 99cdf0e10cSrcweir 100cdf0e10cSrcweir String conStr = (String) param.get("ConnectionString"); 101cdf0e10cSrcweir System.out.println(""); 102cdf0e10cSrcweir System.out.print("> Connecting the Office "); 103cdf0e10cSrcweir System.out.println("With " + conStr); 104cdf0e10cSrcweir 105cdf0e10cSrcweir for (int l = 0; l < entries.length; l++) 106cdf0e10cSrcweir { 107cdf0e10cSrcweir if (entries[l].hasErrorMsg) 108cdf0e10cSrcweir { 109cdf0e10cSrcweir System.out.println(entries[l].ErrorMsg); 110cdf0e10cSrcweir 111cdf0e10cSrcweir continue; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir office = new OfficeProvider(); 115cdf0e10cSrcweir 116cdf0e10cSrcweir XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager( 117cdf0e10cSrcweir param); 118cdf0e10cSrcweir 119cdf0e10cSrcweir if (msf == null) 120cdf0e10cSrcweir { 121cdf0e10cSrcweir return false; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir 124cdf0e10cSrcweir param.put("ServiceFactory", msf); 125cdf0e10cSrcweir 126cdf0e10cSrcweir DescEntry entry = entries[l]; 127cdf0e10cSrcweir 128cdf0e10cSrcweir //get some helper classes 129cdf0e10cSrcweir Summarizer sumIt = new Summarizer(); 130cdf0e10cSrcweir DynamicClassLoader dcl = new DynamicClassLoader(); 131cdf0e10cSrcweir 132cdf0e10cSrcweir TestCase tCase = null; 133cdf0e10cSrcweir 134cdf0e10cSrcweir tCase = (TestCase) new BasicTestCase(entry); 135cdf0e10cSrcweir 136cdf0e10cSrcweir if (tCase == null) 137cdf0e10cSrcweir { 138cdf0e10cSrcweir sumIt.summarizeDown(entry, entry.ErrorMsg); 139cdf0e10cSrcweir 140cdf0e10cSrcweir LogWriter sumObj = OutProducerFactory.createOutProducer(param); 141cdf0e10cSrcweir sumObj.initialize(entry, true); 142cdf0e10cSrcweir sumObj.summary(entry); 143cdf0e10cSrcweir 144cdf0e10cSrcweir continue; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir System.out.println("Creating: " + tCase.getObjectName()); 148cdf0e10cSrcweir 149cdf0e10cSrcweir LogWriter log = (LogWriter) dcl.getInstance( 150cdf0e10cSrcweir (String) param.get("LogWriter")); 151cdf0e10cSrcweir log.initialize(entry, true); 152cdf0e10cSrcweir entry.UserDefinedParams = param; 153cdf0e10cSrcweir tCase.setLogWriter((PrintWriter) log); 154cdf0e10cSrcweir 155cdf0e10cSrcweir try 156cdf0e10cSrcweir { 157cdf0e10cSrcweir tCase.initializeTestCase(param); 158cdf0e10cSrcweir } 159cdf0e10cSrcweir catch (RuntimeException e) 160cdf0e10cSrcweir { 161cdf0e10cSrcweir helper.ProcessHandler ph = (helper.ProcessHandler) param.get( 162cdf0e10cSrcweir "AppProvider"); 163cdf0e10cSrcweir 164cdf0e10cSrcweir if (ph != null) 165cdf0e10cSrcweir { 166cdf0e10cSrcweir OfficeWatcher ow = (OfficeWatcher) param.get("Watcher"); 167cdf0e10cSrcweir 168cdf0e10cSrcweir if ((ow != null) && ow.isAlive()) 169cdf0e10cSrcweir { 170cdf0e10cSrcweir ow.finish = true; 171cdf0e10cSrcweir } 172cdf0e10cSrcweir 173cdf0e10cSrcweir ph.kill(); 174cdf0e10cSrcweir shortWait(5000); 175cdf0e10cSrcweir } 176cdf0e10cSrcweir 177cdf0e10cSrcweir continue; 178cdf0e10cSrcweir } 179cdf0e10cSrcweir 180cdf0e10cSrcweir TestEnvironment tEnv = tCase.getTestEnvironment(param); 181cdf0e10cSrcweir 182cdf0e10cSrcweir if (tEnv == null) 183cdf0e10cSrcweir { 184cdf0e10cSrcweir sumIt.summarizeDown(entry, "Unable to create testcase"); 185cdf0e10cSrcweir 186cdf0e10cSrcweir LogWriter sumObj = OutProducerFactory.createOutProducer(param); 187cdf0e10cSrcweir sumObj.initialize(entry, true); 188cdf0e10cSrcweir sumObj.summary(entry); 189cdf0e10cSrcweir 190cdf0e10cSrcweir helper.ProcessHandler ph = (helper.ProcessHandler) param.get( 191cdf0e10cSrcweir "AppProvider"); 192cdf0e10cSrcweir 193cdf0e10cSrcweir if (ph != null) 194cdf0e10cSrcweir { 195cdf0e10cSrcweir OfficeWatcher ow = (OfficeWatcher) param.get("Watcher"); 196cdf0e10cSrcweir 197cdf0e10cSrcweir if ((ow != null) && ow.isAlive()) 198cdf0e10cSrcweir { 199cdf0e10cSrcweir ow.finish = true; 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir ph.kill(); 203cdf0e10cSrcweir shortWait(5000); 204cdf0e10cSrcweir } 205cdf0e10cSrcweir 206cdf0e10cSrcweir continue; 207cdf0e10cSrcweir } 208cdf0e10cSrcweir 209cdf0e10cSrcweir System.out.println("created " + tCase.getObjectName()); 210cdf0e10cSrcweir 211cdf0e10cSrcweir for (int j = 0; j < entry.SubEntryCount; j++) 212cdf0e10cSrcweir { 213cdf0e10cSrcweir if (!entry.SubEntries[j].isToTest) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir Summarizer.summarizeDown(entry.SubEntries[j], 216cdf0e10cSrcweir "not part of the job"); 217cdf0e10cSrcweir 218cdf0e10cSrcweir continue; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir if ((exclusions != null) && 222cdf0e10cSrcweir (exclusions.contains(entry.SubEntries[j].longName))) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir Summarizer.summarizeDown(entry.SubEntries[j], 225cdf0e10cSrcweir "known issue"); 226cdf0e10cSrcweir 227cdf0e10cSrcweir continue; 228cdf0e10cSrcweir } 229cdf0e10cSrcweir 230cdf0e10cSrcweir System.out.println("running: " + 231cdf0e10cSrcweir entry.SubEntries[j].entryName); 232cdf0e10cSrcweir 233cdf0e10cSrcweir LogWriter ifclog = (LogWriter) dcl.getInstance( 234cdf0e10cSrcweir (String) param.get("LogWriter")); 235cdf0e10cSrcweir ifclog.initialize(entry.SubEntries[j], true); 236cdf0e10cSrcweir entry.SubEntries[j].UserDefinedParams = param; 237cdf0e10cSrcweir entry.SubEntries[j].Logger = ifclog; 238cdf0e10cSrcweir 239cdf0e10cSrcweir if ((tEnv == null) || tEnv.isDisposed()) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir helper.ProcessHandler ph = (helper.ProcessHandler) param.get( 242cdf0e10cSrcweir "AppProvider"); 243cdf0e10cSrcweir 244cdf0e10cSrcweir if (ph != null) 245cdf0e10cSrcweir { 246cdf0e10cSrcweir office.closeExistingOffice(param, true); 247cdf0e10cSrcweir shortWait(5000); 248cdf0e10cSrcweir } 249cdf0e10cSrcweir 250cdf0e10cSrcweir tEnv = getEnv(entry, param); 251cdf0e10cSrcweir } 252cdf0e10cSrcweir 253cdf0e10cSrcweir BasicIfcTest ifc = null; 254cdf0e10cSrcweir lib.TestResult res = null; 255cdf0e10cSrcweir ifc = new BasicIfcTest(entry.SubEntries[j].longName); 256cdf0e10cSrcweir res = ifc.run(entry.SubEntries[j], tEnv, param); 257cdf0e10cSrcweir 258cdf0e10cSrcweir sumIt.summarizeUp(entry.SubEntries[j]); 259cdf0e10cSrcweir 260cdf0e10cSrcweir LogWriter sumIfc = OutProducerFactory.createOutProducer(param); 261cdf0e10cSrcweir 262cdf0e10cSrcweir sumIfc.initialize(entry.SubEntries[j], true); 263cdf0e10cSrcweir sumIfc.summary(entry.SubEntries[j]); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir 266cdf0e10cSrcweir try 267cdf0e10cSrcweir { 268cdf0e10cSrcweir tCase.cleanupTestCase(param); 269cdf0e10cSrcweir } 270cdf0e10cSrcweir catch (Exception e) 271cdf0e10cSrcweir { 272cdf0e10cSrcweir log.println("TestCase already gone"); 273cdf0e10cSrcweir 274cdf0e10cSrcweir helper.ProcessHandler ph = (helper.ProcessHandler) param.get( 275cdf0e10cSrcweir "AppProvider"); 276cdf0e10cSrcweir 277cdf0e10cSrcweir if (ph != null) 278cdf0e10cSrcweir { 279cdf0e10cSrcweir office.closeExistingOffice(param, true); 280cdf0e10cSrcweir shortWait(5000); 281cdf0e10cSrcweir } 282cdf0e10cSrcweir } 283cdf0e10cSrcweir 284cdf0e10cSrcweir sumIt.summarizeUp(entry); 285cdf0e10cSrcweir 286cdf0e10cSrcweir LogWriter sumObj = OutProducerFactory.createOutProducer(param); 287cdf0e10cSrcweir sumObj.initialize(entry, true); 288cdf0e10cSrcweir sumObj.summary(entry); 289cdf0e10cSrcweir } 290cdf0e10cSrcweir 291cdf0e10cSrcweir if (entries.length > 1) 292cdf0e10cSrcweir { 293cdf0e10cSrcweir System.out.println(); 294cdf0e10cSrcweir 295cdf0e10cSrcweir int counter = 0; 296cdf0e10cSrcweir System.out.println( 297cdf0e10cSrcweir "Failures that appeared during scenario execution:"); 298cdf0e10cSrcweir 299cdf0e10cSrcweir for (int i = 0; i < entries.length; i++) 300cdf0e10cSrcweir { 301cdf0e10cSrcweir if (!entries[i].State.endsWith("OK")) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir System.out.println("\t " + entries[i].longName); 304cdf0e10cSrcweir counter++; 305cdf0e10cSrcweir } 306cdf0e10cSrcweir } 307cdf0e10cSrcweir 308cdf0e10cSrcweir System.out.println(counter + " of " + entries.length + 309cdf0e10cSrcweir " tests failed"); 310cdf0e10cSrcweir } 311cdf0e10cSrcweir 312cdf0e10cSrcweir helper.ProcessHandler ph = (helper.ProcessHandler) param.get( 313cdf0e10cSrcweir "AppProvider"); 314cdf0e10cSrcweir 315cdf0e10cSrcweir if (ph != null) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir office.closeExistingOffice(param, true); 318cdf0e10cSrcweir } 319cdf0e10cSrcweir 320cdf0e10cSrcweir return true; 321cdf0e10cSrcweir } 322cdf0e10cSrcweir getEnv(DescEntry entry, TestParameters param)323cdf0e10cSrcweir protected TestEnvironment getEnv(DescEntry entry, TestParameters param) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir DynamicClassLoader dcl = new DynamicClassLoader(); 326cdf0e10cSrcweir String officeProviderName = (String) param.get("OfficeProvider"); 327cdf0e10cSrcweir AppProvider office = (AppProvider) dcl.getInstance(officeProviderName); 328cdf0e10cSrcweir 329cdf0e10cSrcweir if (office == null) 330cdf0e10cSrcweir { 331cdf0e10cSrcweir System.out.println("ERROR: Wrong parameter 'OfficeProvider', " + 332cdf0e10cSrcweir " it cannot be instantiated."); 333cdf0e10cSrcweir System.exit(-1); 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir XMultiServiceFactory msf = (XMultiServiceFactory) office.getManager( 337cdf0e10cSrcweir param); 338cdf0e10cSrcweir 339cdf0e10cSrcweir if (msf == null) 340cdf0e10cSrcweir { 341cdf0e10cSrcweir return null; 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir param.put("ServiceFactory", msf); 345cdf0e10cSrcweir 346cdf0e10cSrcweir TestCase tCase = (TestCase) new BasicTestCase(entry); 347cdf0e10cSrcweir 348cdf0e10cSrcweir System.out.println("Creating: " + tCase.getObjectName()); 349cdf0e10cSrcweir 350cdf0e10cSrcweir LogWriter log = (LogWriter) dcl.getInstance( 351cdf0e10cSrcweir (String) param.get("LogWriter")); 352cdf0e10cSrcweir log.initialize(entry, true); 353cdf0e10cSrcweir entry.UserDefinedParams = param; 354cdf0e10cSrcweir tCase.setLogWriter((PrintWriter) log); 355cdf0e10cSrcweir 356cdf0e10cSrcweir TestEnvironment tEnv = null; 357cdf0e10cSrcweir 358cdf0e10cSrcweir try 359cdf0e10cSrcweir { 360cdf0e10cSrcweir tCase.initializeTestCase(param); 361cdf0e10cSrcweir tEnv = tCase.getTestEnvironment(param); 362cdf0e10cSrcweir } 363cdf0e10cSrcweir catch (java.lang.RuntimeException e) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir System.out.println(e.getMessage()); 366cdf0e10cSrcweir 367cdf0e10cSrcweir helper.ProcessHandler ph = (helper.ProcessHandler) param.get( 368cdf0e10cSrcweir "AppProvider"); 369cdf0e10cSrcweir 370cdf0e10cSrcweir if (ph != null) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir office.closeExistingOffice(param, true); 373cdf0e10cSrcweir shortWait(5000); 374cdf0e10cSrcweir } 375cdf0e10cSrcweir 376cdf0e10cSrcweir entry.ErrorMsg = e.getMessage(); 377cdf0e10cSrcweir entry.hasErrorMsg = true; 378cdf0e10cSrcweir } 379cdf0e10cSrcweir 380cdf0e10cSrcweir return tEnv; 381cdf0e10cSrcweir } 382cdf0e10cSrcweir shortWait(int millis)383cdf0e10cSrcweir protected void shortWait(int millis) 384cdf0e10cSrcweir { 385cdf0e10cSrcweir try 386cdf0e10cSrcweir { 387cdf0e10cSrcweir Thread.sleep(millis); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir catch (java.lang.InterruptedException ie) 390cdf0e10cSrcweir { 391cdf0e10cSrcweir } 392cdf0e10cSrcweir } 393cdf0e10cSrcweir getExclusionList(String url, boolean debug)394cdf0e10cSrcweir protected Vector getExclusionList(String url, boolean debug) 395cdf0e10cSrcweir { 396cdf0e10cSrcweir Vector entryList = new Vector(); 397cdf0e10cSrcweir String line = "#"; 398cdf0e10cSrcweir BufferedReader exclusion = null; 399cdf0e10cSrcweir 400cdf0e10cSrcweir try 401cdf0e10cSrcweir { 402cdf0e10cSrcweir exclusion = new BufferedReader(new FileReader(url)); 403cdf0e10cSrcweir } 404cdf0e10cSrcweir catch (java.io.FileNotFoundException fnfe) 405cdf0e10cSrcweir { 406cdf0e10cSrcweir if (debug) 407cdf0e10cSrcweir { 408cdf0e10cSrcweir System.out.println("Couldn't find file " + url); 409cdf0e10cSrcweir } 410cdf0e10cSrcweir 411cdf0e10cSrcweir return entryList; 412cdf0e10cSrcweir } 413cdf0e10cSrcweir 414cdf0e10cSrcweir while (line != null) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir try 417cdf0e10cSrcweir { 418cdf0e10cSrcweir if (!line.startsWith("#")) 419cdf0e10cSrcweir { 420cdf0e10cSrcweir entryList.add(line); 421cdf0e10cSrcweir } 422cdf0e10cSrcweir 423cdf0e10cSrcweir line = exclusion.readLine(); 424cdf0e10cSrcweir } 425cdf0e10cSrcweir catch (java.io.IOException ioe) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir if (debug) 428cdf0e10cSrcweir { 429cdf0e10cSrcweir System.out.println( 430cdf0e10cSrcweir "Exception while reading exclusion list"); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir 433cdf0e10cSrcweir return entryList; 434cdf0e10cSrcweir } 435cdf0e10cSrcweir } 436cdf0e10cSrcweir 437cdf0e10cSrcweir try 438cdf0e10cSrcweir { 439cdf0e10cSrcweir exclusion.close(); 440cdf0e10cSrcweir } 441cdf0e10cSrcweir catch (java.io.IOException ioe) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir if (debug) 444cdf0e10cSrcweir { 445cdf0e10cSrcweir System.out.println("Couldn't close file " + url); 446cdf0e10cSrcweir } 447cdf0e10cSrcweir 448cdf0e10cSrcweir return entryList; 449cdf0e10cSrcweir } 450cdf0e10cSrcweir 451cdf0e10cSrcweir return entryList; 452cdf0e10cSrcweir } 453cdf0e10cSrcweir } 454