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