View Javadoc

1   /*
2    * $Id: AtomFeedConsumeAndTransformTestCase.java 22401 2011-07-13 09:10:18Z dirk.olmes $
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.atom;
12  
13  import org.mule.api.MuleEventContext;
14  import org.mule.api.MuleMessage;
15  import org.mule.api.client.MuleClient;
16  import org.mule.tck.functional.EventCallback;
17  import org.mule.tck.functional.FunctionalTestComponent;
18  import org.mule.tck.junit4.FunctionalTestCase;
19  import org.mule.util.concurrent.Latch;
20  
21  import java.io.InputStream;
22  import java.util.concurrent.TimeUnit;
23  
24  import org.apache.abdera.model.Feed;
25  import org.junit.Test;
26  
27  import static org.junit.Assert.assertEquals;
28  import static org.junit.Assert.assertNotNull;
29  import static org.junit.Assert.assertTrue;
30  
31  public class AtomFeedConsumeAndTransformTestCase extends FunctionalTestCase
32  {
33      private Latch receiveLatch = new Latch();
34      private MuleMessage message = null;
35  
36      @Override
37      protected String getConfigResources()
38      {
39          return "atom-consume-transform-feed.xml";
40      }
41  
42      @Override
43      protected void doSetUp() throws Exception
44      {
45          FunctionalTestComponent comp = (FunctionalTestComponent)getComponent("feedTransformer");
46          comp.setEventCallback(new EventCallback()
47          {
48              @Override
49              public void eventReceived(MuleEventContext context, Object component) throws Exception
50              {
51                  message = context.getMessage();
52                  receiveLatch.countDown();
53              }
54          });
55      }
56  
57      @Test
58      public void testSendFeed() throws Exception
59      {
60          InputStream input = getFeedInput();
61  
62          MuleClient client = muleContext.getClient();
63          client.dispatch("vm://fromTest", input, null);
64  
65          assertTrue(receiveLatch.await(RECEIVE_TIMEOUT, TimeUnit.MILLISECONDS));
66  
67          Object payload = message.getPayload();
68          assertTrue(payload instanceof Feed);
69  
70          Feed feed = (Feed) payload;
71          assertEquals(25, feed.getEntries().size());
72      }
73  
74      private InputStream getFeedInput()
75      {
76          InputStream input = getClass().getClassLoader().getResourceAsStream("sample-feed.atom");
77          assertNotNull(input);
78          return input;
79      }
80  }