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