1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
package org.mule.tck.providers; |
12 | |
|
13 | |
import org.mule.impl.RequestContext; |
14 | |
import org.mule.tck.AbstractMuleTestCase; |
15 | |
import org.mule.umo.MessagingException; |
16 | |
import org.mule.umo.provider.MessageTypeNotSupportedException; |
17 | |
import org.mule.umo.provider.UMOMessageAdapter; |
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | 0 | public abstract class AbstractMessageAdapterTestCase extends AbstractMuleTestCase |
23 | |
{ |
24 | |
protected void doSetUp() throws Exception |
25 | |
{ |
26 | 0 | RequestContext.setEvent(getTestEvent("hello")); |
27 | 0 | } |
28 | |
|
29 | |
protected void doTearDown() throws Exception |
30 | |
{ |
31 | 0 | RequestContext.clear(); |
32 | 0 | } |
33 | |
|
34 | |
protected void doTestMessageEqualsPayload(Object message, Object payload) throws Exception |
35 | |
{ |
36 | 0 | assertEquals(message, payload); |
37 | 0 | } |
38 | |
|
39 | |
public void testMessageRetrieval() throws Exception |
40 | |
{ |
41 | 0 | Object message = getValidMessage(); |
42 | 0 | UMOMessageAdapter adapter = createAdapter(message); |
43 | |
|
44 | 0 | doTestMessageEqualsPayload(message, adapter.getPayload()); |
45 | |
|
46 | 0 | byte[] bytes = adapter.getPayloadAsBytes(); |
47 | 0 | assertNotNull(bytes); |
48 | |
|
49 | 0 | String stringMessage = adapter.getPayloadAsString(); |
50 | 0 | assertNotNull(stringMessage); |
51 | |
|
52 | 0 | assertNotNull(adapter.getPayload()); |
53 | |
|
54 | |
try |
55 | |
{ |
56 | 0 | adapter = createAdapter(getInvalidMessage()); |
57 | 0 | fail("Message adapter should throw MessageTypeNotSupportedException if an invalid message is set"); |
58 | |
} |
59 | 0 | catch (MessageTypeNotSupportedException e) |
60 | |
{ |
61 | |
|
62 | 0 | } |
63 | 0 | } |
64 | |
|
65 | |
public void testMessageProps() throws Exception |
66 | |
{ |
67 | 0 | UMOMessageAdapter adapter = createAdapter(getValidMessage()); |
68 | |
|
69 | 0 | adapter.setProperty("TestString", "Test1"); |
70 | 0 | adapter.setProperty("TestLong", new Long(20000000)); |
71 | 0 | adapter.setProperty("TestInt", new Integer(200000)); |
72 | 0 | assertNotNull(adapter.getPropertyNames()); |
73 | |
|
74 | 0 | Object prop = adapter.getProperty("TestString"); |
75 | 0 | assertNotNull(prop); |
76 | 0 | assertEquals("Test1", prop); |
77 | |
|
78 | 0 | prop = adapter.getProperty("TestLong"); |
79 | 0 | assertNotNull(prop); |
80 | 0 | assertEquals(new Long(20000000), prop); |
81 | |
|
82 | 0 | prop = adapter.getProperty("TestInt"); |
83 | 0 | assertNotNull(prop); |
84 | 0 | assertEquals(new Integer(200000), prop); |
85 | 0 | } |
86 | |
|
87 | |
public Object getInvalidMessage() |
88 | |
{ |
89 | 0 | return new InvalidMessage(); |
90 | |
} |
91 | |
|
92 | |
public abstract Object getValidMessage() throws Exception; |
93 | |
|
94 | |
public abstract UMOMessageAdapter createAdapter(Object payload) throws MessagingException; |
95 | |
|
96 | 0 | final class InvalidMessage |
97 | |
{ |
98 | |
public String toString() |
99 | |
{ |
100 | 0 | return "invalid message"; |
101 | |
} |
102 | |
} |
103 | |
|
104 | |
} |