xref: /trunk/main/testtools/qa/cli/CLITest.java (revision 3309286857f19787ae62bd793a98b5af4edd2ad3)
15c44d1b3SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
35c44d1b3SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
45c44d1b3SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
55c44d1b3SAndrew Rist  * distributed with this work for additional information
65c44d1b3SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
75c44d1b3SAndrew Rist  * to you under the Apache License, Version 2.0 (the
85c44d1b3SAndrew Rist  * "License"); you may not use this file except in compliance
95c44d1b3SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
115c44d1b3SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
135c44d1b3SAndrew Rist  * Unless required by applicable law or agreed to in writing,
145c44d1b3SAndrew Rist  * software distributed under the License is distributed on an
155c44d1b3SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
165c44d1b3SAndrew Rist  * KIND, either express or implied.  See the License for the
175c44d1b3SAndrew Rist  * specific language governing permissions and limitations
185c44d1b3SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
205c44d1b3SAndrew Rist  *************************************************************/
215c44d1b3SAndrew Rist 
225c44d1b3SAndrew Rist 
23cdf0e10cSrcweir package clitest;
24cdf0e10cSrcweir 
25cdf0e10cSrcweir 
26cdf0e10cSrcweir import java.io.*;
27cdf0e10cSrcweir 
28*d55f601aSDamjan Jovanovic import org.junit.Test;
29*d55f601aSDamjan Jovanovic import static org.junit.Assert.*;
30cdf0e10cSrcweir 
31*d55f601aSDamjan Jovanovic 
32*d55f601aSDamjan Jovanovic public class CLITest
33cdf0e10cSrcweir {
34*d55f601aSDamjan Jovanovic     @Test
runCLITests()35*d55f601aSDamjan Jovanovic     public void runCLITests() throws Exception
36cdf0e10cSrcweir     {
37cdf0e10cSrcweir         String testProgram = System.getProperty("cli_test", "");
38cdf0e10cSrcweir         if (testProgram.length() == 0)
39*d55f601aSDamjan Jovanovic             fail("Check the make file. Java must be called with -Dcli_test=pathtoexe");
40cdf0e10cSrcweir 
41cdf0e10cSrcweir         String arg1 = System.getProperty("cli_test_arg", "");
42cdf0e10cSrcweir         if (arg1.length() == 0)
43*d55f601aSDamjan Jovanovic             fail("Check the make file. Java must be called with " +
44cdf0e10cSrcweir                  "-Dcli_test_arg=path_to_bootstrap_ini");
45cdf0e10cSrcweir         String[] cmdarray = new String[] {testProgram, arg1};
46cdf0e10cSrcweir 
47cdf0e10cSrcweir         Process proc = null;
48cdf0e10cSrcweir         Reader outReader;
49cdf0e10cSrcweir         Reader errReader;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir         proc = Runtime.getRuntime().exec(cmdarray);
52cdf0e10cSrcweir         outReader = new Reader(proc.getInputStream());
53cdf0e10cSrcweir         errReader = new Reader(proc.getErrorStream());
54cdf0e10cSrcweir //       System.out.println("### waiting for " + testProgram);
55cdf0e10cSrcweir         proc.waitFor();
56cdf0e10cSrcweir         int retVal = proc.exitValue();
57*d55f601aSDamjan Jovanovic         System.out.println("### " + testProgram + " finished with exit code " + retVal);
58*d55f601aSDamjan Jovanovic         assertTrue("CLI test failed.", retVal == 0);
59cdf0e10cSrcweir     }
60cdf0e10cSrcweir }
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /*  This reads reads from an InputStream and discards the data.
64cdf0e10cSrcweir  */
65cdf0e10cSrcweir class Reader extends Thread
66cdf0e10cSrcweir {
67cdf0e10cSrcweir     InputStream is;
Reader(InputStream stream)68cdf0e10cSrcweir     public Reader(InputStream stream)
69cdf0e10cSrcweir     {
70cdf0e10cSrcweir         is = stream;
71cdf0e10cSrcweir         start();
72cdf0e10cSrcweir     }
73cdf0e10cSrcweir 
run()74cdf0e10cSrcweir     public void run()
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         try
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir             byte[] buf = new byte[1024];
79cdf0e10cSrcweir             while (-1 != is.read(buf));
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir         catch (java.io.IOException exc)
82cdf0e10cSrcweir         {
83cdf0e10cSrcweir         }
84cdf0e10cSrcweir     }
85cdf0e10cSrcweir }
86