1
2
3
4
5
6
7 package org.mule.module.xml.functional;
8
9 import org.mule.api.MuleEventContext;
10 import org.mule.module.client.MuleClient;
11 import org.mule.tck.functional.EventCallback;
12 import org.mule.tck.functional.FunctionalTestComponent;
13 import org.mule.tck.junit4.FunctionalTestCase;
14
15 import com.thoughtworks.xstream.converters.extended.ISO8601DateConverter;
16
17 import java.util.Date;
18
19 import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
20 import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
21 import org.junit.Test;
22
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25
26 public class XStreamAdditionalConvertersTestCase extends FunctionalTestCase
27 {
28 private CountDownLatch latch = new CountDownLatch(1);
29
30 @Override
31 protected void doSetUp() throws Exception
32 {
33 super.doSetUp();
34
35 FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent("ObjectToXml");
36 assertNotNull(testComponent);
37 testComponent.setEventCallback(new Callback(latch));
38 }
39
40 @Override
41 protected String getConfigResources()
42 {
43 return "org/mule/module/xml/xstream-additional-converters.xml";
44 }
45
46 @Test
47 public void testAdditionalConverters() throws Exception
48 {
49 ISO8601DateConverter converter = new ISO8601DateConverter();
50 String timestamp = converter.toString(new Date(System.currentTimeMillis()));
51 String input = "<test-bean><createDate>" + timestamp + "</createDate></test-bean>";
52
53 MuleClient client = new MuleClient(muleContext);
54 client.dispatch("vm://FromTest", input, null);
55
56 assertTrue(latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
57 }
58
59 private static class Callback implements EventCallback
60 {
61 private CountDownLatch testLatch;
62
63 public Callback(CountDownLatch latch)
64 {
65 testLatch = latch;
66 }
67
68 public void eventReceived(MuleEventContext context, Object component) throws Exception
69 {
70 Object payload = context.getMessage().getPayload();
71 assertTrue(payload instanceof TestBean);
72 assertNotNull(((TestBean) payload).getCreateDate());
73
74 testLatch.countDown();
75 }
76 }
77
78 public static class TestBean
79 {
80 private Date createDate = null;
81
82 public Date getCreateDate()
83 {
84 return createDate;
85 }
86
87 public void setCreateDate(Date createDate)
88 {
89 this.createDate = createDate;
90 }
91 }
92 }
93
94