|
| 1 | +/* |
| 2 | + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
| 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. Oracle designates this |
| 8 | + * particular file as subject to the "Classpath" exception as provided |
| 9 | + * by Oracle in the LICENSE file that accompanied this code. |
| 10 | + * |
| 11 | + * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | + * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | + * accompanied this code). |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU General Public License version |
| 18 | + * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | + * |
| 21 | + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| 22 | + * or visit www.oracle.com if you need additional information or have any |
| 23 | + * questions. |
| 24 | + */ |
| 25 | + |
| 26 | +package com.sun.btrace; |
| 27 | + |
| 28 | +import org.junit.Assert; |
| 29 | +import org.junit.Before; |
| 30 | +import support.RuntimeTest; |
| 31 | +import org.junit.BeforeClass; |
| 32 | +import org.junit.Test; |
| 33 | + |
| 34 | +/** |
| 35 | + * A set of end-to-end functional tests. |
| 36 | + * <p> |
| 37 | + * The test simulates a user submitting a BTrace script to the target application |
| 38 | + * and asserts that no exceptions are thrown, JVM keeps on running and |
| 39 | + * BTrace generates the anticipated output. |
| 40 | + * |
| 41 | + * @author Jaroslav Bachorik |
| 42 | + */ |
| 43 | +public class BTraceFunctionalTests extends RuntimeTest { |
| 44 | + @BeforeClass |
| 45 | + public static void classSetup() { |
| 46 | + RuntimeTest.setup(); |
| 47 | + } |
| 48 | + |
| 49 | + @Before |
| 50 | + @Override |
| 51 | + public void reset() { |
| 52 | + super.reset(); |
| 53 | + } |
| 54 | + |
| 55 | + @Test |
| 56 | + public void testOSMBean() throws Exception { |
| 57 | + isUnsafe = true; |
| 58 | + test( |
| 59 | + "resources.Main", |
| 60 | + "traces/OSMBeanTest.java", |
| 61 | + 2, |
| 62 | + new ResultValidator() { |
| 63 | + public void validate(String stdout, String stderr, int retcode) { |
| 64 | + Assert.assertFalse("Script should not have failed", stdout.contains("FAILED")); |
| 65 | + Assert.assertTrue("Non-empty stderr", stderr.isEmpty()); |
| 66 | + Assert.assertEquals("Unexpected return code", 0, retcode); |
| 67 | + } |
| 68 | + } |
| 69 | + ); |
| 70 | + } |
| 71 | + |
| 72 | + @Test |
| 73 | + public void testOnProbe() throws Exception { |
| 74 | + test( |
| 75 | + "resources.Main", |
| 76 | + "traces/ProbeTest.java", |
| 77 | + 5, |
| 78 | + new ResultValidator() { |
| 79 | + public void validate(String stdout, String stderr, int retcode) { |
| 80 | + Assert.assertFalse("Script should not have failed", stdout.contains("FAILED")); |
| 81 | + Assert.assertTrue("Non-empty stderr", stderr.isEmpty()); |
| 82 | + Assert.assertTrue(stdout.contains("[this, noargs]")); |
| 83 | + Assert.assertTrue(stdout.contains("[this, args]")); |
| 84 | + Assert.assertEquals("Unexpected return code", 0, retcode); |
| 85 | + } |
| 86 | + } |
| 87 | + ); |
| 88 | + } |
| 89 | + |
| 90 | + @Test |
| 91 | + public void testOnMethod() throws Exception { |
| 92 | + test( |
| 93 | + "resources.Main", |
| 94 | + "traces/OnMethodTest.java", |
| 95 | + 5, |
| 96 | + new ResultValidator() { |
| 97 | + public void validate(String stdout, String stderr, int retcode) { |
| 98 | + Assert.assertFalse("Script should not have failed", stdout.contains("FAILED")); |
| 99 | + Assert.assertTrue("Non-empty stderr", stderr.isEmpty()); |
| 100 | + Assert.assertTrue(stdout.contains("[this, noargs]")); |
| 101 | + Assert.assertTrue(stdout.contains("[this, args]")); |
| 102 | + Assert.assertEquals("Unexpected return code", 0, retcode); |
| 103 | + } |
| 104 | + } |
| 105 | + ); |
| 106 | + } |
| 107 | +} |
0 commit comments