Java Code Examples for jdk.testlibrary.OutputAnalyzer#stdoutShouldNotContain()

The following examples show how to use jdk.testlibrary.OutputAnalyzer#stdoutShouldNotContain() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestNative.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    String lib = System.getProperty("test.nativepath");
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true, "-Djava.library.path=" + lib, "jdk.jfr.event.sampling.TestNative$Test");

    OutputAnalyzer output = ProcessTools.executeProcess(pb);
    output.shouldHaveExitValue(0);
    output.stdoutShouldNotContain("No native samples found");
}
 
Example 2
Source File: TsacertOptionTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
void start() throws Throwable {
    // create a jar file that contains one file
    Utils.createFiles(FILENAME);
    JarUtils.createJar(UNSIGNED_JARFILE, FILENAME);

    // look for free network port for TSA service
    int port = jdk.testlibrary.Utils.getFreePort();
    String host = jdk.testlibrary.Utils.getHostname();
    String tsaUrl = "http://" + host + ":" + port;

    // create key pair for jar signing
    ProcessTools.executeCommand(KEYTOOL,
            "-genkey",
            "-alias", SIGNING_KEY_ALIAS,
            "-keyalg", KEY_ALG,
            "-keysize", Integer.toString(KEY_SIZE),
            "-keystore", KEYSTORE,
            "-storepass", PASSWORD,
            "-keypass", PASSWORD,
            "-dname", "CN=Test",
            "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);

    // create key pair for TSA service
    // SubjectInfoAccess extension contains URL to TSA service
    ProcessTools.executeCommand(KEYTOOL,
            "-genkey",
            "-v",
            "-alias", TSA_KEY_ALIAS,
            "-keyalg", KEY_ALG,
            "-keysize", Integer.toString(KEY_SIZE),
            "-keystore", KEYSTORE,
            "-storepass", PASSWORD,
            "-keypass", PASSWORD,
            "-dname", "CN=TSA",
            "-ext", "ExtendedkeyUsage:critical=timeStamping",
            "-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl,
            "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);

    try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(port,
            KEYSTORE);) {

        // start TSA
        tsa.start();

        // sign jar file
        // specify -tsadigestalg option because
        // TSA server uses SHA-1 digest algorithm
         OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,
                "-J-Dhttp.proxyHost=",
                "-J-Dhttp.proxyPort=",
                "-J-Djava.net.useSystemProxies=",
                "-verbose",
                "-keystore", KEYSTORE,
                "-storepass", PASSWORD,
                "-keypass", PASSWORD,
                "-signedjar", SIGNED_JARFILE,
                "-tsacert", TSA_KEY_ALIAS,
                "-tsadigestalg", "SHA-1",
                UNSIGNED_JARFILE,
                SIGNING_KEY_ALIAS);

        analyzer.shouldHaveExitValue(0);
        analyzer.stdoutShouldNotContain(WARNING);
        analyzer.shouldContain(JAR_SIGNED);

        // verify signed jar
        analyzer = ProcessTools.executeCommand(JARSIGNER,
                "-verbose",
                "-verify",
                "-keystore", KEYSTORE,
                "-storepass", PASSWORD,
                SIGNED_JARFILE);

        analyzer.shouldHaveExitValue(0);
        analyzer.stdoutShouldNotContain(WARNING);
        analyzer.shouldContain(JAR_VERIFIED);
    }

    System.out.println("Test passed");
}
 
Example 3
Source File: TsacertOptionTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
void start() throws Throwable {
    // create a jar file that contains one file
    Utils.createFiles(FILENAME);
    JarUtils.createJar(UNSIGNED_JARFILE, FILENAME);

    // look for free network port for TSA service
    int port = jdk.testlibrary.Utils.getFreePort();
    String host = jdk.testlibrary.Utils.getHostname();
    String tsaUrl = "http://" + host + ":" + port;

    // create key pair for jar signing
    ProcessTools.executeCommand(KEYTOOL,
            "-genkey",
            "-alias", SIGNING_KEY_ALIAS,
            "-keyalg", KEY_ALG,
            "-keysize", Integer.toString(KEY_SIZE),
            "-keystore", KEYSTORE,
            "-storepass", PASSWORD,
            "-keypass", PASSWORD,
            "-dname", "CN=Test",
            "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);

    // create key pair for TSA service
    // SubjectInfoAccess extension contains URL to TSA service
    ProcessTools.executeCommand(KEYTOOL,
            "-genkey",
            "-v",
            "-alias", TSA_KEY_ALIAS,
            "-keyalg", KEY_ALG,
            "-keysize", Integer.toString(KEY_SIZE),
            "-keystore", KEYSTORE,
            "-storepass", PASSWORD,
            "-keypass", PASSWORD,
            "-dname", "CN=TSA",
            "-ext", "ExtendedkeyUsage:critical=timeStamping",
            "-ext", "SubjectInfoAccess=timeStamping:URI:" + tsaUrl,
            "-validity", Integer.toString(VALIDITY)).shouldHaveExitValue(0);

    try (TimestampCheck.Handler tsa = TimestampCheck.Handler.init(port,
            KEYSTORE);) {

        // start TSA
        tsa.start();

        // sign jar file
        // specify -tsadigestalg option because
        // TSA server uses SHA-1 digest algorithm
         OutputAnalyzer analyzer = ProcessTools.executeCommand(JARSIGNER,
                "-J-Dhttp.proxyHost=",
                "-J-Dhttp.proxyPort=",
                "-J-Djava.net.useSystemProxies=",
                "-verbose",
                "-keystore", KEYSTORE,
                "-storepass", PASSWORD,
                "-keypass", PASSWORD,
                "-signedjar", SIGNED_JARFILE,
                "-tsacert", TSA_KEY_ALIAS,
                "-tsadigestalg", "SHA-1",
                UNSIGNED_JARFILE,
                SIGNING_KEY_ALIAS);

        analyzer.shouldHaveExitValue(0);
        analyzer.stdoutShouldNotContain(WARNING);
        analyzer.shouldContain(JAR_SIGNED);

        // verify signed jar
        analyzer = ProcessTools.executeCommand(JARSIGNER,
                "-verbose",
                "-verify",
                "-keystore", KEYSTORE,
                "-storepass", PASSWORD,
                SIGNED_JARFILE);

        analyzer.shouldHaveExitValue(0);
        analyzer.stdoutShouldNotContain(WARNING);
        analyzer.shouldContain(JAR_VERIFIED);
    }

    System.out.println("Test passed");
}