View Javadoc

1   /*
2    * $Id: RssEndpointTestCase.java 19191 2010-08-25 21:05:23Z tcarlson $
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.EndpointFactory;
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.api.registry.ServiceException;
15  import org.mule.module.rss.endpoint.RssInboundEndpoint;
16  import org.mule.tck.AbstractMuleTestCase;
17  import org.mule.transport.file.FileConnector;
18  import org.mule.transport.http.HttpPollingConnector;
19  
20  public class RssEndpointTestCase extends AbstractMuleTestCase
21  {
22      public void testHttpInboundEndpointCreation() throws Exception
23      {
24          String uri = "rss:http://blog.com/rss";
25          EndpointFactory factory = muleContext.getRegistry().lookupEndpointFactory();
26          InboundEndpoint in = factory.getEndpointBuilder(uri).buildInboundEndpoint();
27          assertNotNull(in);
28          assertEquals("rss:http", in.getEndpointURI().getFullScheme());
29          assertEquals("http", in.getProtocol());
30          assertTrue(in.getConnector() instanceof HttpPollingConnector);
31          assertTrue(in instanceof RssInboundEndpoint);
32      }
33  
34      public void testHttpOutboundEndpointCreation() throws Exception
35      {
36          String uri = "rss:http://blog.com/rss";
37          EndpointFactory factory = muleContext.getRegistry().lookupEndpointFactory();
38          try
39          {
40              factory.getEndpointBuilder(uri).buildOutboundEndpoint();
41              fail("RSS outbound endpoints are not supported");
42          }
43          catch (UnsupportedOperationException e)
44          {
45              //exprected
46          }
47      }
48  
49      public void testFileInboundEndpointCreation() throws Exception
50      {
51          String uri = "rss:file://./src/foo";
52          EndpointFactory factory = muleContext.getRegistry().lookupEndpointFactory();
53          InboundEndpoint in = factory.getEndpointBuilder(uri).buildInboundEndpoint();
54          assertNotNull(in);
55          assertEquals("rss:file", in.getEndpointURI().getFullScheme());
56          assertEquals("file", in.getProtocol());
57          assertTrue(in.getConnector() instanceof FileConnector);
58          assertTrue(in instanceof RssInboundEndpoint);
59      }
60  
61      public void testFileOutboundEndpointCreation() throws Exception
62      {
63          String uri = "rss:file://./src/foo";
64          EndpointFactory factory = muleContext.getRegistry().lookupEndpointFactory();
65          try
66          {
67              factory.getEndpointBuilder(uri).buildOutboundEndpoint();
68              fail("RSS outbound endpoints are not supported");
69          }
70          catch (UnsupportedOperationException e)
71          {
72              //exprected
73          }
74      }
75  
76      public void testXXInboundEndpointCreation() throws Exception
77      {
78          String uri = "rss:xxx://./src/foo";
79          EndpointFactory factory = muleContext.getRegistry().lookupEndpointFactory();
80          try
81          {
82              factory.getEndpointBuilder(uri).buildInboundEndpoint();
83              fail("xxx is not a valid transport");
84          }
85          catch (ServiceException e)
86          {
87              //expected
88          }
89      }
90  }