1
2
3
4
5
6
7 package org.mule.module.rss;
8
9 import org.mule.tck.junit4.FunctionalTestCase;
10 import org.mule.tck.probe.PollingProber;
11 import org.mule.tck.probe.Probe;
12 import org.mule.tck.probe.Prober;
13
14 import java.io.File;
15 import java.io.FileOutputStream;
16 import java.io.IOException;
17
18 import org.junit.Test;
19
20 import static org.mule.module.rss.SampleFeed.ENTRIES_IN_RSS_FEED;
21
22 public class FileRssFeedConsumeTestCase extends FunctionalTestCase
23 {
24
25 @Override
26 protected String getConfigResources()
27 {
28 return "file-rss-consume.xml";
29 }
30
31 @Test
32 public void testConsumeFeedEntries() throws Exception
33 {
34 createSampleFeedFileInWorkDirectory();
35
36 final EntryReceiver component = (EntryReceiver) getComponent("feedSplitterConsumer");
37 Prober prober = new PollingProber(10000, 100);
38 prober.check(new Probe()
39 {
40 public boolean isSatisfied()
41 {
42 return component.getCount() == SampleFeed.ENTRIES_IN_RSS_FEED;
43 }
44
45 public String describeFailure()
46 {
47 return String.format("Did not receive %d feed entries (only got %d)",
48 ENTRIES_IN_RSS_FEED, component.getCount());
49 }
50 });
51 }
52
53 private void createSampleFeedFileInWorkDirectory() throws IOException
54 {
55 String workDirectory = muleContext.getConfiguration().getWorkingDirectory();
56 FileOutputStream fos = new FileOutputStream(new File(workDirectory, "sample-feed.rss"));
57 String feed = SampleFeed.feedAsString();
58 fos.write(feed.getBytes());
59 fos.close();
60 }
61
62 }