View Javadoc

1   /*
2    * $Id: NamespaceTestCase.java 20321 2010-11-24 15:21:24Z dfeist $
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  package org.mule.module.rss;
11  
12  import org.mule.api.endpoint.InboundEndpoint;
13  import org.mule.api.processor.MessageProcessor;
14  import org.mule.api.service.Service;
15  import org.mule.construct.SimpleFlowConstruct;
16  import org.mule.module.rss.endpoint.RssInboundEndpoint;
17  import org.mule.module.rss.routing.EntryLastUpdatedFilter;
18  import org.mule.module.rss.routing.FeedLastUpdatedFilter;
19  import org.mule.module.rss.routing.FeedSplitter;
20  import org.mule.routing.MessageFilter;
21  import org.mule.service.ServiceCompositeMessageSource;
22  import org.mule.tck.FunctionalTestCase;
23  
24  import java.text.SimpleDateFormat;
25  
26  public class NamespaceTestCase extends FunctionalTestCase
27  {
28      protected String getConfigResources()
29      {
30          return "namespace-config.xml";
31      }
32  
33      public void testEndpointConfig() throws Exception
34      {
35          Service service = muleContext.getRegistry().lookupService("test");
36          assertNotNull(service);
37          assertTrue(((ServiceCompositeMessageSource) service.getMessageSource()).getEndpoints().get(0) instanceof RssInboundEndpoint);
38          RssInboundEndpoint ep = (RssInboundEndpoint) ((ServiceCompositeMessageSource) service.getMessageSource()).getEndpoints().get(0);
39          assertEquals(FeedSplitter.class, ep.getMessageProcessors().get(0).getClass());
40          assertNotNull(ep.getLastUpdate());
41          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
42  
43          assertEquals(sdf.parse("2009-10-01"), ep.getLastUpdate());
44      }
45  
46      public void testFlowConfig() throws Exception
47      {
48          SimpleFlowConstruct flowConstruct = muleContext.getRegistry().lookupObject("flowTest");
49          assertNotNull(flowConstruct);
50          assertTrue(flowConstruct.getMessageSource() instanceof InboundEndpoint);
51          InboundEndpoint ep = ((InboundEndpoint)flowConstruct.getMessageSource());
52          assertEquals(2, ep.getMessageProcessors().size());
53          MessageProcessor mp = ep.getMessageProcessors().get(0);
54          assertTrue(mp instanceof FeedSplitter);
55          mp = ep.getMessageProcessors().get(1);
56          assertTrue(mp instanceof MessageFilter);
57  
58          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
59  
60          assertEquals(sdf.parse("2009-10-01"), ((EntryLastUpdatedFilter)((MessageFilter)mp).getFilter()).getLastUpdate());
61      }
62  
63      public void testGlobalFilterConfig() throws Exception {
64          FeedLastUpdatedFilter filter = muleContext.getRegistry().lookupObject("feedFilter");
65          assertNotNull(filter);
66  
67          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
68  
69          assertEquals(sdf.parse("2009-10-01 13:00:00"), filter.getLastUpdate());
70          assertFalse(filter.isAcceptWithoutUpdateDate());
71  
72      }
73  }