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 package clitest; 24 25 26 import java.io.*; 27 28 import org.junit.Test; 29 import static org.junit.Assert.*; 30 31 32 public class CLITest 33 { 34 @Test runCLITests()35 public void runCLITests() throws Exception 36 { 37 String testProgram = System.getProperty("cli_test", ""); 38 if (testProgram.length() == 0) 39 fail("Check the make file. Java must be called with -Dcli_test=pathtoexe"); 40 41 String arg1 = System.getProperty("cli_test_arg", ""); 42 if (arg1.length() == 0) 43 fail("Check the make file. Java must be called with " + 44 "-Dcli_test_arg=path_to_bootstrap_ini"); 45 String[] cmdarray = new String[] {testProgram, arg1}; 46 47 Process proc = null; 48 Reader outReader; 49 Reader errReader; 50 51 proc = Runtime.getRuntime().exec(cmdarray); 52 outReader = new Reader(proc.getInputStream()); 53 errReader = new Reader(proc.getErrorStream()); 54 // System.out.println("### waiting for " + testProgram); 55 proc.waitFor(); 56 int retVal = proc.exitValue(); 57 System.out.println("### " + testProgram + " finished with exit code " + retVal); 58 assertTrue("CLI test failed.", retVal == 0); 59 } 60 } 61 62 63 /* This reads reads from an InputStream and discards the data. 64 */ 65 class Reader extends Thread 66 { 67 InputStream is; Reader(InputStream stream)68 public Reader(InputStream stream) 69 { 70 is = stream; 71 start(); 72 } 73 run()74 public void run() 75 { 76 try 77 { 78 byte[] buf = new byte[1024]; 79 while (-1 != is.read(buf)); 80 } 81 catch (java.io.IOException exc) 82 { 83 } 84 } 85 } 86