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 
23 
24 package convwatch;
25 
26 import complexlib.ComplexTestCase;
27 import helper.ProcessHandler;
28 import convwatch.GraphicalTestArguments;
29 
30 /**
31  * Some Helperfunctions which are nice in ReferenceBuilder and ConvWatchTest
32  */
33 
34 public abstract class EnhancedComplexTestCase extends ComplexTestCase
35 {
36     // public void before()
37     //     {
38     //         // System.out.println("before()");
39     //     }
40     //
41     // public void after()
42     //     {
43     //         // System.out.println("after()");
44     //     }
45 
checkExistance(String _sScriptFile, String _sName)46     void checkExistance(String _sScriptFile, String _sName)
47         {
48             boolean bBackValue = false;
49             // Process testshl = Runtime.getRuntime().exec(scriptFile);
50             ProcessHandler aHandler = new ProcessHandler(_sScriptFile);
51             bBackValue = aHandler.executeSynchronously();
52             TimeHelper.waitInSeconds(1, "wait after ProcessHandler.executeSynchronously()");
53 
54             StringBuffer aBuffer = new StringBuffer();
55             aBuffer.append(aHandler.getErrorText()).append(aHandler.getOutputText());
56             String sText = aBuffer.toString();
57 
58             if (sText.length() == 0)
59             {
60                 String sError = "Must quit. " + _sName + " may be not accessible.";
61                 assure(sError, false);
62                 // System.exit(1);
63             }
64             else
65             {
66                 // System.out.println("Output from script:");
67                 // System.out.println(sText);
68             }
69         }
70 
71     // -----------------------------------------------------------------------------
72 
checkEnvironment(Object[] _aList)73     protected void checkEnvironment(Object[] _aList)
74         {
75             // checks if some packages already installed,
76             // this function will not return if packages are not installed,
77             // it will call System.exit(1)!
78 
79             if (needCheckForInstalledSoftware())
80             {
81                 for (int i=0;i<_aList.length;i++)
82                 {
83                     String sCommand = (String)_aList[i];
84                     // TODO: nice to have, a pair object
85                     checkExistance(sCommand, sCommand);
86                 }
87             }
88         }
89 
90     // -----------------------------------------------------------------------------
91 
mustInstalledSoftware()92     protected abstract Object[] mustInstalledSoftware();
needCheckForInstalledSoftware()93     public boolean needCheckForInstalledSoftware()
94         {
95             String sNEEDCHECK = (String)param.get( PropertyName.CHECK_NEED_TOOLS );
96 // TODO: I need to get the boolean value with get("name") because, if it is not given getBool() returns
97 //       with a default of 'false' which is not very helpful if the default should be 'true'
98 //       maybe a getBoolean("name", true) could be a better choise.
99             if (sNEEDCHECK == null)
100             {
101                 sNEEDCHECK = "false";
102             }
103             if (sNEEDCHECK.toLowerCase().equals("yes") ||
104                 sNEEDCHECK.toLowerCase().equals("true"))
105             {
106                 return true;
107             }
108             return false;
109         }
110 
111     // -----------------------------------------------------------------------------
112 
getGraphicalTestArguments()113     public GraphicalTestArguments getGraphicalTestArguments()
114         {
115             GraphicalTestArguments aGTA = new GraphicalTestArguments(param);
116             if (aGTA.getImportFilterName() != null && aGTA.getImportFilterName().toLowerCase().equals("help"))
117             {
118                 aGTA = null;
119             }
120             if (aGTA.getExportFilterName() != null && aGTA.getExportFilterName().toLowerCase().equals("help"))
121             {
122                 aGTA = null;
123             }
124             return aGTA;
125         }
126 }
127