1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 package convwatch; 23 24 import complexlib.ComplexTestCase; 25 import helper.ProcessHandler; 26 import convwatch.GraphicalTestArguments; 27 28 /** 29 * Some Helperfunctions which are nice in ReferenceBuilder and ConvWatchTest 30 */ 31 32 public abstract class EnhancedComplexTestCase extends ComplexTestCase 33 { 34 // public void before() 35 // { 36 // // System.out.println("before()"); 37 // } 38 // 39 // public void after() 40 // { 41 // // System.out.println("after()"); 42 // } 43 checkExistance(String _sScriptFile, String _sName)44 void checkExistance(String _sScriptFile, String _sName) 45 { 46 boolean bBackValue = false; 47 // Process testshl = Runtime.getRuntime().exec(scriptFile); 48 ProcessHandler aHandler = new ProcessHandler(_sScriptFile); 49 bBackValue = aHandler.executeSynchronously(); 50 TimeHelper.waitInSeconds(1, "wait after ProcessHandler.executeSynchronously()"); 51 52 StringBuffer aBuffer = new StringBuffer(); 53 aBuffer.append(aHandler.getErrorText()).append(aHandler.getOutputText()); 54 String sText = aBuffer.toString(); 55 56 if (sText.length() == 0) 57 { 58 String sError = "Must quit. " + _sName + " may be not accessible."; 59 assure(sError, false); 60 // System.exit(1); 61 } 62 else 63 { 64 // System.out.println("Output from script:"); 65 // System.out.println(sText); 66 } 67 } 68 69 // ----------------------------------------------------------------------------- 70 checkEnvironment(Object[] _aList)71 protected void checkEnvironment(Object[] _aList) 72 { 73 // checks if some packages already installed, 74 // this function will not return if packages are not installed, 75 // it will call System.exit(1)! 76 77 if (needCheckForInstalledSoftware()) 78 { 79 for (int i=0;i<_aList.length;i++) 80 { 81 String sCommand = (String)_aList[i]; 82 // TODO: nice to have, a pair object 83 checkExistance(sCommand, sCommand); 84 } 85 } 86 } 87 88 // ----------------------------------------------------------------------------- 89 mustInstalledSoftware()90 protected abstract Object[] mustInstalledSoftware(); needCheckForInstalledSoftware()91 public boolean needCheckForInstalledSoftware() 92 { 93 String sNEEDCHECK = (String)param.get( PropertyName.CHECK_NEED_TOOLS ); 94 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns 95 // with a default of 'false' which is not very helpful if the default should be 'true' 96 // maybe a getBoolean("name", true) could be a better choice. 97 if (sNEEDCHECK == null) 98 { 99 sNEEDCHECK = "false"; 100 } 101 if (sNEEDCHECK.toLowerCase().equals("yes") || 102 sNEEDCHECK.toLowerCase().equals("true")) 103 { 104 return true; 105 } 106 return false; 107 } 108 109 // ----------------------------------------------------------------------------- 110 getGraphicalTestArguments()111 public GraphicalTestArguments getGraphicalTestArguments() 112 { 113 GraphicalTestArguments aGTA = new GraphicalTestArguments(param); 114 if (aGTA.getImportFilterName() != null && aGTA.getImportFilterName().toLowerCase().equals("help")) 115 { 116 aGTA = null; 117 } 118 if (aGTA.getExportFilterName() != null && aGTA.getExportFilterName().toLowerCase().equals("help")) 119 { 120 aGTA = null; 121 } 122 return aGTA; 123 } 124 } 125