use of com.amazonaws.services.elasticache.AmazonElastiCache in project spring-cloud-aws by awspring.
the class CacheBeanDefinitionParserTest method parseInternal_mixedCacheConfig_returnsBothCaches.
@Test
void parseInternal_mixedCacheConfig_returnsBothCaches() throws Exception {
// Arrange
DefaultListableBeanFactory beanFactory = new DefaultListableBeanFactory();
// Register a mock object which will be used to replay service calls
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
beanDefinitionBuilder.setFactoryMethod("mock");
beanDefinitionBuilder.addConstructorArgValue(AmazonElastiCache.class);
beanFactory.registerBeanDefinition(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), beanDefinitionBuilder.getBeanDefinition());
BeanDefinitionBuilder cacheBuilder = BeanDefinitionBuilder.rootBeanDefinition(Mockito.class);
cacheBuilder.setFactoryMethod("mock");
cacheBuilder.addConstructorArgValue(AmazonElastiCache.class);
beanFactory.registerBeanDefinition(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), cacheBuilder.getBeanDefinition());
XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(beanFactory);
reader.loadBeanDefinitions(new ClassPathResource(getClass().getSimpleName() + "-mixedCacheConfig.xml", getClass()));
AmazonElastiCache client = beanFactory.getBean(AmazonWebserviceClientConfigurationUtils.getBeanName(AmazonElastiCacheClient.class.getName()), AmazonElastiCache.class);
// Replay invocation that will be called
DescribeCacheClustersRequest memcached1 = new DescribeCacheClustersRequest().withCacheClusterId("memcached");
memcached1.setShowCacheNodeInfo(true);
when(client.describeCacheClusters(memcached1)).thenReturn(new DescribeCacheClustersResult().withCacheClusters(new CacheCluster().withCacheClusterId("memcached").withConfigurationEndpoint(new Endpoint().withAddress("localhost").withPort(Integer.parseInt(System.getProperty("memcachedPort")))).withCacheClusterStatus("available").withEngine("memcached")));
Cache cache = beanFactory.getBean("memc", Cache.class);
when(cache.getName()).thenReturn("memc");
// Act
CacheManager cacheManager = beanFactory.getBean(CacheManager.class);
Cache memc = cacheManager.getCache("memc");
Cache memcached = cacheManager.getCache("memcached");
// Assert
assertThat(cacheManager).isNotNull();
assertThat(memcached).isNotNull();
memc.put("foo", "bar");
memc.evict("foo");
memcached.put("foo", "bar");
memcached.evict("foo");
}
Aggregations