1 /* 2 * Copyright (C) 2010-2014 Hamburg Sud and the contributors. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package org.aludratest.service.cmdline; 17 18 import java.io.InputStream; 19 import java.io.OutputStream; 20 21 import org.aludratest.impl.log4testing.ElementName; 22 import org.aludratest.impl.log4testing.ElementType; 23 import org.aludratest.impl.log4testing.TechnicalArgument; 24 import org.aludratest.impl.log4testing.TechnicalLocator; 25 import org.aludratest.service.Interaction; 26 import org.databene.commons.Validator; 27 28 /** Provides methods for interacting with the command line. 29 * @author Volker Bergmann */ 30 public interface CommandLineInteraction extends Interaction { 31 32 /** Creates a process. 33 * @param processType the process type 34 * @param processName the process name 35 * @param processTimeout the maximum time to wait for process termination 36 * @param responseTimeout the maximum time to wait for process response 37 * @param command 38 * @return the processId */ 39 int create(@ElementType String processType, @ElementName String processName, @TechnicalArgument int processTimeout, 40 @TechnicalArgument int responseTimeout, String... command); 41 42 /** Sets the working directory of the specified process. 43 * @param processType the process type 44 * @param processName the process name 45 * @param processId the internal id of the process 46 * @param relativeWorkingDirectory the path of the process' working directory relative to the configuration's base.directory setting */ 47 void setRelativeWorkingDirectory(@ElementType String processType, @ElementName String processName, 48 @TechnicalLocator int processId, String relativeWorkingDirectory); 49 50 /** Sets an environment variable of the specified process. 51 * @param processType the process type 52 * @param processName the process name 53 * @param processId the internal id of the process 54 * @param key 55 * @param value */ 56 void setEnvironmentVariable(@ElementType String processType, @ElementName String processName, 57 @TechnicalLocator int processId, String key, String value); 58 59 /** Redirects the standard output of the referenced process to the provided {@link OutputStream}. 60 * @param processType the process type 61 * @param processName the process name 62 * @param processId the internal id of the process 63 * @param out */ 64 void redirectStdOutTo(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId, 65 OutputStream out); 66 67 /** Redirects the error output of the referenced process to the provided {@link OutputStream}. 68 * @param processType the process type 69 * @param processName the process name 70 * @param processId the internal id of the process 71 * @param out */ 72 void redirectErrOutTo(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId, 73 OutputStream out); 74 75 /** Redirects provided {@link OutputStream}'s output to the standard input of the referenced process. 76 * @param processType the process type 77 * @param processName the process name 78 * @param processId the internal id of the process 79 * @param in */ 80 void redirectStdInFrom(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId, 81 InputStream in); 82 83 /** Starts the referenced process. 84 * @param processType the process type 85 * @param processName the process name 86 * @param processId the internal id of the process */ 87 void start(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId); 88 89 /** Reads the next line of the referenced process' standard output. 90 * @param processType the process type 91 * @param processName the process name 92 * @param processId the internal id of the process 93 * @return */ 94 String readLineOfStdOut(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId); 95 96 /** Skips the references process' standard output lines until a line matches the validator or the no more output is available. 97 * @param processType the process type 98 * @param processName the process name 99 * @param processId the internal id of the process 100 * @param validator */ 101 void skipStdOutUntilLineMatches(@ElementType String processType, @ElementName String processName, 102 @TechnicalLocator int processId, Validator<String> validator); 103 104 /** Reads the next line of the referenced process' error output. 105 * @param processType the process type 106 * @param processName the process name 107 * @param processId the internal id of the process 108 * @return */ 109 String readLineOfErrOut(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId); 110 111 /** Skips lines of the refernced process' error output until a line matches the Validator. 112 * @param processType the process type 113 * @param processName the process name 114 * @param processId the internal id of the process 115 * @param validator */ 116 void skipErrOutUntilLineMatches(@ElementType String processType, @ElementName String processName, 117 @TechnicalLocator int processId, Validator<String> validator); 118 119 /** Enters a text into the referenced process' standard input. 120 * @param processType the process type 121 * @param processName the process name 122 * @param processId the internal id of the process 123 * @param text */ 124 void enter(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId, String text); 125 126 /** Waits until the references process has finished. 127 * @param processType the process type 128 * @param processName the process name 129 * @param processId the internal id of the process 130 * @return */ 131 int waitUntilFinished(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId); 132 133 /** Destroys the referenced process. 134 * @param processType the process type 135 * @param processName the process name 136 * @param processId the internal id of the process */ 137 void destroy(@ElementType String processType, @ElementName String processName, @TechnicalLocator int processId); 138 139 }