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