01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright notice. All rights reserved.
03: */
04: package com.tc.object.msg;
05:
06: import com.tc.io.TCByteBufferOutputStream;
07: import com.tc.net.protocol.tcm.NullMessageMonitor;
08: import com.tc.net.protocol.tcm.TCMessageHeader;
09: 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(
18: JMXMessage.class, b);
19: return reason;
20: }
21:
22: public void testMessage() throws Exception {
23: NonPortableReason reason = createReason(NonPortableReason.CLASS_NOT_ADAPTABLE);
24: reason.setMessage(" Hello there\n");
25: createMessageAndTest(reason);
26:
27: reason = createReason(NonPortableReason.SUPER_CLASS_NOT_ADAPTABLE);
28: reason.addErroneousSuperClass(TCTestCase.class);
29: createMessageAndTest(reason);
30:
31: reason = createReason(NonPortableReason.CLASS_NOT_IN_BOOT_JAR);
32: createMessageAndTest(reason);
33:
34: reason = createReason(NonPortableReason.SUPER_CLASS_NOT_INSTRUMENTED);
35: reason.addErroneousSuperClass(Object.class);
36: createMessageAndTest(reason);
37:
38: reason = createReason(NonPortableReason.SUPER_CLASS_NOT_INSTRUMENTED);
39: reason.addErroneousSuperClass(getClass());
40: createMessageAndTest(reason);
41:
42: reason = createReason(NonPortableReason.SUPER_CLASS_NOT_INSTRUMENTED);
43: reason.addErroneousSuperClass(Object.class);
44: reason.addErroneousSuperClass(getClass());
45: createMessageAndTest(reason);
46:
47: reason = createReason(NonPortableReason.SUBCLASS_OF_LOGICALLY_MANAGED_CLASS);
48: reason.addErroneousSuperClass(getClass());
49: createMessageAndTest(reason);
50:
51: reason = createReason(NonPortableReason.CLASS_NOT_INCLUDED_IN_CONFIG);
52: createMessageAndTest(reason);
53: }
54:
55: private void createMessageAndTest(NonPortableReason reason)
56: throws Exception {
57:
58: JMXMessage msg = new JMXMessage(new SessionID(0),
59: new NullMessageMonitor(), new TCByteBufferOutputStream(
60: 4, 4096, false), null,
61: TCMessageType.JMX_MESSAGE);
62: msg.setJMXObject(reason);
63: msg.dehydrate();
64: JMXMessage msg2 = new JMXMessage(SessionID.NULL_ID,
65: new NullMessageMonitor(), null, (TCMessageHeader) msg
66: .getHeader(), msg.getPayload());
67: msg2.hydrate();
68: assertNonPortableReasonEquals(msg.getJMXObject(), msg2
69: .getJMXObject());
70: }
71:
72: private void assertNonPortableReasonEquals(Object object,
73: Object object2) {
74: assertTrue(object instanceof NonPortableReason);
75: assertTrue(object2 instanceof NonPortableReason);
76: NonPortableReason npr1 = (NonPortableReason) object;
77: NonPortableReason npr2 = (NonPortableReason) object2;
78: assertEquals(npr1.getClassName(), npr2.getClassName());
79: assertEquals(npr1.getErroneousSuperClasses(), npr2
80: .getErroneousSuperClasses());
81: assertEquals(npr1.getReason(), npr2.getReason());
82: assertEquals(npr1.getMessage(), npr2.getMessage());
83: assertEquals(npr1.getDetailedReason(), npr2.getDetailedReason());
84: System.out.println(npr1.getDetailedReason() + "\n");
85: }
86:
87: }
|