1   /*
2    * $Id: MuleDescriptorTestCase.java 11621 2008-04-22 03:01:54Z dfeist $
3    * --------------------------------------------------------------------------------------
4    * Copyright (c) MuleSource, Inc.  All rights reserved.  http://www.mulesource.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.mule;
12  
13  import org.mule.api.endpoint.InboundEndpoint;
14  import org.mule.api.service.Service;
15  import org.mule.component.simple.PassThroughComponent;
16  import org.mule.model.seda.SedaService;
17  import org.mule.tck.AbstractMuleTestCase;
18  import org.mule.tck.testmodels.fruit.Orange;
19  import org.mule.tck.testmodels.mule.TestExceptionStrategy;
20  
21  public class MuleDescriptorTestCase extends AbstractMuleTestCase
22  {
23      public void testDescriptorDefaults() throws Exception
24      {
25          Service service = new SedaService();
26  
27          //TODO RM*
28  //        MuleConfiguration config = new MuleConfiguration();
29  //        assertEquals(config.getQueueProfile().getMaxOutstandingMessages(), 
30  //                     descriptor.getQueueProfile().getMaxOutstandingMessages());
31  //        assertEquals(config.getThreadingProfile().getMaxBufferSize(), 
32  //                     descriptor.getThreadingProfile().getMaxBufferSize());
33  //        assertEquals(config.getPoolingProfile().getMaxIdle(), descriptor.getPoolingProfile().getMaxIdle());
34  //        assertEquals(config.getPoolingProfile().getMaxWait(), descriptor.getPoolingProfile().getMaxWait());
35  //        assertEquals(config.getPoolingProfile().getMaxActive(), descriptor.getPoolingProfile().getMaxActive());
36  //        assertEquals("1.0", descriptor.getVersion());
37          // assertEquals(2, descriptor.getInitialisationPolicy());
38  
39          //assertNull("Factory should be null but is " + service.getServiceFactory(), service.getServiceFactory());
40          assertNotNull(service.getComponent());
41          assertTrue(service.getComponent() instanceof PassThroughComponent);
42          // assertEquals(0, service.getProperties().size());
43      }
44  
45      // These validations seems a bit silly, IMHO.
46  //    public void testDescriptorNullValidation() throws Exception
47  //    {
48  //        Service service = new SedaService();
49  //        try
50  //        {
51  //            service.setExceptionListener(null);
52  //            fail("setting exeption strategy to null should fail");
53  //        }
54  //        catch (RuntimeException e)
55  //        {
56  //            // expected
57  //        }
58  //
59  //        try
60  //        {
61  //            service.setName(null);
62  //            fail("setting name to null should fail");
63  //        }
64  //        catch (RuntimeException e)
65  //        {
66  //            // expected
67  //        }
68  //
69  //        try
70  //        {
71  //            service.setServiceFactory(null);
72  //            fail("setting serviceFactory to null should fail");
73  //        }
74  //        catch (RuntimeException e)
75  //        {
76  //            // expected
77  //        }
78  //
79  //    }
80  
81      public void testEndpointValidation() throws Exception
82      {
83          Service service = getTestService("Terry", Orange.class);
84          TestExceptionStrategy es = new TestExceptionStrategy();
85          service.setExceptionListener(es);
86          assertEquals(1, service.getOutboundRouter().getRouters().size());
87          
88          // TODO Why should there be an outbound endpoint configured?
89          //Endpoint ep = (Endpoint)((OutboundRouter)service.getOutboundRouter().getRouters().get(0)).getEndpoints().get(0);
90          //assertNotNull(ep);
91          //assertNotNull(ep.getConnector().getExceptionListener());
92  
93          // create receive endpoint
94          InboundEndpoint endpoint = getTestInboundEndpoint("test2");
95          service.getInboundRouter().addEndpoint(endpoint);
96          // Add receive endpoint, this shoulbe set as default
97          assertNotNull(endpoint.getConnector().getExceptionListener());
98      }
99  }