1   /*
2    * $Id: MuleConfigurationTestCase.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.test.config;
12  
13  import org.mule.config.MuleConfiguration;
14  import org.mule.config.PoolingProfile;
15  import org.mule.tck.AbstractMuleTestCase;
16  import org.mule.util.ObjectPool;
17  
18  public class MuleConfigurationTestCase extends AbstractMuleTestCase
19  {
20  
21      public void testConfigurationDefaults()
22      {
23          MuleConfiguration mc = new MuleConfiguration();
24          assertEquals(MuleConfiguration.DEFAULT_MAX_OUTSTANDING_MESSAGES, mc.getQueueProfile()
25              .getMaxOutstandingMessages());
26          assertEquals(PoolingProfile.DEFAULT_MAX_POOL_WAIT, mc.getPoolingProfile().getMaxWait());
27          assertEquals(PoolingProfile.DEFAULT_MAX_POOL_ACTIVE, mc.getPoolingProfile().getMaxActive());
28          assertEquals(PoolingProfile.DEFAULT_MAX_POOL_IDLE, mc.getPoolingProfile().getMaxIdle());
29          assertEquals(PoolingProfile.DEFAULT_POOL_EXHAUSTED_ACTION, mc.getPoolingProfile()
30              .getExhaustedAction());
31          assertEquals(PoolingProfile.DEFAULT_POOL_INITIALISATION_POLICY, mc.getPoolingProfile()
32              .getInitialisationPolicy());
33          assertEquals(MuleConfiguration.DEFAULT_SYNCHRONOUS, mc.isSynchronous());
34          assertNull(mc.getModel());
35      }
36  
37      public void testConfiguration()
38      {
39          MuleConfiguration mc = new MuleConfiguration();
40  
41          mc.getQueueProfile().setMaxOutstandingMessages(1);
42          mc.getPoolingProfile().setMaxWait(0);
43          mc.getPoolingProfile().setMaxActive(1);
44          mc.getPoolingProfile().setMaxIdle(1);
45          mc.getPoolingProfile().setExhaustedAction((byte) 1);
46          mc.getPoolingProfile().setInitialisationPolicy((byte) 0);
47          mc.setSynchronous(false);
48          mc.setModel("Test");
49  
50          PoolingProfile pp = mc.getPoolingProfile();
51  
52          pp.setExhaustedActionString("GROW");
53          assertEquals(ObjectPool.WHEN_EXHAUSTED_GROW, pp.getExhaustedAction());
54          pp.setExhaustedActionString("WHEN_EXHAUSTED_GROW");
55          assertEquals(ObjectPool.WHEN_EXHAUSTED_GROW, pp.getExhaustedAction());
56  
57          pp.setExhaustedActionString("WAIT");
58          assertEquals(ObjectPool.WHEN_EXHAUSTED_WAIT, pp.getExhaustedAction());
59          pp.setExhaustedActionString("WHEN_EXHAUSTED_WAIT");
60          assertEquals(ObjectPool.WHEN_EXHAUSTED_WAIT, pp.getExhaustedAction());
61  
62          pp.setExhaustedActionString("FAIL");
63          assertEquals(ObjectPool.WHEN_EXHAUSTED_FAIL, pp.getExhaustedAction());
64          pp.setExhaustedActionString("WHEN_EXHAUSTED_FAIL");
65          assertEquals(ObjectPool.WHEN_EXHAUSTED_FAIL, pp.getExhaustedAction());
66  
67          pp.setExhaustedActionString("BLAH");
68          assertEquals(ObjectPool.DEFAULT_EXHAUSTED_ACTION, pp.getExhaustedAction());
69  
70          pp.setExhaustedActionString(null);
71          assertEquals(ObjectPool.DEFAULT_EXHAUSTED_ACTION, pp.getExhaustedAction());
72  
73          pp.setInitialisationPolicyString("INITIALISE_NONE");
74          assertEquals(PoolingProfile.INITIALISE_NONE, pp.getInitialisationPolicy());
75  
76          pp.setInitialisationPolicyString("INITIALISE_ONE");
77          assertEquals(PoolingProfile.INITIALISE_ONE, pp.getInitialisationPolicy());
78          pp.setInitialisationPolicyString("POOL_INITIALISE_ONE_COMPONENT");
79          assertEquals(PoolingProfile.INITIALISE_ONE, pp.getInitialisationPolicy());
80  
81          pp.setInitialisationPolicyString("INITIALISE_ALL");
82          assertEquals(PoolingProfile.INITIALISE_ALL, pp.getInitialisationPolicy());
83  
84          pp.setInitialisationPolicyString("FOO");
85          assertEquals(PoolingProfile.DEFAULT_POOL_INITIALISATION_POLICY, pp.getInitialisationPolicy());
86  
87          pp.setInitialisationPolicyString(null);
88          assertEquals(PoolingProfile.DEFAULT_POOL_INITIALISATION_POLICY, pp.getInitialisationPolicy());
89      }
90  
91  }