Search in sources :

Example 1 with NamedCacheResolver

use of org.springframework.cache.interceptor.NamedCacheResolver in project spring-framework by spring-projects.

the class JCacheInterceptorTests method severalCachesNotSupported.

@Test
public void severalCachesNotSupported() {
    JCacheInterceptor interceptor = createInterceptor(createOperationSource(cacheManager, new NamedCacheResolver(cacheManager, "default", "simpleCache"), defaultExceptionCacheResolver, defaultKeyGenerator));
    AnnotatedJCacheableService service = new AnnotatedJCacheableService(cacheManager.getCache("default"));
    Method m = ReflectionUtils.findMethod(AnnotatedJCacheableService.class, "cache", String.class);
    try {
        interceptor.execute(dummyInvoker, service, m, new Object[] { "myId" });
    } catch (IllegalStateException ex) {
        assertTrue(ex.getMessage().contains("JSR-107 only supports a single cache"));
    } catch (Throwable ex) {
        fail("Unexpected: " + ex);
    }
}
Also used : Method(java.lang.reflect.Method) NamedCacheResolver(org.springframework.cache.interceptor.NamedCacheResolver) Test(org.junit.Test)

Example 2 with NamedCacheResolver

use of org.springframework.cache.interceptor.NamedCacheResolver in project spring-framework by spring-projects.

the class JCacheInterceptorTests method noCacheCouldBeResolved.

@Test
public void noCacheCouldBeResolved() {
    JCacheInterceptor interceptor = createInterceptor(createOperationSource(// Returns empty list
    cacheManager, // Returns empty list
    new NamedCacheResolver(cacheManager), defaultExceptionCacheResolver, defaultKeyGenerator));
    AnnotatedJCacheableService service = new AnnotatedJCacheableService(cacheManager.getCache("default"));
    Method m = ReflectionUtils.findMethod(AnnotatedJCacheableService.class, "cache", String.class);
    try {
        interceptor.execute(dummyInvoker, service, m, new Object[] { "myId" });
    } catch (IllegalStateException ex) {
        assertTrue(ex.getMessage().contains("Cache could not have been resolved for"));
    } catch (Throwable ex) {
        fail("Unexpected: " + ex);
    }
}
Also used : Method(java.lang.reflect.Method) NamedCacheResolver(org.springframework.cache.interceptor.NamedCacheResolver) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)2 Test (org.junit.Test)2 NamedCacheResolver (org.springframework.cache.interceptor.NamedCacheResolver)2