KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > msg > JMXMessageTest


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
3  */

4 package com.tc.object.msg;
5
6 import com.tc.io.TCByteBufferOutputStream;
7 import com.tc.net.protocol.tcm.NullMessageMonitor;
8 import com.tc.net.protocol.tcm.TCMessageHeader;
9 import com.tc.net.protocol.tcm.TCMessageType;
10 import com.tc.object.session.SessionID;
11 import com.tc.test.TCTestCase;
12 import com.tc.util.NonPortableReason;
13
14 public class JMXMessageTest extends TCTestCase {
15
16   private NonPortableReason createReason(byte b) {
17     NonPortableReason reason = new NonPortableReason(JMXMessage.class, b);
18     return reason;
19   }
20
21   public void testMessage() throws Exception JavaDoc {
22     NonPortableReason reason = createReason(NonPortableReason.CLASS_NOT_ADAPTABLE);
23     reason.setMessage(" Hello there\n");
24     createMessageAndTest(reason);
25
26     reason = createReason(NonPortableReason.SUPER_CLASS_NOT_ADAPTABLE);
27     reason.addErroneousSuperClass(TCTestCase.class);
28     createMessageAndTest(reason);
29
30     reason = createReason(NonPortableReason.CLASS_NOT_IN_BOOT_JAR);
31     createMessageAndTest(reason);
32
33     reason = createReason(NonPortableReason.SUPER_CLASS_NOT_INSTRUMENTED);
34     reason.addErroneousSuperClass(Object JavaDoc.class);
35     createMessageAndTest(reason);
36
37     reason = createReason(NonPortableReason.SUPER_CLASS_NOT_INSTRUMENTED);
38     reason.addErroneousSuperClass(getClass());
39     createMessageAndTest(reason);
40
41     reason = createReason(NonPortableReason.SUPER_CLASS_NOT_INSTRUMENTED);
42     reason.addErroneousSuperClass(Object JavaDoc.class);
43     reason.addErroneousSuperClass(getClass());
44     createMessageAndTest(reason);
45
46     reason = createReason(NonPortableReason.SUBCLASS_OF_LOGICALLY_MANAGED_CLASS);
47     reason.addErroneousSuperClass(getClass());
48     createMessageAndTest(reason);
49
50     reason = createReason(NonPortableReason.CLASS_NOT_INCLUDED_IN_CONFIG);
51     createMessageAndTest(reason);
52   }
53
54   private void createMessageAndTest(NonPortableReason reason) throws Exception JavaDoc {
55
56     JMXMessage msg = new JMXMessage(new NullMessageMonitor(), new TCByteBufferOutputStream(4, 4096, false), null,
57                                     TCMessageType.JMX_MESSAGE);
58     msg.setJMXObject(reason);
59     msg.dehydrate();
60     JMXMessage msg2 = new JMXMessage(SessionID.NULL_ID, new NullMessageMonitor(), null, (TCMessageHeader) msg
61         .getHeader(), msg.getPayload());
62     msg2.hydrate();
63     assertNonPortableReasonEquals(msg.getJMXObject(), msg2.getJMXObject());
64   }
65
66   private void assertNonPortableReasonEquals(Object JavaDoc object, Object JavaDoc object2) {
67     assertTrue(object instanceof NonPortableReason);
68     assertTrue(object2 instanceof NonPortableReason);
69     NonPortableReason npr1 = (NonPortableReason) object;
70     NonPortableReason npr2 = (NonPortableReason) object2;
71     assertEquals(npr1.getClassName(), npr2.getClassName());
72     assertEquals(npr1.getErroneousSuperClasses(), npr2.getErroneousSuperClasses());
73     assertEquals(npr1.getReason(), npr2.getReason());
74     assertEquals(npr1.getMessage(), npr2.getMessage());
75     assertEquals(npr1.getDetailedReason(), npr2.getDetailedReason());
76     System.out.println(npr1.getDetailedReason() + "\n");
77   }
78
79 }
80
Popular Tags