|
| 1 | +/* |
| 2 | + * Copyright 2012-2018 the original author or authors. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package org.springframework.boot.autoconfigure.orm.jpa; |
| 18 | + |
| 19 | +import org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory; |
| 20 | +import org.junit.Test; |
| 21 | +import org.junit.runner.RunWith; |
| 22 | + |
| 23 | +import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 24 | +import org.springframework.boot.autoconfigure.cache.CacheAutoConfiguration; |
| 25 | +import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; |
| 26 | +import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
| 27 | +import org.springframework.boot.testsupport.runner.classpath.ClassPathExclusions; |
| 28 | +import org.springframework.boot.testsupport.runner.classpath.ModifiedClassPathRunner; |
| 29 | +import org.springframework.cache.annotation.EnableCaching; |
| 30 | +import org.springframework.context.annotation.Configuration; |
| 31 | + |
| 32 | +import static org.assertj.core.api.Assertions.assertThat; |
| 33 | + |
| 34 | +/** |
| 35 | + * Tests for Hibernate 2nd level cache with ehcache2. |
| 36 | + * |
| 37 | + * @author Stephane Nicoll |
| 38 | + */ |
| 39 | +@RunWith(ModifiedClassPathRunner.class) |
| 40 | +@ClassPathExclusions("ehcache-3*.jar") |
| 41 | +public class Hibernate2ndLevelCacheEhCacheIntegrationTests { |
| 42 | + |
| 43 | + private final ApplicationContextRunner contextRunner = new ApplicationContextRunner() |
| 44 | + .withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class, |
| 45 | + DataSourceAutoConfiguration.class, |
| 46 | + HibernateJpaAutoConfiguration.class)) |
| 47 | + .withPropertyValues("spring.datasource.initialization-mode=never") |
| 48 | + .withUserConfiguration(TestConfiguration.class); |
| 49 | + |
| 50 | + @Test |
| 51 | + public void hibernate2ndLevelCacheWithEhCache2() { |
| 52 | + this.contextRunner |
| 53 | + .withPropertyValues("spring.cache.type=ehcache", |
| 54 | + "spring.jpa.properties.hibernate.cache.region.factory_class=" |
| 55 | + + SingletonEhCacheRegionFactory.class.getName()) |
| 56 | + .run((context) -> assertThat(context).hasNotFailed()); |
| 57 | + } |
| 58 | + |
| 59 | + @Configuration |
| 60 | + @EnableCaching |
| 61 | + static class TestConfiguration { |
| 62 | + |
| 63 | + } |
| 64 | + |
| 65 | +} |
0 commit comments