View Javadoc

1   /*
2    * $Id: QueueStoreConfigurationTestCase.java 22597 2011-08-05 20:40:24Z dfeist $
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  
11  package org.mule.config.spring;
12  
13  import org.mule.api.config.MuleProperties;
14  import org.mule.api.processor.ProcessingStrategy;
15  import org.mule.api.store.ListableObjectStore;
16  import org.mule.config.QueueProfile;
17  import org.mule.construct.Flow;
18  import org.mule.construct.flow.DefaultFlowProcessingStrategy;
19  import org.mule.model.seda.SedaService;
20  import org.mule.processor.strategy.QueuedAsynchronousProcessingStrategy;
21  import org.mule.tck.FunctionalTestCase;
22  import org.mule.util.store.SimpleMemoryObjectStore;
23  
24  import java.io.Serializable;
25  
26  public class QueueStoreConfigurationTestCase extends FunctionalTestCase
27  {
28      @Override
29      protected String getConfigResources()
30      {
31          return "org/mule/test/spring/queue-store-configs.xml";
32      }
33  
34      public void testServiceDefaults()
35      {
36          SedaService service = lookupService("serviceDefault");
37          QueueProfile queueProfile = service.getQueueProfile();
38          assertEquals(0, queueProfile.getMaxOutstandingMessages());
39          assertObjectStoreIsDefaultMemoryObjectStore(queueProfile.getObjectStore());
40      }
41      
42      public void testServiceOnlyNumberOfOutstandingMessagesConfigured()
43      {
44          SedaService service = lookupService("serviceNoObjectStore");
45          QueueProfile queueProfile = service.getQueueProfile();
46          assertEquals(42, queueProfile.getMaxOutstandingMessages());
47          assertObjectStoreIsDefaultMemoryObjectStore(queueProfile.getObjectStore());
48      }
49      
50      public void testServiceExplicitDefaultMemoryObjectStoreConfigured()
51      {
52          SedaService service = lookupService("serviceExplicitDefaultMemoryObjectStore");
53          QueueProfile queueProfile = service.getQueueProfile();
54          assertObjectStoreIsDefaultMemoryObjectStore(queueProfile.getObjectStore());
55      }
56      
57      public void testServiceExplicitDefaultPersistentObjectStoreConfigured()
58      {
59          SedaService service = lookupService("serviceExplicitDefaultPersistentObjectStore");
60          QueueProfile queueProfile = service.getQueueProfile();
61          assertObjectStoreIsDefaultPersistentObjectStore(queueProfile.getObjectStore());
62      }
63  
64      public void testServiceExplicitObjectStoreConfigured()
65      {
66          SedaService service = lookupService("serviceExplicitObjectStore");
67          QueueProfile queueProfile = service.getQueueProfile();
68          assertTrue(queueProfile.getObjectStore() instanceof TestObjectStore);
69      }
70  
71      public void testFlowDefaults()
72      {
73          Flow flow = lookupFlow("flowDefault");
74          
75          // default for flow is sync processing -> no queueing
76          assertTrue(flow.getProcessingStrategy() instanceof DefaultFlowProcessingStrategy);
77      }
78      
79      public void testFlowQueuedAsync()
80      {
81          Flow flow = lookupFlow("flowQueuedAsync");
82          
83          
84          ProcessingStrategy pipeline = flow.getProcessingStrategy();
85          assertTrue(pipeline instanceof QueuedAsynchronousProcessingStrategy);
86          
87          QueuedAsynchronousProcessingStrategy queuedPipeline = (QueuedAsynchronousProcessingStrategy)pipeline;
88          assertObjectStoreIsDefaultMemoryObjectStore(queuedPipeline.getQueueStore());
89      }
90      
91      private SedaService lookupService(String name)
92      {
93          return (SedaService) muleContext.getRegistry().lookupService(name);
94      }
95      
96      private Flow lookupFlow(String name)
97      {
98          return (Flow) muleContext.getRegistry().lookupFlowConstruct(name);
99      }
100 
101     private void assertObjectStoreIsDefaultMemoryObjectStore(ListableObjectStore<Serializable> objectStore)
102     {
103         Object defaultMemoryObjectStore = 
104             muleContext.getRegistry().lookupObject(MuleProperties.OBJECT_STORE_DEFAULT_IN_MEMORY_NAME);
105         assertEquals(defaultMemoryObjectStore, objectStore);
106     }
107     
108     private void assertObjectStoreIsDefaultPersistentObjectStore(ListableObjectStore<Serializable> objectStore)
109     {
110         Object defaultPersistentObjectStore = 
111             muleContext.getRegistry().lookupObject(MuleProperties.OBJECT_STORE_DEFAULT_PERSISTENT_NAME);
112         assertEquals(defaultPersistentObjectStore, objectStore);
113     }
114     
115     public static class TestObjectStore extends SimpleMemoryObjectStore<Serializable>
116     {
117         // no custom methods
118     }
119 }