< prev index next >

test/jdk/lib/testlibrary/OutputAnalyzerTest.java

Print this page
rev 51638 : [mq]: 8210112
rev 51639 : [mq]: 8210112-1


   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 package jdk.testlibrary;
  24 
  25 /*
  26  * @test
  27  * @summary Test the OutputAnalyzer utility class
  28  * @modules java.management
  29  * @build jdk.testlibrary.*
  30  * @run main jdk.testlibrary.OutputAnalyzerTest
  31  */
  32 


  33 public class OutputAnalyzerTest {
  34 
  35     public static void main(String args[]) throws Exception {
  36 
  37         String stdout = "aaaaaa";
  38         String stderr = "bbbbbb";
  39         String nonExistingString = "cccc";
  40 
  41         OutputAnalyzer output = new OutputAnalyzer(stdout, stderr);
  42 
  43         if (!stdout.equals(output.getStdout())) {
  44             throw new Exception("getStdout() returned '" + output.getStdout()
  45                     + "', expected '" + stdout + "'");
  46         }
  47 
  48         if (!stderr.equals(output.getStderr())) {
  49             throw new Exception("getStderr() returned '" + output.getStderr()
  50                     + "', expected '" + stderr + "'");
  51         }
  52 


 133         } catch (RuntimeException e) {
 134             // expected
 135         }
 136 
 137         try {
 138             output.stdoutShouldMatch(stderrPattern);
 139             throw new Exception(
 140                     "stdoutShouldMatch() failed to throw exception");
 141         } catch (RuntimeException e) {
 142             // expected
 143         }
 144 
 145         try {
 146             output.stderrShouldMatch(stdoutPattern);
 147             throw new Exception(
 148                     "stderrShouldMatch() failed to throw exception");
 149         } catch (RuntimeException e) {
 150             // expected
 151         }
 152 
 153         if (output.shouldMatchByLine(byLinePattern) != 1) {
 154             throw new Exception("shouldMatchByLine() should find one line");


 155         }

 156         try {
 157             output.shouldMatchByLine(nonExistingPattern);
 158             throw new Exception("shouldMatchByLine() failed to throw exception");
 159         } catch (RuntimeException e) {
 160             // expected
 161         }
 162         if (output.stdoutShouldMatchByLine(stdoutByLinePattern) != 1) {
 163             throw new Exception("stdoutShouldMatchByLine() should find one line");



 164         }
 165 
 166         // Should not match
 167         try {
 168             output.shouldNotMatch(nonExistingPattern);
 169             output.stdoutShouldNotMatch(nonExistingPattern);
 170             output.stderrShouldNotMatch(nonExistingPattern);
 171         } catch (RuntimeException e) {
 172             throw new Exception("shouldNotMatch() failed", e);
 173         }
 174 
 175         try {
 176             output.shouldNotMatch(stdoutPattern);
 177             throw new Exception("shouldNotMatch() failed to throw exception");
 178         } catch (RuntimeException e) {
 179             // expected
 180         }
 181 
 182         try {
 183             output.stdoutShouldNotMatch(stdoutPattern);


   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */

  23 
  24 /*
  25  * @test
  26  * @summary Test the OutputAnalyzer utility class
  27  * @modules java.management
  28  * @library /test/lib
  29  * @run main OutputAnalyzerTest
  30  */
  31 
  32 import jdk.test.lib.process.OutputAnalyzer;
  33 
  34 public class OutputAnalyzerTest {
  35 
  36     public static void main(String args[]) throws Exception {
  37 
  38         String stdout = "aaaaaa";
  39         String stderr = "bbbbbb";
  40         String nonExistingString = "cccc";
  41 
  42         OutputAnalyzer output = new OutputAnalyzer(stdout, stderr);
  43 
  44         if (!stdout.equals(output.getStdout())) {
  45             throw new Exception("getStdout() returned '" + output.getStdout()
  46                     + "', expected '" + stdout + "'");
  47         }
  48 
  49         if (!stderr.equals(output.getStderr())) {
  50             throw new Exception("getStderr() returned '" + output.getStderr()
  51                     + "', expected '" + stderr + "'");
  52         }
  53 


 134         } catch (RuntimeException e) {
 135             // expected
 136         }
 137 
 138         try {
 139             output.stdoutShouldMatch(stderrPattern);
 140             throw new Exception(
 141                     "stdoutShouldMatch() failed to throw exception");
 142         } catch (RuntimeException e) {
 143             // expected
 144         }
 145 
 146         try {
 147             output.stderrShouldMatch(stdoutPattern);
 148             throw new Exception(
 149                     "stderrShouldMatch() failed to throw exception");
 150         } catch (RuntimeException e) {
 151             // expected
 152         }
 153 
 154         try {
 155             output.shouldMatchByLine(byLinePattern);
 156         } catch (RuntimeException e) {
 157             throw new Exception("shouldMatchByLine() failed", e);
 158         }
 159 
 160         try {
 161             output.shouldMatchByLine(nonExistingPattern);
 162             throw new Exception("shouldMatchByLine() failed to throw exception");
 163         } catch (RuntimeException e) {
 164             // expected
 165         }
 166 
 167         try {
 168             output.stdoutShouldMatchByLine(stdoutByLinePattern);
 169         } catch (RuntimeException e) {
 170             throw new Exception("stdoutShouldMatchByLine() failed", e);
 171         }
 172 
 173         // Should not match
 174         try {
 175             output.shouldNotMatch(nonExistingPattern);
 176             output.stdoutShouldNotMatch(nonExistingPattern);
 177             output.stderrShouldNotMatch(nonExistingPattern);
 178         } catch (RuntimeException e) {
 179             throw new Exception("shouldNotMatch() failed", e);
 180         }
 181 
 182         try {
 183             output.shouldNotMatch(stdoutPattern);
 184             throw new Exception("shouldNotMatch() failed to throw exception");
 185         } catch (RuntimeException e) {
 186             // expected
 187         }
 188 
 189         try {
 190             output.stdoutShouldNotMatch(stdoutPattern);
< prev index next >