1   /*
2    * $Id: MuleDescriptorTestCase.java 7976 2007-08-21 14:26:13Z dirk.olmes $
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.config.MuleConfiguration;
14  import org.mule.impl.MuleDescriptor;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.tck.testmodels.fruit.Orange;
17  import org.mule.tck.testmodels.mule.TestExceptionStrategy;
18  import org.mule.umo.UMODescriptor;
19  import org.mule.umo.endpoint.UMOEndpoint;
20  
21  /**
22   * @author <a href="mailto:ross.mason@symphonysoft.com">Ross Mason</a>
23   * @version $Revision: 7976 $
24   */
25  public class MuleDescriptorTestCase extends AbstractMuleTestCase
26  {
27      public void testDescriptorDefaults() throws Exception
28      {
29          MuleDescriptor descriptor = new MuleDescriptor();
30          descriptor.initialise();
31          MuleConfiguration config = new MuleConfiguration();
32  
33          assertNotNull(descriptor.getInterceptors());
34          assertEquals(0, descriptor.getInterceptors().size());
35  
36          assertEquals(config.getQueueProfile().getMaxOutstandingMessages(), descriptor.getQueueProfile()
37              .getMaxOutstandingMessages());
38          assertEquals(config.getPoolingProfile().getMaxIdle(), descriptor.getPoolingProfile().getMaxIdle());
39          assertEquals(config.getPoolingProfile().getMaxWait(), descriptor.getPoolingProfile().getMaxWait());
40          assertEquals(config.getPoolingProfile().getMaxActive(), descriptor.getPoolingProfile().getMaxActive());
41          assertEquals("1.0", descriptor.getVersion());
42          // assertEquals(2, descriptor.getInitialisationPolicy());
43  
44          assertNull(descriptor.getImplementation());
45          assertNull(descriptor.getInboundEndpoint());
46          assertNull(descriptor.getInboundTransformer());
47          assertNull(descriptor.getName());
48          assertNull(descriptor.getOutboundEndpoint());
49          assertNull(descriptor.getOutboundTransformer());
50          assertEquals(0, descriptor.getProperties().size());
51      }
52  
53      public void testDescriptorNullValidation() throws Exception
54      {
55          UMODescriptor descriptor = new MuleDescriptor();
56  
57          try
58          {
59              descriptor.setExceptionListener(null);
60              fail("setting exeption strategy to null should fail");
61          }
62          catch (RuntimeException e)
63          {
64              // expected
65          }
66  
67          try
68          {
69              descriptor.setName(null);
70              fail("setting name to null should fail");
71          }
72          catch (RuntimeException e)
73          {
74              // expected
75          }
76  
77          try
78          {
79              descriptor.setImplementation(null);
80              fail("setting implementation to null should fail");
81          }
82          catch (RuntimeException e)
83          {
84              // expected
85          }
86  
87      }
88  
89      public void testImplementationValidation() throws Exception
90      {
91          UMODescriptor descriptor = new MuleDescriptor();
92  
93          try
94          {
95              descriptor.setImplementation(null);
96              fail("setting implementation to null should fail");
97          }
98          catch (RuntimeException e)
99          {
100             // expected
101         }
102 
103     }
104 
105     public void testEndpointValidation() throws Exception
106     {
107         UMODescriptor descriptor = getTestDescriptor("Terry", Orange.class.getName());
108         TestExceptionStrategy es = new TestExceptionStrategy();
109         descriptor.setExceptionListener(es);
110         assertNotNull(descriptor.getOutboundEndpoint());
111         assertNotNull(descriptor.getOutboundEndpoint().getConnector().getExceptionListener());
112 
113         // create receive endpoint
114         UMOEndpoint endpoint = getTestEndpoint("test2", UMOEndpoint.ENDPOINT_TYPE_RECEIVER);
115         descriptor.setInboundEndpoint(endpoint);
116         // Add receive endpoint, this shoulbe set as default
117         assertNotNull(descriptor.getInboundEndpoint().getConnector().getExceptionListener());
118         // assertNotNull(descriptor.getReceiveEndpoint());
119         // assertEquals(descriptor.getReceiveEndpoint(),
120         // endpoint.getEndpointURI());
121     }
122 }