001: /**
002: * AnagramsMBeanTest.java
003: *
004: * Created on Wed May 11 09:37:26 MEST 2005
005: */package com.toy.anagrams.mbeans;
006:
007: import junit.framework.*;
008: import javax.management.*;
009: import java.lang.management.ManagementFactory;
010: import javax.management.NotCompliantMBeanException;
011:
012: public class AnagramsMBeanTest extends TestCase {
013: public AnagramsMBeanTest(String testName) {
014: super (testName);
015: }
016:
017: /**
018: * Test of MaxThinkingTime Attribute
019: */
020: public void testMaxThinkingTimeAttribute() throws Exception {
021: System.out.println("testMaxThinkingTimeAttribute");
022:
023: // Get JMX MBean Attribute.
024: Integer val = (Integer) getAttribute("MaxThinkingTime");
025:
026: assertTrue("MaxThinkingTime is equals to 0", val == 0);
027: }
028:
029: /**
030: * Test of MinThinkingTime Attribute
031: */
032: public void testMinThinkingTimeAttribute() throws Exception {
033: System.out.println("testMinThinkingTimeAttribute");
034:
035: // Get JMX MBean Attribute.
036: Integer val = (Integer) getAttribute("MinThinkingTime");
037:
038: assertTrue("MinThinkingTime is equals to 0", val == 0);
039: }
040:
041: /**
042: * Test of CurrentAnagram Attribute
043: */
044: public void testCurrentAnagramAttribute() throws Exception {
045: System.out.println("testCurrentAnagramAttribute");
046:
047: // Get JMX MBean Attribute.
048: String val = (String) getAttribute("CurrentAnagram");
049:
050: assertTrue("CurrentAnagram is null", val == null);
051: }
052:
053: /**
054: * Test of resetThinkingTimes() Operation
055: */
056: public void testResetThinkingTimesOperation() throws Exception {
057: System.out.println("testresetThinkingTimesOperation");
058:
059: // Operation signature.
060: String[] signature = new String[] {};
061:
062: Object[] params = new Object[] {};
063:
064: // Invoke JMX MBean Operation.
065: Object val = (Object) invoke("resetThinkingTimes", params,
066: signature);
067:
068: assertTrue("reset returns value is void", val == null);
069: }
070:
071: public Object createMBean() throws NotCompliantMBeanException {
072: return new AnagramsStats();
073: }
074:
075: protected void setUp() throws Exception {
076: //JMX initialization
077: jmxInit();
078: //TODO add your own init code here
079: }
080:
081: protected void tearDown() throws Exception {
082: //JMX termination
083: jmxTerminate();
084: //TODO add your own terminate code here
085: }
086:
087: public static Test suite() {
088: TestSuite suite = new TestSuite(AnagramsMBeanTest.class);
089: return suite;
090: }
091:
092: /** JMX Initialization methods.
093: * WARNING: Do NOT modify this code.
094: */
095: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">
096: //GEN-BEGIN:generatedCode
097: private Object getAttribute(String attName) throws Exception {
098: return getMBeanServer().getAttribute(mbeanName, attName);
099: }
100:
101: private void setAttribute(Attribute att) throws Exception {
102: getMBeanServer().setAttribute(mbeanName, att);
103: }
104:
105: private Object invoke(String opName, Object params[],
106: String signature[]) throws Exception {
107: return getMBeanServer().invoke(mbeanName, opName, params,
108: signature);
109: }
110:
111: private void jmxInit() throws Exception {
112: mbeanName = new ObjectName(":type=AnagramsMBean");
113: Object mbean = createMBean();
114: server = ManagementFactory.getPlatformMBeanServer();
115: server.registerMBean(mbean, mbeanName);
116: }
117:
118: private void jmxTerminate() throws Exception {
119: server.unregisterMBean(mbeanName);
120: }
121:
122: private MBeanServer getMBeanServer() {
123: return server;
124: }
125:
126: private MBeanServer server;
127: private ObjectName mbeanName;
128: // </editor-fold>
129: //GEN-END:generatedCode
130: }
|