* Evaluation article: Different Types of Bean Injection in Spring * added tests & changed configuration to Java-based config * removed xml config files * rename unit tests * BAEL-972 - Apache Commons Text * remove code from evaluation article * remove code from evaluation article * BAEL-972 - Apache Commons Text - added another example * BAEL-972 - Apache Commons Text - just indentation * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java * BAEL-994 - TemporalAdjuster in Java - fix problems * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * BAEL-1033 Introduction to StreamUtils * fix formatting * BAEL-1033 minor refactor * BAEL-1035 Introduction to Eclipse Collections * format * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * BAEL-1035 Introduction to Eclipse Collections * cleanup * cleanup * BAEL-1109 Introduction to JCache * BAEL-1109 Introduction to JCache * remove unneeded property in pom.xml * fix formatting * close cache instances properly * remove latest commit * BAEL-1057 Introduction to rxjava-jdbc
44 lines
1.3 KiB
Java
44 lines
1.3 KiB
Java
package com.baeldung.jcache;
|
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import javax.cache.Cache;
|
|
import javax.cache.CacheManager;
|
|
import javax.cache.Caching;
|
|
import javax.cache.configuration.FactoryBuilder;
|
|
import javax.cache.configuration.MutableConfiguration;
|
|
import javax.cache.spi.CachingProvider;
|
|
|
|
import org.junit.After;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
|
|
public class CacheLoaderTest {
|
|
|
|
private static final String CACHE_NAME = "SimpleCache";
|
|
|
|
private Cache<Integer, String> cache;
|
|
|
|
@Before
|
|
public void setup() {
|
|
CachingProvider cachingProvider = Caching.getCachingProvider();
|
|
CacheManager cacheManager = cachingProvider.getCacheManager();
|
|
MutableConfiguration<Integer, String> config = new MutableConfiguration<Integer, String>().setReadThrough(true)
|
|
.setCacheLoaderFactory(new FactoryBuilder.SingletonFactory<>(new SimpleCacheLoader()));
|
|
this.cache = cacheManager.createCache("SimpleCache", config);
|
|
}
|
|
|
|
@After
|
|
public void tearDown() {
|
|
Caching.getCachingProvider()
|
|
.getCacheManager().destroyCache(CACHE_NAME);
|
|
}
|
|
|
|
@Test
|
|
public void whenReadingFromStorage_thenCorrect() {
|
|
for (int i = 1; i < 4; i++) {
|
|
String value = cache.get(i);
|
|
assertEquals("fromCache" + i, value);
|
|
}
|
|
}
|
|
} |