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.rss;
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 com.sun.syndication.feed.synd.SyndFeed;
18  
19  import java.io.InputStream;
20  
21  import edu.emory.mathcs.backport.java.util.concurrent.TimeUnit;
22  import org.junit.Test;
23  
24  import static org.junit.Assert.assertEquals;
25  import static org.junit.Assert.assertTrue;
26  
27  public class RssFeedConsumeAndTransformTestCase 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 "rss-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 = SampleFeed.feedAsStream();
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 SyndFeed);
65  
66          SyndFeed feed = (SyndFeed) payload;
67          assertEquals(25, feed.getEntries().size());
68      }
69  }