use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class TempDirTest method launchTests.
/**
* Runs the actual tests in nested class TestMain.
* The reason for running the tests in a separate process
* is that we need to modify the class path and
* the -Djava.io.tmpdir property.
*/
private static void launchTests(int pid, Path clientTmpDir) throws Throwable {
final String sep = File.separator;
// Need to add jdk/lib/tools.jar to classpath.
String classpath = System.getProperty("test.class.path", "") + File.pathSeparator + System.getProperty("test.jdk", ".") + sep + "lib" + sep + "tools.jar";
String[] tmpDirArg = null;
if (clientTmpDir != null) {
tmpDirArg = new String[] { "-Djava.io.tmpdir=" + clientTmpDir };
}
// Arguments : [-Djava.io.tmpdir=] -classpath cp TempDirTest$TestMain pid
String[] args = RunnerUtil.concat(tmpDirArg, new String[] { "-classpath", classpath, "TempDirTest$TestMain", Integer.toString(pid) });
OutputAnalyzer output = ProcessTools.executeTestJvm(args);
output.shouldHaveExitValue(0);
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class StoreTrustedCertKeytool method listCerts.
private void listCerts() throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException {
final String[] command = new String[] { "-debug", "-list", "-v", "-alias", ALIAS, "-keystore", KEYSTORE_PATH, "-storetype", "pkcs12", "-storepass", PASSWORD };
OutputAnalyzer output = Utils.executeKeytoolCommand(command);
if (output == null) {
throw new RuntimeException("Keystore print fails");
}
X509Certificate ksCert = null;
final KeyStore ks = Utils.loadKeyStore(KEYSTORE_PATH, Utils.KeyStoreType.pkcs12, PASSWORD.toCharArray());
ksCert = (X509Certificate) ks.getCertificate(ALIAS);
if (ksCert == null) {
throw new RuntimeException("Certificate " + ALIAS + " not found in Keystore " + KEYSTORE_PATH);
}
String serialNumber = ksCert.getSerialNumber().toString(16);
output.shouldContain(serialNumber);
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class Utils method executeKeytoolCommand.
public static OutputAnalyzer executeKeytoolCommand(String[] command, int exitCode) {
String[] keytoolCmd = new String[command.length + 1];
OutputAnalyzer output = null;
try {
keytoolCmd[0] = JDKToolFinder.getJDKTool(KEYTOOL);
System.arraycopy(command, 0, keytoolCmd, 1, command.length);
output = ProcessTools.executeCommand(keytoolCmd);
output.shouldHaveExitValue(exitCode);
out.println("Executed keytool command sucessfully:" + Arrays.toString(keytoolCmd));
} catch (Throwable e) {
e.printStackTrace(System.err);
throw new RuntimeException("Keytool Command execution failed : " + Arrays.toString(keytoolCmd), e);
}
return output;
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class KeytoolWriteP12Test method keytoolListTest.
private void keytoolListTest(String keyStore, Algorithm algorithm, String... optionalArgs) {
final String keyStoreName = WORKING_DIRECTORY + File.separator + keyStore;
final String[] command = new String[] { "-debug", "-list", "-v", "-alias", ALIAS, "-keystore", keyStoreName, "-storetype", "pkcs12", "-storepass", Utils.DEFAULT_PASSWD };
deleteKeyStoreFile(keyStoreName);
Utils.createKeyStore(DNAME, PKCS12, keyStoreName, ALIAS, algorithm.name(), optionalArgs);
OutputAnalyzer output = Utils.executeKeytoolCommand(command);
output.shouldContain(DNAME);
}
use of jdk.testlibrary.OutputAnalyzer in project jdk8u_jdk by JetBrains.
the class NoPremainAgentTest method main.
// Use a javaagent without the premain() function.
// Verify that we get the correct exception.
public static void main(String[] a) throws Exception {
String testArgs = String.format("-javaagent:NoPremainAgent.jar -classpath %s DummyMain", System.getProperty("test.classes", "."));
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(Utils.addTestJavaOpts(testArgs.split("\\s+")));
System.out.println("testjvm.cmd:" + Utils.getCommandLine(pb));
OutputAnalyzer output = new OutputAnalyzer(pb.start());
System.out.println("testjvm.stdout:" + output.getStdout());
System.out.println("testjvm.stderr:" + output.getStderr());
output.stderrShouldContain("java.lang.NoSuchMethodException");
if (0 == output.getExitValue()) {
throw new RuntimeException("Expected error but got exit value 0");
}
}
Aggregations