View Javadoc
1   /*
2    * Copyright (c) MuleSoft, Inc.  All rights reserved.  http://www.mulesoft.com
3    * The software in this package is published under the terms of the CPAL v1.0
4    * license, a copy of which has been included with this distribution in the
5    * LICENSE.txt file.
6    */
7   package org.mule.module.spring.objectstore;
8   
9   import org.mule.api.store.ObjectStore;
10  import org.mule.transport.NullPayload;
11  import org.mule.util.store.AbstractObjectStoreContractTestCase;
12  
13  import java.io.Serializable;
14  
15  import org.mockito.Mockito;
16  import org.springmodules.cache.CachingModel;
17  import org.springmodules.cache.provider.CacheProviderFacade;
18  
19  import static org.mockito.Mockito.mock;
20  
21  public class SpringCacheObjectStoreTestCase extends AbstractObjectStoreContractTestCase
22  {
23  
24      @Override
25      public ObjectStore<Serializable> getObjectStore()
26      {
27          SpringCacheObjectStore<Serializable> objectStore = new SpringCacheObjectStore<Serializable>();
28          CachingModel cachingModel = mock(CachingModel.class);
29          CacheProviderFacade cacheProvider = mock(CacheProviderFacade.class);
30          objectStore.setCacheProvider(cacheProvider);
31          objectStore.setCachingModel(cachingModel);
32  
33          Mockito.when(cacheProvider.getFromCache("this_key_does_not_exist", cachingModel)).thenReturn(null);
34          Mockito.when(cacheProvider.getFromCache("theKey", cachingModel)).thenReturn(null).thenReturn(new SpringCacheObjectStore.ObjectStoreValue<Serializable>(null));
35  
36          return objectStore;
37      }
38  
39      @Override
40      public Serializable getStorableValue()
41      {
42          return NullPayload.getInstance();
43      }
44  }