/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6317101
* @summary Test that the jmx.invoke.getters system property works
* @author Eamonn McManus
* @run clean InvokeGettersTest
* @run build InvokeGettersTest
* @run main InvokeGettersTest
*/
import javax.management.*;
public class InvokeGettersTest {
public static interface ThingMBean {
public int getWhatsit();
public void setWhatsit(int x);
public boolean isTrue();
}
public int getWhatsit() {
return whatsit;
}
public void setWhatsit(int x) {
whatsit = x;
}
public boolean isTrue() {
return true;
}
private int whatsit;
}
else
}
boolean shouldWork) throws Exception {
++x;
if (got != x)
++x;
try {
if (!shouldWork)
return fail("invoke setWhatsit worked but should not have");
} catch (ReflectionException e) {
if (shouldWork)
return fail("invoke setWhatsit did not work but should have");
}
try {
if (!shouldWork)
return fail("invoke getWhatsit worked but should not have");
if (got != x)
} catch (ReflectionException e) {
if (shouldWork)
return fail("invoke getWhatsit did not work but should have");
}
try {
if (!shouldWork)
return fail("invoke isTrue worked but should not have");
if (!t)
return fail("isTrue returned false");
} catch (ReflectionException e) {
if (shouldWork)
return fail("invoke isTrue did not work but should have");
else
}
// Following cases should fail whether or not jmx.invoke.getters is set
final Object[][] badInvokes = {
};
boolean ok = true;
try {
} catch (ReflectionException e) {
if (e.getCause() instanceof NoSuchMethodException)
else {
"exception: " + e.getCause());
}
}
}
return ok;
}
return false;
}
private static int x;
}