* Java Example of Hexagonal Architecture

* removing unnecessary maven files from pull request and spaces in code

* Removing unnecessary lines

* Example code for using Multiple Cache Manager in SpringBoot

* BAEL-3963:Using multiple cache managers in Spring

* removing new module created in last pull request

* Fixes as per editor Suggestions

Co-authored-by: Ankur Gupta <ankur.gupta@jda.com>
This commit is contained in:
Ankur Gupta
2020-04-18 20:41:31 +05:30
committed by GitHub
parent d2c03ec301
commit f38f3ffbf8
16 changed files with 542 additions and 44 deletions

View File

@@ -0,0 +1,64 @@
package com.baeldung.multiplecachemanager;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.cache.Cache;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.util.Assert;
import com.baeldung.multiplecachemanager.bo.OrderDetailBO;
import com.baeldung.multiplecachemanager.entity.Order;
import com.baeldung.multiplecachemanager.repository.OrderDetailRepository;
@SpringBootApplication
@SpringBootTest
public class MultipleCacheManagerIntegrationUnitTest {
@MockBean
private OrderDetailRepository orderDetailRepository;
@Autowired
private OrderDetailBO orderDetailBO;
@Autowired
private CacheManager cacheManager;
@Autowired
private CacheManager alternateCacheManager;
@Test
public void givenCacheResolverIsConfigured_whenCallGetOrderDetail_thenDataShouldBeInCaffieneCacheManager() {
Integer key = 30001;
cacheManager.getCache("orders")
.evict(key);
Order order = new Order();
order.setCustomerId(1001);
order.setItemId(10001);
order.setOrderId(30001);
order.setQuantity(2);
Mockito.when(orderDetailRepository.getOrderDetail(key))
.thenReturn(order);
orderDetailBO.getOrderDetail(key);
org.springframework.cache.caffeine.CaffeineCache cache = (CaffeineCache) cacheManager.getCache("orders");
Assert.notNull(cache.get(key)
.get(), "caffieneCache should have had the data");
}
@Test
public void givenCacheResolverIsConfigured_whenCallGetOrderPrice_thenDataShouldBeInAlternateCacheManager() {
Integer key = 30001;
alternateCacheManager.getCache("orderprice")
.evict(key);
Mockito.when(orderDetailRepository.getOrderPrice(key))
.thenReturn(500.0);
orderDetailBO.getOrderPrice(key);
Cache cache = alternateCacheManager.getCache("orderprice");
Assert.notNull(cache.get(key)
.get(), "alternateCache should have had the data");
}
}