View Javadoc

1   /*
2    * $Id: XStreamAdditionalConvertersTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
5    *
6    * The software in this package is published under the terms of the CPAL v1.0
7    * license, a copy of which has been included with this distribution in the
8    * LICENSE.txt file.
9    */
10  
11  package org.mule.module.xml.functional;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.module.client.MuleClient;
15  import org.mule.tck.FunctionalTestCase;
16  import org.mule.tck.functional.EventCallback;
17  import org.mule.tck.functional.FunctionalTestComponent;
18  
19  import java.util.Date;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.CountDownLatch;
22  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
23  
24  public class XStreamAdditionalConvertersTestCase extends FunctionalTestCase
25  {
26      private CountDownLatch latch = new CountDownLatch(1);
27      
28      @Override
29      protected void doSetUp() throws Exception
30      {
31          super.doSetUp();
32  
33          FunctionalTestComponent testComponent = (FunctionalTestComponent) getComponent("ObjectToXml");
34          assertNotNull(testComponent);
35          testComponent.setEventCallback(new Callback(latch));
36      }
37  
38      @Override
39      protected String getConfigResources()
40      {
41          return "org/mule/module/xml/xstream-additional-converters.xml";
42      }
43  
44      public void testAdditionalConverters() throws Exception
45      {
46          String input = "<test-bean><createDate>2009-05-19T07:40:00</createDate></test-bean>";
47          
48          MuleClient client = new MuleClient(muleContext);
49          client.dispatch("vm://FromTest", input, null);
50          
51          assertTrue(latch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
52      }
53          
54      private static class Callback implements EventCallback
55      {
56          private CountDownLatch testLatch;
57  
58          public Callback(CountDownLatch latch)
59          {
60              testLatch = latch;
61          }
62  
63          public void eventReceived(MuleEventContext context, Object component) throws Exception
64          {
65              Object payload = context.getMessage().getPayload();
66              assertTrue(payload instanceof TestBean);
67              assertNotNull(((TestBean) payload).getCreateDate());
68              
69              testLatch.countDown();
70          }
71      }
72  
73      public static class TestBean
74      {
75          private Date createDate = null;
76  
77          public Date getCreateDate()
78          {
79              return createDate;
80          }
81  
82          public void setCreateDate(Date createDate)
83          {
84              this.createDate = createDate;
85          }
86      }
87  }
88  
89