| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | /* | |
| 2 | - * Copyright 2002-2014 the original author or authors. | ||
| 2 | + * Copyright 2002-2015 the original author or authors. | ||
| 3 | 3 | * | |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | 5 | * you may not use this file except in compliance with the License. | |
@@ -20,7 +20,7 @@ | |||
| 20 | 20 | import org.junit.Test; | |
| 21 | 21 | ||
| 22 | 22 | import org.springframework.cache.Cache; | |
| 23 | - import org.springframework.cache.config.AbstractAnnotationTests; | ||
| 23 | + import org.springframework.cache.config.AbstractCacheAnnotationTests; | ||
| 24 | 24 | import org.springframework.cache.config.CacheableService; | |
| 25 | 25 | import org.springframework.context.ConfigurableApplicationContext; | |
| 26 | 26 | import org.springframework.context.support.GenericXmlApplicationContext; | |
@@ -30,17 +30,18 @@ | |||
| 30 | 30 | /** | |
| 31 | 31 | * @author Costin Leau | |
| 32 | 32 | */ | |
| 33 | - public class AspectJAnnotationTests extends AbstractAnnotationTests { | ||
| 34 | - | ||
| 33 | + public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests { | ||
| 35 | 34 | ||
| 36 | 35 | @Override | |
| 37 | 36 | protected ConfigurableApplicationContext getApplicationContext() { | |
| 38 | - return new GenericXmlApplicationContext("/org/springframework/cache/config/annotation-cache-aspectj.xml"); | ||
| 37 | + return new GenericXmlApplicationContext( | ||
| 38 | + "/org/springframework/cache/config/annotation-cache-aspectj.xml"); | ||
| 39 | 39 | } | |
| 40 | 40 | ||
| 41 | 41 | @Test | |
| 42 | 42 | public void testKeyStrategy() throws Exception { | |
| 43 | - AnnotationCacheAspect aspect = ctx.getBean("org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class); | ||
| 43 | + AnnotationCacheAspect aspect = ctx.getBean( | ||
| 44 | + "org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class); | ||
| 44 | 45 | Assert.assertSame(ctx.getBean("keyGenerator"), aspect.getKeyGenerator()); | |
| 45 | 46 | } | |
| 46 | 47 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -33,6 +33,7 @@ public abstract class AbstractCacheTests<T extends Cache> { | |||
| 33 | 33 | ||
| 34 | 34 | protected abstract Object getNativeCache(); | |
| 35 | 35 | ||
| 36 | + | ||
| 36 | 37 | @Test | |
| 37 | 38 | public void testCacheName() throws Exception { | |
| 38 | 39 | assertEquals(CACHE_NAME, getCache().getName()); | |
@@ -105,6 +106,7 @@ public void testCacheClear() throws Exception { | |||
| 105 | 106 | assertNull(cache.get("enescu")); | |
| 106 | 107 | } | |
| 107 | 108 | ||
| 109 | + | ||
| 108 | 110 | private String createRandomKey() { | |
| 109 | 111 | return UUID.randomUUID().toString(); | |
| 110 | 112 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -28,7 +28,7 @@ | |||
| 28 | 28 | ||
| 29 | 29 | import org.springframework.cache.annotation.CachingConfigurerSupport; | |
| 30 | 30 | import org.springframework.cache.annotation.EnableCaching; | |
| 31 | - import org.springframework.cache.config.AbstractAnnotationTests; | ||
| 31 | + import org.springframework.cache.config.AbstractCacheAnnotationTests; | ||
| 32 | 32 | import org.springframework.cache.config.AnnotatedClassCacheableService; | |
| 33 | 33 | import org.springframework.cache.config.CacheableService; | |
| 34 | 34 | import org.springframework.cache.config.DefaultCacheableService; | |
@@ -43,7 +43,7 @@ | |||
| 43 | 43 | /** | |
| 44 | 44 | * @author Stephane Nicoll | |
| 45 | 45 | */ | |
| 46 | - public class JCacheEhCacheAnnotationTests extends AbstractAnnotationTests { | ||
| 46 | + public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests { | ||
| 47 | 47 | ||
| 48 | 48 | private CacheManager jCacheManager; | |
| 49 | 49 | ||
@@ -58,6 +58,10 @@ protected ConfigurableApplicationContext getApplicationContext() { | |||
| 58 | 58 | return context; | |
| 59 | 59 | } | |
| 60 | 60 | ||
| 61 | + protected CachingProvider getCachingProvider() { | ||
| 62 | + return Caching.getCachingProvider(); | ||
| 63 | + } | ||
| 64 | + | ||
| 61 | 65 | @After | |
| 62 | 66 | public void shutdown() { | |
| 63 | 67 | if (jCacheManager != null) { | |
@@ -73,11 +77,6 @@ public void testCustomCacheManager() { | |||
| 73 | 77 | } | |
| 74 | 78 | ||
| 75 | 79 | ||
| 76 | - protected CachingProvider getCachingProvider() { | ||
| 77 | - return Caching.getCachingProvider(); | ||
| 78 | - } | ||
| 79 | - | ||
| 80 | - | ||
| 81 | 80 | @Configuration | |
| 82 | 81 | @EnableCaching | |
| 83 | 82 | static class EnableCachingConfig extends CachingConfigurerSupport { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -30,27 +30,35 @@ | |||
| 30 | 30 | /** | |
| 31 | 31 | * @author Stephane Nicoll | |
| 32 | 32 | */ | |
| 33 | - public class JCacheEhCacheTests extends AbstractCacheTests<JCacheCache> { | ||
| 33 | + public class JCacheEhCacheApiTests extends AbstractCacheTests<JCacheCache> { | ||
| 34 | 34 | ||
| 35 | 35 | private CacheManager cacheManager; | |
| 36 | 36 | ||
| 37 | 37 | private Cache<Object, Object> nativeCache; | |
| 38 | 38 | ||
| 39 | 39 | private JCacheCache cache; | |
| 40 | 40 | ||
| 41 | + | ||
| 41 | 42 | @Before | |
| 42 | - public void setUp() { | ||
| 43 | + public void setup() { | ||
| 43 | 44 | this.cacheManager = getCachingProvider().getCacheManager(); | |
| 44 | 45 | this.cacheManager.createCache(CACHE_NAME, new MutableConfiguration<>()); | |
| 45 | 46 | this.nativeCache = this.cacheManager.getCache(CACHE_NAME); | |
| 46 | 47 | this.cache = new JCacheCache(this.nativeCache); | |
| 47 | 48 | } | |
| 48 | 49 | ||
| 50 | + protected CachingProvider getCachingProvider() { | ||
| 51 | + return Caching.getCachingProvider(); | ||
| 52 | + } | ||
| 53 | + | ||
| 49 | 54 | @After | |
| 50 | - public void shutdownCacheManager() { | ||
| 51 | - this.cacheManager.close(); | ||
| 55 | + public void shutdown() { | ||
| 56 | + if (this.cacheManager != null) { | ||
| 57 | + this.cacheManager.close(); | ||
| 58 | + } | ||
| 52 | 59 | } | |
| 53 | 60 | ||
| 61 | + | ||
| 54 | 62 | @Override | |
| 55 | 63 | protected JCacheCache getCache() { | |
| 56 | 64 | return this.cache; | |
@@ -61,8 +69,4 @@ protected Object getNativeCache() { | |||
| 61 | 69 | return this.nativeCache; | |
| 62 | 70 | } | |
| 63 | 71 | ||
| 64 | - protected CachingProvider getCachingProvider() { | ||
| 65 | - return Caching.getCachingProvider(); | ||
| 66 | - } | ||
| 67 | - | ||
| 68 | 72 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,14 +34,14 @@ | |||
| 34 | 34 | import static org.junit.Assert.*; | |
| 35 | 35 | ||
| 36 | 36 | /** | |
| 37 | - * Abstract annotation test (containing several reusable methods). | ||
| 37 | + * Abstract cache annotation tests (containing several reusable methods). | ||
| 38 | 38 | * | |
| 39 | 39 | * @author Costin Leau | |
| 40 | 40 | * @author Chris Beams | |
| 41 | 41 | * @author Phillip Webb | |
| 42 | 42 | * @author Stephane Nicoll | |
| 43 | 43 | */ | |
| 44 | - public abstract class AbstractAnnotationTests { | ||
| 44 | + public abstract class AbstractCacheAnnotationTests { | ||
| 45 | 45 | ||
| 46 | 46 | protected ConfigurableApplicationContext ctx; | |
| 47 | 47 | ||
@@ -72,7 +72,7 @@ public void setup() { | |||
| 72 | 72 | } | |
| 73 | 73 | ||
| 74 | 74 | @After | |
| 75 | - public void tearDown() { | ||
| 75 | + public void close() { | ||
| 76 | 76 | if (ctx != null) { | |
| 77 | 77 | ctx.close(); | |
| 78 | 78 | } | |
@@ -128,7 +128,8 @@ public void testEvictEarly(CacheableService<?> service) throws Exception { | |||
| 128 | 128 | assertSame(r1, r2); | |
| 129 | 129 | try { | |
| 130 | 130 | service.evictEarly(o1); | |
| 131 | - } catch (RuntimeException ex) { | ||
| 131 | + } | ||
| 132 | + catch (RuntimeException ex) { | ||
| 132 | 133 | // expected | |
| 133 | 134 | } | |
| 134 | 135 | ||
@@ -147,7 +148,8 @@ public void testEvictException(CacheableService<?> service) throws Exception { | |||
| 147 | 148 | assertSame(r1, r2); | |
| 148 | 149 | try { | |
| 149 | 150 | service.evictWithException(o1); | |
| 150 | - } catch (RuntimeException ex) { | ||
| 151 | + } | ||
| 152 | + catch (RuntimeException ex) { | ||
| 151 | 153 | // expected | |
| 152 | 154 | } | |
| 153 | 155 | // exception occurred, eviction skipped, data should still be in the cache | |
@@ -179,7 +181,8 @@ public void testEvictWKeyEarly(CacheableService<?> service) throws Exception { | |||
| 179 | 181 | ||
| 180 | 182 | try { | |
| 181 | 183 | service.invalidateEarly(o1, null); | |
| 182 | - } catch (Exception ex) { | ||
| 184 | + } | ||
| 185 | + catch (Exception ex) { | ||
| 183 | 186 | // expected | |
| 184 | 187 | } | |
| 185 | 188 | Object r3 = service.cache(o1); | |
@@ -290,7 +293,8 @@ public void testCheckedThrowable(CacheableService<?> service) throws Exception { | |||
| 290 | 293 | try { | |
| 291 | 294 | service.throwChecked(arg); | |
| 292 | 295 | fail("Excepted exception"); | |
| 293 | - } catch (Exception ex) { | ||
| 296 | + } | ||
| 297 | + catch (Exception ex) { | ||
| 294 | 298 | assertEquals("Wrong exception type", IOException.class, ex.getClass()); | |
| 295 | 299 | assertEquals(arg, ex.getMessage()); | |
| 296 | 300 | } | |
@@ -300,7 +304,8 @@ public void testUncheckedThrowable(CacheableService<?> service) throws Exception | |||
| 300 | 304 | try { | |
| 301 | 305 | service.throwUnchecked(Long.valueOf(1)); | |
| 302 | 306 | fail("Excepted exception"); | |
| 303 | - } catch (RuntimeException ex) { | ||
| 307 | + } | ||
| 308 | + catch (RuntimeException ex) { | ||
| 304 | 309 | assertEquals("Wrong exception type", UnsupportedOperationException.class, ex.getClass()); | |
| 305 | 310 | assertEquals("1", ex.getMessage()); | |
| 306 | 311 | } | |
@@ -623,7 +628,8 @@ public void testUnknownCustomKeyGenerator() { | |||
| 623 | 628 | Object param = new Object(); | |
| 624 | 629 | cs.unknownCustomKeyGenerator(param); | |
| 625 | 630 | fail("should have failed with NoSuchBeanDefinitionException"); | |
| 626 | - } catch (NoSuchBeanDefinitionException e) { | ||
| 631 | + } | ||
| 632 | + catch (NoSuchBeanDefinitionException ex) { | ||
| 627 | 633 | // expected | |
| 628 | 634 | } | |
| 629 | 635 | } | |
@@ -645,7 +651,8 @@ public void testUnknownCustomCacheManager() { | |||
| 645 | 651 | Object param = new Object(); | |
| 646 | 652 | cs.unknownCustomCacheManager(param); | |
| 647 | 653 | fail("should have failed with NoSuchBeanDefinitionException"); | |
| 648 | - } catch (NoSuchBeanDefinitionException e) { | ||
| 654 | + } | ||
| 655 | + catch (NoSuchBeanDefinitionException ex) { | ||
| 649 | 656 | // expected | |
| 650 | 657 | } | |
| 651 | 658 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,7 +23,7 @@ | |||
| 23 | 23 | * @author Costin Leau | |
| 24 | 24 | * @author Chris Beams | |
| 25 | 25 | */ | |
| 26 | - public class AnnotationTests extends AbstractAnnotationTests { | ||
| 26 | + public class AnnotationDrivenCacheConfigTests extends AbstractCacheAnnotationTests { | ||
| 27 | 27 | ||
| 28 | 28 | @Override | |
| 29 | 29 | protected ConfigurableApplicationContext getApplicationContext() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | /* | |
| 2 | - * Copyright 2002-2014 the original author or authors. | ||
| 2 | + * Copyright 2002-2015 the original author or authors. | ||
| 3 | 3 | * | |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | 5 | * you may not use this file except in compliance with the License. | |
@@ -30,7 +30,7 @@ | |||
| 30 | 30 | * @author Chris Beams | |
| 31 | 31 | * @author Stephane Nicoll | |
| 32 | 32 | */ | |
| 33 | - public class AnnotationNamespaceDrivenTests extends AbstractAnnotationTests { | ||
| 33 | + public class AnnotationNamespaceDrivenTests extends AbstractCacheAnnotationTests { | ||
| 34 | 34 | ||
| 35 | 35 | @Override | |
| 36 | 36 | protected ConfigurableApplicationContext getApplicationContext() { | |
@@ -40,8 +40,8 @@ protected ConfigurableApplicationContext getApplicationContext() { | |||
| 40 | 40 | ||
| 41 | 41 | @Test | |
| 42 | 42 | public void testKeyStrategy() { | |
| 43 | - CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0", | ||
| 44 | - CacheInterceptor.class); | ||
| 43 | + CacheInterceptor ci = ctx.getBean( | ||
| 44 | + "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); | ||
| 45 | 45 | assertSame(ctx.getBean("keyGenerator"), ci.getKeyGenerator()); | |
| 46 | 46 | } | |
| 47 | 47 | ||
@@ -67,8 +67,9 @@ public void bothSetOnlyResolverIsUsed() { | |||
| 67 | 67 | ||
| 68 | 68 | @Test | |
| 69 | 69 | public void testCacheErrorHandler() { | |
| 70 | - CacheInterceptor ci = ctx.getBean("org.springframework.cache.interceptor.CacheInterceptor#0", | ||
| 71 | - CacheInterceptor.class); | ||
| 70 | + CacheInterceptor ci = ctx.getBean( | ||
| 71 | + "org.springframework.cache.interceptor.CacheInterceptor#0", CacheInterceptor.class); | ||
| 72 | 72 | assertSame(ctx.getBean("errorHandler", CacheErrorHandler.class), ci.getErrorHandler()); | |
| 73 | 73 | } | |
| 74 | + | ||
| 74 | 75 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,5 +1,5 @@ | |||
| 1 | 1 | /* | |
| 2 | - * Copyright 2002-2014 the original author or authors. | ||
| 2 | + * Copyright 2002-2015 the original author or authors. | ||
| 3 | 3 | * | |
| 4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
| 5 | 5 | * you may not use this file except in compliance with the License. | |
@@ -27,7 +27,7 @@ | |||
| 27 | 27 | * @author Costin Leau | |
| 28 | 28 | * @author Chris Beams | |
| 29 | 29 | */ | |
| 30 | - public class CacheAdviceNamespaceTests extends AbstractAnnotationTests { | ||
| 30 | + public class CacheAdviceNamespaceTests extends AbstractCacheAnnotationTests { | ||
| 31 | 31 | ||
| 32 | 32 | @Override | |
| 33 | 33 | protected ConfigurableApplicationContext getApplicationContext() { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -44,7 +44,7 @@ | |||
| 44 | 44 | * @author Chris Beams | |
| 45 | 45 | * @author Stephane Nicoll | |
| 46 | 46 | */ | |
| 47 | - public class EnableCachingTests extends AbstractAnnotationTests { | ||
| 47 | + public class EnableCachingTests extends AbstractCacheAnnotationTests { | ||
| 48 | 48 | ||
| 49 | 49 | /** hook into superclass suite of tests */ | |
| 50 | 50 | @Override | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -24,7 +24,6 @@ | |||
| 24 | 24 | * runs against EhCache 2.x with the EhCache-JCache add-on. | |
| 25 | 25 | * | |
| 26 | 26 | * @author Juergen Hoeller | |
| 27 | - * @since 4.2.1 | ||
| 28 | 27 | */ | |
| 29 | 28 | public class JCacheEhCache3AnnotationTests extends JCacheEhCacheAnnotationTests { | |
| 30 | 29 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments