4183N/A/*
4183N/A * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
4183N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4183N/A *
4183N/A * This code is free software; you can redistribute it and/or modify it
4183N/A * under the terms of the GNU General Public License version 2 only, as
4183N/A * published by the Free Software Foundation.
4183N/A *
4183N/A * This code is distributed in the hope that it will be useful, but WITHOUT
4183N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
4183N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4183N/A * version 2 for more details (a copy is included in the LICENSE file that
4183N/A * accompanied this code).
4183N/A *
4183N/A * You should have received a copy of the GNU General Public License version
4183N/A * 2 along with this work; if not, write to the Free Software Foundation,
4183N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
4183N/A *
4183N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
4183N/A * or visit www.oracle.com if you need additional information or have any
4183N/A * questions.
4183N/A */
4183N/A
4183N/A/*
4183N/A * @test
4183N/A * @summary Test the OutputAnalyzer utility class
4183N/A * @library /testlibrary
4183N/A */
4183N/A
4183N/Aimport com.oracle.java.testlibrary.OutputAnalyzer;
4183N/A
4183N/Apublic class OutputAnalyzerTest {
4183N/A
4183N/A public static void main(String args[]) throws Exception {
4183N/A
4183N/A String stdout = "aaaaaa";
4183N/A String stderr = "bbbbbb";
4183N/A
4437N/A // Regexps used for testing pattern matching of the test input
4437N/A String stdoutPattern = "[a]";
4437N/A String stderrPattern = "[b]";
4437N/A String nonExistingPattern = "[c]";
4437N/A
4183N/A OutputAnalyzer output = new OutputAnalyzer(stdout, stderr);
4183N/A
4183N/A if (!stdout.equals(output.getStdout())) {
4183N/A throw new Exception("getStdout() returned '" + output.getStdout() + "', expected '" + stdout + "'");
4183N/A }
4183N/A
4183N/A if (!stderr.equals(output.getStderr())) {
4183N/A throw new Exception("getStderr() returned '" + output.getStderr() + "', expected '" + stderr + "'");
4183N/A }
4183N/A
4183N/A try {
4183N/A output.shouldContain(stdout);
4183N/A output.stdoutShouldContain(stdout);
4183N/A output.shouldContain(stderr);
4183N/A output.stderrShouldContain(stderr);
4183N/A } catch (RuntimeException e) {
4183N/A throw new Exception("shouldContain() failed", e);
4183N/A }
4183N/A
4183N/A try {
4183N/A output.shouldContain("cccc");
4183N/A throw new Exception("shouldContain() failed to throw exception");
4183N/A } catch (RuntimeException e) {
4183N/A // expected
4183N/A }
4183N/A
4183N/A try {
4183N/A output.stdoutShouldContain(stderr);
4183N/A throw new Exception("stdoutShouldContain() failed to throw exception");
4183N/A } catch (RuntimeException e) {
4183N/A // expected
4183N/A }
4183N/A
4183N/A try {
4183N/A output.stderrShouldContain(stdout);
4183N/A throw new Exception("stdoutShouldContain() failed to throw exception");
4183N/A } catch (RuntimeException e) {
4183N/A // expected
4183N/A }
4183N/A
4183N/A try {
4183N/A output.shouldNotContain("cccc");
4183N/A output.stdoutShouldNotContain("cccc");
4183N/A output.stderrShouldNotContain("cccc");
4183N/A } catch (RuntimeException e) {
4183N/A throw new Exception("shouldNotContain() failed", e);
4183N/A }
4183N/A
4183N/A try {
4183N/A output.shouldNotContain(stdout);
4183N/A throw new Exception("shouldContain() failed to throw exception");
4183N/A } catch (RuntimeException e) {
4183N/A // expected
4183N/A }
4183N/A
4183N/A try {
4183N/A output.stdoutShouldNotContain(stdout);
4183N/A throw new Exception("shouldContain() failed to throw exception");
4183N/A } catch (RuntimeException e) {
4183N/A // expected
4183N/A }
4183N/A
4183N/A try {
4437N/A output.stderrShouldNotContain(stderr);
4437N/A throw new Exception("shouldContain() failed to throw exception");
4437N/A } catch (RuntimeException e) {
4437N/A // expected
4437N/A }
4437N/A
4437N/A // Should match
4437N/A try {
4437N/A output.shouldMatch(stdoutPattern);
4437N/A output.stdoutShouldMatch(stdoutPattern);
4437N/A output.shouldMatch(stderrPattern);
4437N/A output.stderrShouldMatch(stderrPattern);
4437N/A } catch (RuntimeException e) {
4437N/A throw new Exception("shouldMatch() failed", e);
4437N/A }
4437N/A
4437N/A try {
4437N/A output.shouldMatch(nonExistingPattern);
4437N/A throw new Exception("shouldMatch() failed to throw exception");
4437N/A } catch (RuntimeException e) {
4437N/A // expected
4437N/A }
4437N/A
4437N/A try {
4437N/A output.stdoutShouldMatch(stderrPattern);
4437N/A throw new Exception(
4437N/A "stdoutShouldMatch() failed to throw exception");
4183N/A } catch (RuntimeException e) {
4437N/A // expected
4437N/A }
4437N/A
4437N/A try {
4437N/A output.stderrShouldMatch(stdoutPattern);
4437N/A throw new Exception(
4437N/A "stderrShouldMatch() failed to throw exception");
4437N/A } catch (RuntimeException e) {
4437N/A // expected
4437N/A }
4437N/A
4437N/A // Should not match
4437N/A try {
4437N/A output.shouldNotMatch(nonExistingPattern);
4437N/A output.stdoutShouldNotMatch(nonExistingPattern);
4437N/A output.stderrShouldNotMatch(nonExistingPattern);
4437N/A } catch (RuntimeException e) {
4437N/A throw new Exception("shouldNotMatch() failed", e);
4437N/A }
4437N/A
4437N/A try {
4437N/A output.shouldNotMatch(stdoutPattern);
4437N/A throw new Exception("shouldNotMatch() failed to throw exception");
4437N/A } catch (RuntimeException e) {
4437N/A // expected
4437N/A }
4437N/A
4437N/A try {
4437N/A output.stdoutShouldNotMatch(stdoutPattern);
4437N/A throw new Exception("shouldNotMatch() failed to throw exception");
4437N/A } catch (RuntimeException e) {
4437N/A // expected
4437N/A }
4437N/A
4437N/A try {
4437N/A output.stderrShouldNotMatch(stderrPattern);
4437N/A throw new Exception("shouldNotMatch() failed to throw exception");
4437N/A } catch (RuntimeException e) {
4437N/A // expected
4183N/A }
4183N/A }
4183N/A}