View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.atom;
8   
9   import org.mule.api.MuleEventContext;
10  import org.mule.api.MuleMessage;
11  import org.mule.api.client.MuleClient;
12  import org.mule.tck.functional.EventCallback;
13  import org.mule.tck.functional.FunctionalTestComponent;
14  import org.mule.tck.junit4.FunctionalTestCase;
15  import org.mule.util.concurrent.Latch;
16  
17  import java.io.InputStream;
18  
19  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
20  import org.apache.abdera.model.Feed;
21  import org.junit.Test;
22  
23  import static org.junit.Assert.assertEquals;
24  import static org.junit.Assert.assertNotNull;
25  import static org.junit.Assert.assertTrue;
26  
27  public class AtomFeedConsumeAndTransformTestCase extends FunctionalTestCase
28  {
29  
30      private Latch receiveLatch = new Latch();
31      private MuleMessage message = null;
32  
33      @Override
34      protected String getConfigResources()
35      {
36          return "atom-consume-transform-feed.xml";
37      }
38  
39      @Override
40      protected void doSetUp() throws Exception
41      {
42          FunctionalTestComponent comp = (FunctionalTestComponent)getComponent("feedTransformer");
43          comp.setEventCallback(new EventCallback()
44          {
45              public void eventReceived(MuleEventContext context, Object component) throws Exception
46              {
47                  message = context.getMessage();
48                  receiveLatch.countDown();
49              }
50          });
51      }
52      
53      @Test
54      public void testSendFeed() throws Exception
55      {
56          InputStream input = getFeedInput();
57          
58          MuleClient client = muleContext.getClient();
59          client.dispatch("vm://fromTest", input, null);
60          
61          assertTrue(receiveLatch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
62          
63          Object payload = message.getPayload();
64          assertTrue(payload instanceof Feed);
65  
66          Feed feed = (Feed) payload;
67          assertEquals(25, feed.getEntries().size());
68      }
69      
70      private InputStream getFeedInput()
71      {
72          InputStream input = getClass().getClassLoader().getResourceAsStream("sample-feed.atom");
73          assertNotNull(input);
74          return input;
75      }
76  }