1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir package base; 28*cdf0e10cSrcweir 29*cdf0e10cSrcweir import complexlib.ComplexTestCase; 30*cdf0e10cSrcweir import util.DynamicClassLoader; 31*cdf0e10cSrcweir import share.DescGetter; 32*cdf0e10cSrcweir import stats.OutProducerFactory; 33*cdf0e10cSrcweir import helper.ComplexDescGetter; 34*cdf0e10cSrcweir import helper.AppProvider; 35*cdf0e10cSrcweir import helper.CfgParser; 36*cdf0e10cSrcweir import share.DescEntry; 37*cdf0e10cSrcweir import share.LogWriter; 38*cdf0e10cSrcweir import stats.Summarizer; 39*cdf0e10cSrcweir import lib.TestParameters; 40*cdf0e10cSrcweir import util.PropertyName; 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir /** 43*cdf0e10cSrcweir * Test base for executing a java complex test. 44*cdf0e10cSrcweir * @see base.TestBase 45*cdf0e10cSrcweir */ 46*cdf0e10cSrcweir public class java_complex implements TestBase 47*cdf0e10cSrcweir { 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir /** 50*cdf0e10cSrcweir * This function executes the complex tests given as parameter "-o" or "TestJob". It querys for the correspond class 51*cdf0e10cSrcweir * and crates the JobDescription. 52*cdf0e10cSrcweir * @param param 53*cdf0e10cSrcweir * @return true of all tests run successfuly, esle false 54*cdf0e10cSrcweir */ 55*cdf0e10cSrcweir public boolean executeTest(TestParameters param) 56*cdf0e10cSrcweir { 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir // is there an ini file for the complex tests defined? 59*cdf0e10cSrcweir String complexIniFileName = ((String) param.get("ComplexIni")); 60*cdf0e10cSrcweir if (complexIniFileName != null) 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir CfgParser ini = new CfgParser(complexIniFileName); 63*cdf0e10cSrcweir ini.getIniParameters(param); 64*cdf0e10cSrcweir } 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir // get the test job 67*cdf0e10cSrcweir String testJob = ((String) param.get("TestJob")); 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir DescGetter descGetter = new ComplexDescGetter(); 70*cdf0e10cSrcweir // get the test jobs 71*cdf0e10cSrcweir DescEntry[] entries = descGetter.getDescriptionFor(testJob, null, true); 72*cdf0e10cSrcweir return executeTest(param, entries); 73*cdf0e10cSrcweir 74*cdf0e10cSrcweir } 75*cdf0e10cSrcweir 76*cdf0e10cSrcweir /** 77*cdf0e10cSrcweir * This function run the given DescEntry[] as ComplexTest 78*cdf0e10cSrcweir * @param param 79*cdf0e10cSrcweir * @param entries 80*cdf0e10cSrcweir * @return true of all tests run successfuly, esle false 81*cdf0e10cSrcweir */ 82*cdf0e10cSrcweir public boolean executeTest(TestParameters param, DescEntry[] entries) 83*cdf0e10cSrcweir { 84*cdf0e10cSrcweir // is there an ini file for the complex tests defined? 85*cdf0e10cSrcweir String complexIniFileName = ((String) param.get("ComplexIni")); 86*cdf0e10cSrcweir if (complexIniFileName != null) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir CfgParser ini = new CfgParser(complexIniFileName); 89*cdf0e10cSrcweir ini.getIniParameters(param); 90*cdf0e10cSrcweir } 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir DynamicClassLoader dcl = new DynamicClassLoader(); 93*cdf0e10cSrcweir ComplexTestCase testClass = null; 94*cdf0e10cSrcweir boolean returnVal = true; 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir // the concept of the TimeOut depends on runner logs. If the runner log, 97*cdf0e10cSrcweir // for exmaple to start a test method, the timeout was restet. This is not 98*cdf0e10cSrcweir // while the test itself log something like "open docuent...". 99*cdf0e10cSrcweir // An property of complex test could be that it have only one test method 100*cdf0e10cSrcweir // which works for serveral minutes. Ih this case the TimeOut get not trigger 101*cdf0e10cSrcweir // and the office was killed. 102*cdf0e10cSrcweir // In complex tests just use "ThreadTimeOut" as timout. 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir // param.put("TimeOut", new Integer(0)); 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir for (int i = 0; i < entries.length; i++) 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir if (entries[i] == null) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir continue; 112*cdf0e10cSrcweir } 113*cdf0e10cSrcweir String iniName = entries[i].longName; 114*cdf0e10cSrcweir iniName = iniName.replace('.', '/'); 115*cdf0e10cSrcweir CfgParser ini = new CfgParser(iniName + ".props"); 116*cdf0e10cSrcweir ini.getIniParameters(param); 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir LogWriter log = (LogWriter) dcl.getInstance((String) param.get("LogWriter")); 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir AppProvider office = null; 121*cdf0e10cSrcweir if (!param.getBool("NoOffice")) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir try 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir office = (AppProvider) dcl.getInstance("helper.OfficeProvider"); 126*cdf0e10cSrcweir Object msf = office.getManager(param); 127*cdf0e10cSrcweir if (msf == null) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir returnVal = false; 130*cdf0e10cSrcweir continue; 131*cdf0e10cSrcweir } 132*cdf0e10cSrcweir param.put("ServiceFactory", msf); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir catch (IllegalArgumentException e) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir office = null; 137*cdf0e10cSrcweir } 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir log.initialize(entries[i], param.getBool(PropertyName.LOGGING_IS_ACTIVE)); 140*cdf0e10cSrcweir entries[i].Logger = log; 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir // create an instance 143*cdf0e10cSrcweir try 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir testClass = (ComplexTestCase) dcl.getInstance(entries[i].longName); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir catch (java.lang.Exception e) 148*cdf0e10cSrcweir { 149*cdf0e10cSrcweir e.printStackTrace(); 150*cdf0e10cSrcweir return false; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir testClass.executeMethods(entries[i], param); 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir Summarizer sum = new Summarizer(); 155*cdf0e10cSrcweir sum.summarizeUp(entries[i]); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir if (office != null) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir office.closeExistingOffice(param, false); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir LogWriter out = OutProducerFactory.createOutProducer(param); 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir out.initialize(entries[i], true); 165*cdf0e10cSrcweir out.summary(entries[i]); 166*cdf0e10cSrcweir returnVal &= entries[i].State.endsWith("OK"); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir return returnVal; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir } 171