1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
|
/*
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package nsk.jdi.VirtualMachineManager.createVirtualMachine;
import nsk.share.*;
import nsk.share.jdi.*;
import com.sun.jdi.*;
import com.sun.jdi.connect.*;
import com.sun.jdi.connect.spi.*;
import java.util.*;
import java.io.*;
/**
* The test for the <BR>
* virtualMachineManager.createVirtualMachine(...) methods. <BR>
* <BR>
* The test checks up that both createVirtualMachine(Connection) and <BR>
* createVirtualMachine(Connection, Process) methods throw <BR>
* IllegalStateException if the used Connection is not open. <BR>
* <BR>
*/
public class createVM001 {
static final int STATUS_PASSED = 0;
static final int STATUS_FAILED = 2;
static final int STATUS_TEMP = 95;
static final String errorLogPrefixHead = "createVM001: ";
static final String errorLogPrefix = " ";
static final String infoLogPrefixHead = "--> createVM001: ";
static final String infoLogPrefix = "--> ";
static final String emptyString = "";
static ArgumentHandler argsHandler;
static Log logHandler;
private static void logOnVerbose(String message) {
logHandler.display(message);
}
private static void logOnError(String message) {
logHandler.complain(message);
}
private static void logAlways(String message) {
logHandler.println(message);
}
public static void main (String argv[]) {
int result = run(argv,System.out);
if (result != 0) {
throw new RuntimeException("TEST FAILED with result " + result);
}
}
public static int run (String argv[], PrintStream out) {
int result = new createVM001().runThis(argv, out);
if ( result == STATUS_FAILED ) {
logAlways("\n##> nsk/jdi/VirtualMachineManager/createVirtualMachine/createVM001 test FAILED");
}
else {
logAlways("\n==> nsk/jdi/VirtualMachineManager/createVirtualMachine/createVM001 test PASSED");
}
return result;
}
private int runThis (String argv[], PrintStream out) {
int testResult = STATUS_PASSED;
argsHandler = new ArgumentHandler(argv);
logHandler = new Log(out, argsHandler);
logAlways("==> nsk/jdi/VirtualMachineManager/createVirtualMachine/createVM001 test...");
logOnVerbose
("==> Test checks that virtualMachineManager.createVirtualMachine(...) methods");
logOnVerbose
("==> throw IllegalStateException for Connection that is not open.");
VirtualMachineManager virtualMachineManager = Bootstrap.virtualMachineManager();
if (virtualMachineManager == null) {
logOnError(errorLogPrefixHead + "Bootstrap.virtualMachineManager() returns null.");
return STATUS_FAILED;
}
// check method virtualMachineManager.createVirtualMachine(Connection)...
Connection testConnection = new createVM001_Connection();
try {
VirtualMachine dummyVM = virtualMachineManager.createVirtualMachine(testConnection);
} catch ( IllegalStateException illegStExcep ) {
// OK - expected IllegalStateException because Connection is not open
} catch ( Throwable thrown ) {
logOnError(errorLogPrefixHead + "virtualMachineManager.createVirtualMachine(Connection) throws");
logOnError(errorLogPrefix + "unexpected Exception for Connection that is not open:");
logOnError(errorLogPrefix + "Expected Exception - IllegalStateException");
logOnError(errorLogPrefix + "Actual Exception - '" + thrown + "'");
testResult = STATUS_FAILED;
}
// check method virtualMachineManager.createVirtualMachine(Connection, Process)...
testConnection = new createVM001_Connection();
Process dummyProcess = new createVM001_Process();
try {
VirtualMachine dummyVM = virtualMachineManager.createVirtualMachine(testConnection, dummyProcess);
} catch ( IllegalStateException illegStExcep ) {
// OK - expected IllegalStateException because Connection is not open
} catch ( Throwable thrown ) {
logOnError(errorLogPrefixHead + "virtualMachineManager.createVirtualMachine(Connection, Process)");
logOnError(errorLogPrefix + "throws unexpected Exception for Connection that is not open:");
logOnError(errorLogPrefix + "Expected Exception - IllegalStateException");
logOnError(errorLogPrefix + "Actual Exception - '" + thrown + "'");
testResult = STATUS_FAILED;
}
return testResult;
}
} // end of createVM001 class
class createVM001_Connection extends Connection {
public void close() throws IOException {
if ( true ) {
throw new IOException("Dummy IOException in createVM001_Connection.close().");
}
}
public boolean isOpen() {
return false;
}
public byte[] readPacket() throws IOException {
if ( true ) {
throw new IOException("Dummy IOException in createVM001_Connection.readPacket().");
}
return new byte[11];
}
public void writePacket(byte b[]) throws IOException {
if ( true ) {
throw new IOException("Dummy IOException in createVM001_Connection.writePacket(byte b[]).");
}
}
} // end of createVM001_Connection class
class createVM001_Process extends Process {
public OutputStream getOutputStream() {
return null;
}
public InputStream getInputStream() {
return null;
}
public InputStream getErrorStream() {
return null;
}
public int waitFor() throws InterruptedException {
return 0;
}
public int exitValue() {
return 0;
}
public void destroy() {
}
} // end of createVM001_Process class
|