From 6684c8c69ba731103ad744a69d0bcc79f94fe2d3 Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Sat, 11 Jun 2016 11:26:23 +0200 Subject: [PATCH] #190 - More simplifications for Spring Boot 1.4 M3. Replaced all occurrences of @SpringApplicationConfiguration with @SpringBootTest. Using SpringRunner instead of @SpringJUnit4ClassRunner now. --- .../ElasticsearchOperationsTest.java | 8 +- .../jpa/eclipselink/Application.java | 2 +- .../CustomerRepositoryIntegrationTests.java | 15 ++-- .../jpa/caching/CachingConfiguration.java | 8 +- .../jpa/custom/CustomRepositoryConfig.java | 8 +- .../jpa/customall/CustomRepositoryConfig.java | 8 +- .../jpa/simple/SimpleConfiguration.java | 8 +- .../jpa/auditing/AuditableUserSample.java | 9 +-- .../jpa/caching/CachingRepositoryTests.java | 14 ++-- .../UserRepositoryCustomizationTests.java | 10 +-- .../UserRepositoryCustomizationTests.java | 10 +-- .../jpa/simple/SimpleUserRepositoryTests.java | 10 +-- .../ApplicationConfiguration.java | 14 ++-- .../InterceptorIntegrationTest.java | 10 +-- .../jpa/java8/AuditingConfiguration.java | 12 +-- .../jpa/java8/Java8IntegrationTests.java | 10 +-- .../StoredProcedureConfiguration.java | 8 +- .../UserRepositoryIntegrationTests.java | 10 +-- .../jpa/multipleds/Application.java | 4 +- .../customer/CustomerRepositoryTests.java | 10 +-- .../order/OrderRepositoryTests.java | 9 +-- .../ApplicationConfiguration.java | 0 ...RepositoryInheritanceIntegrationTests.java | 8 +- .../UserRepositoryIntegrationTests.java | 8 +- .../jpa/security/SecurityConfiguration.java | 8 +- .../security/SecurityIntegrationTests.java | 10 +-- .../jpa/showcase/AbstractShowcaseTest.java | 20 ++--- .../map/PersonRepositoryIntegrationTest.java | 17 ++--- .../aggregation/ApplicationConfiguration.java | 8 +- .../OrderRepositoryIntegrationTests.java | 10 +-- .../advanced/ApplicationConfiguration.java | 8 +- .../customer/ApplicationConfiguration.java | 8 +- .../advanced/AdvancedIntegrationTests.java | 11 +-- .../advanced/ServersideScriptTests.java | 11 +-- .../CustomerRepositoryIntegrationTest.java | 10 +-- .../mongodb/geojson/StoreRepositoryTests.java | 10 +-- .../PersonRepositoryIntegrationTest.java | 12 +-- .../ApplicationConfiguration.java | 0 .../ContactRepositoryIntegrationTests.java | 8 +- .../MongoOperationsIntegrationTests.java | 8 +- .../UserRepositoryIntegrationTests.java | 8 +- .../security/ApplicationConfiguration.java | 13 +--- .../PersonRepositoryIntegrationTest.java | 10 +-- .../textsearch/MongoTestConfiguration.java | 9 +-- .../textsearch/TextSearchRepositoryTests.java | 10 +-- .../textsearch/TextSearchTemplateTests.java | 10 +-- .../src/test/resources/application.properties | 1 + .../src/test/resources/logback.xml | 16 ---- .../multistore/ApplicationConfiguration.java | 13 +--- .../ApplicationConfigurationTest.java | 16 ++-- .../sentinel/RedisSentinelApplication.java} | 30 ++++---- .../src/main/resources/application.properties | 1 + .../src/test/resources/logback.xml | 14 ---- .../redis/RedisTestConfiguration.java | 11 +-- .../redis/commands/KeyOperationsTests.java | 15 ++-- .../src/test/resources/application.properties | 1 + redis/example/src/test/resources/logback.xml | 14 ---- .../repositories/PersonRepositoryTests.java | 4 +- .../springdata/rest/headers/Application.java | 5 +- .../headers/ApplicationIntegrationTests.java | 14 ++-- .../rest/headers/WebIntegrationTests.java | 16 ++-- .../ApplicationIntegrationTests.java | 10 +-- .../rest/projections/Application.java | 9 +-- .../ApplicationIntegrationTests.java | 14 ++-- .../springdata/rest/security/Application.java | 69 +++++++++++++++-- .../rest/security/SecurityConfiguration.java | 75 ------------------- .../security/MethodLevelSecurityTests.java | 16 ++-- .../rest/security/UrlLevelSecurityTests.java | 10 +-- .../rest/stores/web/StoresController.java | 5 +- .../rest/stores/StarbucksClient.java | 21 +++--- .../StoreRepositoryIntegrationTests.java | 10 +-- .../springdata/rest/uris/Application.java | 7 +- .../rest/uris/WebIntegrationTests.java | 17 ++--- .../solr/AdvancedSolrRepositoryTests.java | 24 +++--- .../solr/BasicSolrRepositoryTests.java | 16 ++-- .../solr/SolrTestConfiguration.java | 17 ++--- .../src/test/resources/application.properties | 1 + solr/example/src/test/resources/logback.xml | 16 ---- .../springdata/solr/SolrRepositoryTests.java | 24 +++--- .../solr/SolrTestConfiguration.java | 15 ++-- .../src/test/resources/application.properties | 1 + .../src/test/resources/logback.xml | 16 ---- .../src/main/java/example/Application.java | 10 +-- .../users/AbstractIntegrationTests.java | 12 ++- .../main/java/example/users/Application.java | 18 +---- .../java/example/users/UserInitializer.java | 15 +--- 86 files changed, 411 insertions(+), 640 deletions(-) rename jpa/query-by-example/src/{test => main}/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java (100%) rename mongodb/query-by-example/src/{test => main}/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java (100%) rename mongodb/text-search/src/{test => main}/java/example/springdata/mongodb/textsearch/MongoTestConfiguration.java (88%) create mode 100644 mongodb/text-search/src/test/resources/application.properties delete mode 100644 mongodb/text-search/src/test/resources/logback.xml rename redis/cluster-sentinel/src/{test/java/example/springdata/redis/sentinel/RedisSentinelApplicationConfig.java => main/java/example/springdata/redis/sentinel/RedisSentinelApplication.java} (84%) create mode 100644 redis/cluster-sentinel/src/main/resources/application.properties delete mode 100644 redis/cluster-sentinel/src/test/resources/logback.xml create mode 100644 redis/example/src/test/resources/application.properties delete mode 100644 redis/example/src/test/resources/logback.xml delete mode 100644 rest/security/src/main/java/example/springdata/rest/security/SecurityConfiguration.java create mode 100644 solr/example/src/test/resources/application.properties delete mode 100644 solr/example/src/test/resources/logback.xml create mode 100644 solr/managed-schema/src/test/resources/application.properties delete mode 100644 solr/managed-schema/src/test/resources/logback.xml diff --git a/elasticsearch/example/src/test/java/example/springdata/elasticsearch/conference/ElasticsearchOperationsTest.java b/elasticsearch/example/src/test/java/example/springdata/elasticsearch/conference/ElasticsearchOperationsTest.java index d00ef7b2..76053320 100644 --- a/elasticsearch/example/src/test/java/example/springdata/elasticsearch/conference/ElasticsearchOperationsTest.java +++ b/elasticsearch/example/src/test/java/example/springdata/elasticsearch/conference/ElasticsearchOperationsTest.java @@ -25,12 +25,12 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.geo.GeoPoint; import org.springframework.data.elasticsearch.core.query.Criteria; import org.springframework.data.elasticsearch.core.query.CriteriaQuery; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Test case to show Spring Data Elasticsearch functionality. @@ -39,8 +39,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke * @author Christoph Strobl */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = ApplicationConfiguration.class) public class ElasticsearchOperationsTest { private static final SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd"); diff --git a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/Application.java b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/Application.java index 018ee82d..95920b81 100644 --- a/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/Application.java +++ b/jpa/eclipselink/src/main/java/example/springdata/jpa/eclipselink/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. diff --git a/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java b/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java index 06b29240..93de48bc 100644 --- a/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java +++ b/jpa/eclipselink/src/test/java/example/springdata/jpa/eclipselink/CustomerRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,23 +18,22 @@ package example.springdata.jpa.eclipselink; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -import example.springdata.jpa.eclipselink.Application; -import example.springdata.jpa.eclipselink.Customer; -import example.springdata.jpa.eclipselink.CustomerRepository; +import javax.transaction.Transactional; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test for {@link CustomerRepository}. * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest +@Transactional public class CustomerRepositoryIntegrationTests { @Autowired CustomerRepository customers; diff --git a/jpa/example/src/main/java/example/springdata/jpa/caching/CachingConfiguration.java b/jpa/example/src/main/java/example/springdata/jpa/caching/CachingConfiguration.java index a92bcd23..209900b3 100644 --- a/jpa/example/src/main/java/example/springdata/jpa/caching/CachingConfiguration.java +++ b/jpa/example/src/main/java/example/springdata/jpa/caching/CachingConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,14 +17,13 @@ package example.springdata.jpa.caching; import java.util.Arrays; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.cache.support.SimpleCacheManager; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; /** * Java config to use Spring Data JPA alongside the Spring caching support. @@ -32,9 +31,8 @@ import org.springframework.context.annotation.Configuration; * @author Oliver Gierke * @author Thomas Darimont */ -@Configuration @EnableCaching -@EnableAutoConfiguration +@SpringBootApplication class CachingConfiguration { @Bean diff --git a/jpa/example/src/main/java/example/springdata/jpa/custom/CustomRepositoryConfig.java b/jpa/example/src/main/java/example/springdata/jpa/custom/CustomRepositoryConfig.java index 735b80f8..a0fe8036 100644 --- a/jpa/example/src/main/java/example/springdata/jpa/custom/CustomRepositoryConfig.java +++ b/jpa/example/src/main/java/example/springdata/jpa/custom/CustomRepositoryConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,7 @@ */ package example.springdata.jpa.custom; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; /** * Sample configuration to bootstrap Spring Data JPA through JavaConfig @@ -24,6 +23,5 @@ import org.springframework.context.annotation.Configuration; * @author Thomas Darimont * @author Oliver Gierke */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication class CustomRepositoryConfig {} diff --git a/jpa/example/src/main/java/example/springdata/jpa/customall/CustomRepositoryConfig.java b/jpa/example/src/main/java/example/springdata/jpa/customall/CustomRepositoryConfig.java index 63344cee..f7b59c1e 100644 --- a/jpa/example/src/main/java/example/springdata/jpa/customall/CustomRepositoryConfig.java +++ b/jpa/example/src/main/java/example/springdata/jpa/customall/CustomRepositoryConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,7 @@ */ package example.springdata.jpa.customall; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.jpa.repository.config.EnableJpaRepositories; /** @@ -27,7 +26,6 @@ import org.springframework.data.jpa.repository.config.EnableJpaRepositories; * @author Oliver Gierke * @soundtrack Tim Neuhaus - As life found you (The Cabinet) */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication @EnableJpaRepositories(repositoryBaseClass = ExtendedJpaRepository.class) class CustomRepositoryConfig {} diff --git a/jpa/example/src/main/java/example/springdata/jpa/simple/SimpleConfiguration.java b/jpa/example/src/main/java/example/springdata/jpa/simple/SimpleConfiguration.java index 92955b51..c628d7bf 100644 --- a/jpa/example/src/main/java/example/springdata/jpa/simple/SimpleConfiguration.java +++ b/jpa/example/src/main/java/example/springdata/jpa/simple/SimpleConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,12 +15,10 @@ */ package example.springdata.jpa.simple; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @author Oliver Gierke */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication class SimpleConfiguration {} diff --git a/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java b/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java index c4f67566..16f12b38 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java +++ b/jpa/example/src/test/java/example/springdata/jpa/auditing/AuditableUserSample.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.jpa.domain.support.AuditingEntityListener; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.util.ReflectionTestUtils; import org.springframework.transaction.annotation.Transactional; @@ -31,10 +31,9 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @author Thomas Darimont */ - -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @Transactional -@SpringBootTest(classes = AuditingConfiguration.class) +@SpringBootTest public class AuditableUserSample { @Autowired AuditableUserRepository repository; diff --git a/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java b/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java index 26250013..08f7e1d5 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/caching/CachingRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,27 +21,23 @@ import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cache.Cache; import org.springframework.cache.Cache.ValueWrapper; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.Cacheable; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; -import example.springdata.jpa.caching.CachingConfiguration; -import example.springdata.jpa.caching.CachingUserRepository; -import example.springdata.jpa.caching.User; - /** * Integration test to show how to use {@link Cacheable} with a Spring Data repository. * * @author Oliver Gierke * @author Thomas Darimont */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @Transactional -@ContextConfiguration(classes = CachingConfiguration.class) +@SpringBootTest public abstract class CachingRepositoryTests { @Autowired CachingUserRepository repository; diff --git a/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java b/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java index 301ad288..930bfeb2 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/custom/UserRepositoryCustomizationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,8 +22,8 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -32,9 +32,9 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @author Thomas Darimont */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @Transactional -@ContextConfiguration(classes = CustomRepositoryConfig.class) +@SpringBootTest // @ActiveProfiles("jdbc") // Uncomment @ActiveProfiles to enable the JDBC Implementation of the custom repository public class UserRepositoryCustomizationTests { diff --git a/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java b/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java index 33efa15e..12684266 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/customall/UserRepositoryCustomizationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,8 +21,8 @@ import static org.junit.Assert.*; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -31,9 +31,9 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @soundtrack Elen - It's you (Elen) */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @Transactional -@ContextConfiguration(classes = CustomRepositoryConfig.class) +@SpringBootApplication public class UserRepositoryCustomizationTests { @Autowired UserRepository repository; diff --git a/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java b/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java index 994cae9f..1322810d 100644 --- a/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java +++ b/jpa/example/src/test/java/example/springdata/jpa/simple/SimpleUserRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2014 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,11 +28,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Slice; import org.springframework.data.domain.Sort; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -42,9 +42,9 @@ import org.springframework.transaction.annotation.Transactional; * @author Thomas Darimont * @author Christoph Strobl */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @Transactional -@ContextConfiguration(classes = SimpleConfiguration.class) +@SpringBootTest public class SimpleUserRepositoryTests { @Autowired SimpleUserRepository repository; diff --git a/jpa/interceptors/src/main/java/example/springdata/jpa/interceptors/ApplicationConfiguration.java b/jpa/interceptors/src/main/java/example/springdata/jpa/interceptors/ApplicationConfiguration.java index 54c690ce..40d1920d 100644 --- a/jpa/interceptors/src/main/java/example/springdata/jpa/interceptors/ApplicationConfiguration.java +++ b/jpa/interceptors/src/main/java/example/springdata/jpa/interceptors/ApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,18 +19,15 @@ import org.springframework.aop.Advisor; import org.springframework.aop.aspectj.AspectJExpressionPointcut; import org.springframework.aop.interceptor.CustomizableTraceInterceptor; import org.springframework.aop.support.DefaultPointcutAdvisor; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; -@Configuration +@SpringBootApplication @EnableAspectJAutoProxy -@EnableAutoConfiguration public class ApplicationConfiguration { - @Bean - public CustomizableTraceInterceptor interceptor() { + public @Bean CustomizableTraceInterceptor interceptor() { CustomizableTraceInterceptor interceptor = new CustomizableTraceInterceptor(); interceptor.setEnterMessage("Entering $[methodName]($[arguments])."); @@ -39,8 +36,7 @@ public class ApplicationConfiguration { return interceptor; } - @Bean - public Advisor traceAdvisor() { + public @Bean Advisor traceAdvisor() { AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut(); pointcut.setExpression("execution(public * org.springframework.data.repository.Repository+.*(..))"); diff --git a/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java b/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java index b3ee6a01..bd1a11e2 100644 --- a/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java +++ b/jpa/interceptors/src/test/java/example/springdata/jpa/interceptors/InterceptorIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2014 the original author or authors. + * Copyright 2012-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,11 +18,11 @@ package example.springdata.jpa.interceptors; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class InterceptorIntegrationTest { @Autowired CustomerRepository repository; diff --git a/jpa/java8/src/main/java/example/springdata/jpa/java8/AuditingConfiguration.java b/jpa/java8/src/main/java/example/springdata/jpa/java8/AuditingConfiguration.java index 528449b7..78238366 100644 --- a/jpa/java8/src/main/java/example/springdata/jpa/java8/AuditingConfiguration.java +++ b/jpa/java8/src/main/java/example/springdata/jpa/java8/AuditingConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,18 +15,14 @@ */ package example.springdata.jpa.java8; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.orm.jpa.EntityScan; -import org.springframework.context.annotation.Configuration; import org.springframework.data.jpa.convert.threeten.Jsr310JpaConverters; import org.springframework.data.jpa.repository.config.EnableJpaAuditing; import org.springframework.scheduling.annotation.EnableAsync; -@Configuration @EnableAsync -@EnableAutoConfiguration +@SpringBootApplication @EntityScan(basePackageClasses = { AuditingConfiguration.class, Jsr310JpaConverters.class }) @EnableJpaAuditing -class AuditingConfiguration { - -} +class AuditingConfiguration {} diff --git a/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java b/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java index f87f1eb0..9a5afc7f 100644 --- a/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java +++ b/jpa/java8/src/test/java/example/springdata/jpa/java8/Java8IntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2013-2015 the original author or authors. + * Copyright 2013-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,8 +29,8 @@ import java.util.stream.Stream; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -40,8 +40,8 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @author Thomas Darimont */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = AuditingConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest @Transactional @Slf4j public class Java8IntegrationTests { diff --git a/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/StoredProcedureConfiguration.java b/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/StoredProcedureConfiguration.java index 7278fe42..0cbb1f0f 100644 --- a/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/StoredProcedureConfiguration.java +++ b/jpa/jpa21/src/main/java/example/springdata/jpa/storedprocedures/StoredProcedureConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,13 +15,11 @@ */ package example.springdata.jpa.storedprocedures; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @author Thomas Darimont * @author Oliver Gierke */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication class StoredProcedureConfiguration {} diff --git a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java index 8f671a75..7cb608b1 100644 --- a/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java +++ b/jpa/jpa21/src/test/java/example/springdata/jpa/storedprocedures/UserRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import javax.persistence.StoredProcedureQuery; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -35,9 +35,9 @@ import org.springframework.transaction.annotation.Transactional; * @author Thomas Darimont * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) +@SpringBootTest @Transactional -@SpringApplicationConfiguration(classes = StoredProcedureConfiguration.class) public class UserRepositoryIntegrationTests { @Autowired UserRepository repository; diff --git a/jpa/multiple-datasources/src/main/java/example/springdata/jpa/multipleds/Application.java b/jpa/multiple-datasources/src/main/java/example/springdata/jpa/multipleds/Application.java index 38fb7f6f..71742af1 100644 --- a/jpa/multiple-datasources/src/main/java/example/springdata/jpa/multipleds/Application.java +++ b/jpa/multiple-datasources/src/main/java/example/springdata/jpa/multipleds/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -45,7 +45,7 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; * @see example.springdata.jpa.multipleds.order.OrderConfig */ @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, HibernateJpaAutoConfiguration.class, - DataSourceTransactionManagerAutoConfiguration.class, DevToolsDataSourceAutoConfiguration.class }) + DataSourceTransactionManagerAutoConfiguration.class }) @EnableTransactionManagement public class Application { diff --git a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java index a635e7ff..382464fd 100644 --- a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java +++ b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/customer/CustomerRepositoryTests.java @@ -18,8 +18,6 @@ package example.springdata.jpa.multipleds.customer; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -import example.springdata.jpa.multipleds.Application; - import java.util.Optional; import javax.persistence.EntityManager; @@ -28,8 +26,8 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Qualifier; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -37,8 +35,8 @@ import org.springframework.transaction.annotation.Transactional; * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest @Transactional(transactionManager = "customerTransactionManager") public class CustomerRepositoryTests { diff --git a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java index a1b30406..b59bfc40 100644 --- a/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java +++ b/jpa/multiple-datasources/src/test/java/example/springdata/jpa/multipleds/order/OrderRepositoryTests.java @@ -18,14 +18,13 @@ package example.springdata.jpa.multipleds.order; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import example.springdata.jpa.multipleds.Application; import example.springdata.jpa.multipleds.customer.CustomerRepository; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -33,8 +32,8 @@ import org.springframework.transaction.annotation.Transactional; * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest @Transactional(transactionManager = "orderTransactionManager") public class OrderRepositoryTests { diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java b/jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java similarity index 100% rename from jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java rename to jpa/query-by-example/src/main/java/example/springdata/jpa/querybyexample/ApplicationConfiguration.java diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java index 04784ba8..cf42560c 100644 --- a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java +++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryInheritanceIntegrationTests.java @@ -22,9 +22,9 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -34,9 +34,9 @@ import org.springframework.transaction.annotation.Transactional; * @author Mark Paluch * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @Transactional -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@SpringBootTest public class UserRepositoryInheritanceIntegrationTests { @Autowired UserRepository repository; diff --git a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java index 8f0f43fb..4d9655a9 100644 --- a/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java +++ b/jpa/query-by-example/src/test/java/example/springdata/jpa/querybyexample/UserRepositoryIntegrationTests.java @@ -25,10 +25,10 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher.StringMatcher; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -38,9 +38,9 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke */ @SuppressWarnings("unused") -@RunWith(SpringJUnit4ClassRunner.class) +@RunWith(SpringRunner.class) @Transactional -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@SpringBootTest public class UserRepositoryIntegrationTests { @Autowired UserRepository repository; diff --git a/jpa/security/src/main/java/example/springdata/jpa/security/SecurityConfiguration.java b/jpa/security/src/main/java/example/springdata/jpa/security/SecurityConfiguration.java index 0c83daaa..c3156e48 100644 --- a/jpa/security/src/main/java/example/springdata/jpa/security/SecurityConfiguration.java +++ b/jpa/security/src/main/java/example/springdata/jpa/security/SecurityConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,9 +15,8 @@ */ package example.springdata.jpa.security; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.data.repository.query.spi.EvaluationContextExtension; import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension; @@ -25,8 +24,7 @@ import org.springframework.security.data.repository.query.SecurityEvaluationCont * @author Oliver Gierke * @author Thomas Darimont */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication class SecurityConfiguration { @Bean diff --git a/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java b/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java index dc906b72..48928a56 100644 --- a/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java +++ b/jpa/security/src/test/java/example/springdata/jpa/security/SecurityIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.transaction.annotation.Transactional; /** @@ -40,8 +40,8 @@ import org.springframework.transaction.annotation.Transactional; * @author Oliver Gierke * @author Thomas Darimont */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = SecurityConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest @Transactional public class SecurityIntegrationTests { diff --git a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java index 6db3ac01..22e11b3f 100644 --- a/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java +++ b/jpa/showcase/src/test/java/example/springdata/jpa/showcase/AbstractShowcaseTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2011-2014 the original author or authors. + * Copyright 2011-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,29 +15,21 @@ */ package example.springdata.jpa.showcase; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.AbstractTransactionalJUnit4SpringContextTests; import org.springframework.test.context.transaction.BeforeTransaction; import org.springframework.transaction.annotation.Transactional; -import example.springdata.jpa.showcase.AbstractShowcaseTest.TestConfig; - /** * @author Oliver Gierke */ -@SpringApplicationConfiguration(classes = TestConfig.class) +@SpringBootTest @Transactional public abstract class AbstractShowcaseTest extends AbstractTransactionalJUnit4SpringContextTests { - @Configuration - @EnableAutoConfiguration - @ComponentScan - static class TestConfig { - - } + @SpringBootApplication + static class TestConfig {} @BeforeTransaction public void setupData() throws Exception { diff --git a/map/src/test/java/example/springdata/map/PersonRepositoryIntegrationTest.java b/map/src/test/java/example/springdata/map/PersonRepositoryIntegrationTest.java index db8c0896..608f7640 100644 --- a/map/src/test/java/example/springdata/map/PersonRepositoryIntegrationTest.java +++ b/map/src/test/java/example/springdata/map/PersonRepositoryIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,29 +18,26 @@ package example.springdata.map; import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; -import example.springdata.map.Person; -import example.springdata.map.PersonRepository; - import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.map.repository.config.EnableMapRepositories; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests for {@link PersonRepository}. * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration +@RunWith(SpringRunner.class) +@SpringBootTest public class PersonRepositoryIntegrationTest { - @Configuration + @SpringBootApplication @EnableMapRepositories static class Config {} diff --git a/mongodb/aggregation/src/main/java/example/springdata/mongodb/aggregation/ApplicationConfiguration.java b/mongodb/aggregation/src/main/java/example/springdata/mongodb/aggregation/ApplicationConfiguration.java index be8238b2..2d07f920 100644 --- a/mongodb/aggregation/src/main/java/example/springdata/mongodb/aggregation/ApplicationConfiguration.java +++ b/mongodb/aggregation/src/main/java/example/springdata/mongodb/aggregation/ApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,7 @@ */ package example.springdata.mongodb.aggregation; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import com.mongodb.MongoClient; @@ -26,6 +25,5 @@ import com.mongodb.MongoClient; * * @author Oliver Gierke */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication public class ApplicationConfiguration {} diff --git a/mongodb/aggregation/src/test/java/example/springdata/mongodb/aggregation/OrderRepositoryIntegrationTests.java b/mongodb/aggregation/src/test/java/example/springdata/mongodb/aggregation/OrderRepositoryIntegrationTests.java index ad2182b1..f261c7c0 100644 --- a/mongodb/aggregation/src/test/java/example/springdata/mongodb/aggregation/OrderRepositoryIntegrationTests.java +++ b/mongodb/aggregation/src/test/java/example/springdata/mongodb/aggregation/OrderRepositoryIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,8 +25,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests for {@link OrderRepository}. @@ -34,8 +34,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Thomas Darimont * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class OrderRepositoryIntegrationTests { @Autowired OrderRepository repository; diff --git a/mongodb/example/src/main/java/example/springdata/mongodb/advanced/ApplicationConfiguration.java b/mongodb/example/src/main/java/example/springdata/mongodb/advanced/ApplicationConfiguration.java index 4bc0a9de..23d58f7e 100644 --- a/mongodb/example/src/main/java/example/springdata/mongodb/advanced/ApplicationConfiguration.java +++ b/mongodb/example/src/main/java/example/springdata/mongodb/advanced/ApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,7 @@ import javax.annotation.PostConstruct; import javax.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.mongodb.core.MongoOperations; import com.mongodb.BasicDBObject; @@ -31,8 +30,7 @@ import com.mongodb.MongoClient; * * @author Christoph Strobl */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication class ApplicationConfiguration { static final String SYSTEM_PROFILE_DB = "system.profile"; diff --git a/mongodb/example/src/main/java/example/springdata/mongodb/customer/ApplicationConfiguration.java b/mongodb/example/src/main/java/example/springdata/mongodb/customer/ApplicationConfiguration.java index e5af31e3..e81796fd 100644 --- a/mongodb/example/src/main/java/example/springdata/mongodb/customer/ApplicationConfiguration.java +++ b/mongodb/example/src/main/java/example/springdata/mongodb/customer/ApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,8 +15,7 @@ */ package example.springdata.mongodb.customer; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import com.mongodb.MongoClient; @@ -26,6 +25,5 @@ import com.mongodb.MongoClient; * * @author Oliver Gierke */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication class ApplicationConfiguration {} diff --git a/mongodb/example/src/test/java/example/springdata/mongodb/advanced/AdvancedIntegrationTests.java b/mongodb/example/src/test/java/example/springdata/mongodb/advanced/AdvancedIntegrationTests.java index ade14f56..d3f89a5d 100644 --- a/mongodb/example/src/test/java/example/springdata/mongodb/advanced/AdvancedIntegrationTests.java +++ b/mongodb/example/src/test/java/example/springdata/mongodb/advanced/AdvancedIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,11 +24,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Sort; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.query.Meta; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import com.mongodb.BasicDBObject; import com.mongodb.DBCursor; @@ -36,9 +36,10 @@ import com.mongodb.DBObject; /** * @author Christoph Strobl + * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class AdvancedIntegrationTests { @Autowired AdvancedRepository repository; diff --git a/mongodb/example/src/test/java/example/springdata/mongodb/advanced/ServersideScriptTests.java b/mongodb/example/src/test/java/example/springdata/mongodb/advanced/ServersideScriptTests.java index 352a2eba..a7a20fdf 100644 --- a/mongodb/example/src/test/java/example/springdata/mongodb/advanced/ServersideScriptTests.java +++ b/mongodb/example/src/test/java/example/springdata/mongodb/advanced/ServersideScriptTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,20 +27,21 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.script.ExecutableMongoScript; import org.springframework.data.mongodb.core.script.NamedMongoScript; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; /** * @author Christoph Strobl + * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class ServersideScriptTests { @Autowired AdvancedRepository repository; diff --git a/mongodb/example/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java b/mongodb/example/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java index 4419cb95..1b402206 100644 --- a/mongodb/example/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java +++ b/mongodb/example/src/test/java/example/springdata/mongodb/customer/CustomerRepositoryIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,7 +24,7 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.geo.Distance; import org.springframework.data.geo.GeoResults; import org.springframework.data.geo.Metrics; @@ -32,15 +32,15 @@ import org.springframework.data.geo.Point; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.index.GeospatialIndex; import org.springframework.data.querydsl.QSort; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test for {@link CustomerRepository}. * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class CustomerRepositoryIntegrationTest { @Autowired CustomerRepository repository; diff --git a/mongodb/geo-json/src/test/java/example/springdata/mongodb/geojson/StoreRepositoryTests.java b/mongodb/geo-json/src/test/java/example/springdata/mongodb/geojson/StoreRepositoryTests.java index 3f6314de..354e8ba7 100644 --- a/mongodb/geo-json/src/test/java/example/springdata/mongodb/geojson/StoreRepositoryTests.java +++ b/mongodb/geo-json/src/test/java/example/springdata/mongodb/geojson/StoreRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package example.springdata.mongodb.geojson; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.geo.Point; import org.springframework.data.geo.Polygon; import org.springframework.data.mongodb.core.MongoOperations; @@ -27,7 +27,7 @@ import org.springframework.data.mongodb.core.geo.GeoJson; import org.springframework.data.mongodb.core.geo.GeoJsonPolygon; import org.springframework.data.mongodb.core.query.BasicQuery; import org.springframework.data.mongodb.core.query.Criteria; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; @@ -38,8 +38,8 @@ import com.mongodb.DBObject; * @author Christoph Strobl * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { ApplicationConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootTest public class StoreRepositoryTests { private static final GeoJsonPolygon GEO_JSON_POLYGON = new GeoJsonPolygon(new Point(-73.992514, 40.758934), diff --git a/mongodb/java8/src/test/java/example/springdata/mongodb/people/PersonRepositoryIntegrationTest.java b/mongodb/java8/src/test/java/example/springdata/mongodb/people/PersonRepositoryIntegrationTest.java index a236b053..e8dae8cd 100644 --- a/mongodb/java8/src/test/java/example/springdata/mongodb/people/PersonRepositoryIntegrationTest.java +++ b/mongodb/java8/src/test/java/example/springdata/mongodb/people/PersonRepositoryIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,19 +21,19 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.mapping.event.LoggingEventListener; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test for {@link PersonRepository}. * * @author Thomas Darimont - * @authot Oliver Gierke + * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class PersonRepositoryIntegrationTest { @Autowired PersonRepository repository; diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java b/mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java similarity index 100% rename from mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java rename to mongodb/query-by-example/src/main/java/example/springdata/mongodb/querybyexample/ApplicationConfiguration.java diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java index 01105e34..8820d4bc 100644 --- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java +++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/ContactRepositoryIntegrationTests.java @@ -25,11 +25,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher.StringMatcher; import org.springframework.data.mongodb.core.MongoOperations; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories for a case @@ -39,8 +39,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke * @soundtrack Paul van Dyk - VONYC Sessions Episode 496 with guest Armin van Buuren */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class ContactRepositoryIntegrationTests { @Autowired UserRepository userRepository; diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java index b403b49b..dbc76cb9 100644 --- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java +++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/MongoOperationsIntegrationTests.java @@ -28,12 +28,12 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher.StringMatcher; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.query.Query; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories. @@ -42,8 +42,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke */ @SuppressWarnings("unused") -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class MongoOperationsIntegrationTests { @Autowired MongoOperations operations; diff --git a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java index a5cb5ea9..8166f6a8 100644 --- a/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java +++ b/mongodb/query-by-example/src/test/java/example/springdata/mongodb/querybyexample/UserRepositoryIntegrationTests.java @@ -25,10 +25,10 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Example; import org.springframework.data.domain.ExampleMatcher.StringMatcher; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test showing the usage of MongoDB Query-by-Example support through Spring Data repositories. @@ -37,8 +37,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke */ @SuppressWarnings("unused") -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class UserRepositoryIntegrationTests { @Autowired UserRepository repository; diff --git a/mongodb/security/src/main/java/example/springdata/mongodb/security/ApplicationConfiguration.java b/mongodb/security/src/main/java/example/springdata/mongodb/security/ApplicationConfiguration.java index 7bc23845..49dd9d92 100644 --- a/mongodb/security/src/main/java/example/springdata/mongodb/security/ApplicationConfiguration.java +++ b/mongodb/security/src/main/java/example/springdata/mongodb/security/ApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,10 +16,7 @@ package example.springdata.mongodb.security; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.context.annotation.Bean; import org.springframework.data.mongodb.core.mapping.event.LoggingEventListener; -import org.springframework.data.repository.query.spi.EvaluationContextExtension; -import org.springframework.security.data.repository.query.SecurityEvaluationContextExtension; /** * Simple configuration that registers a {@link LoggingEventListener} to demonstrate mapping behaviour when Java 8 @@ -28,10 +25,4 @@ import org.springframework.security.data.repository.query.SecurityEvaluationCont * @author Thomas Darimont */ @SpringBootApplication -class ApplicationConfiguration { - - @Bean - public EvaluationContextExtension securityExtension() { - return new SecurityEvaluationContextExtension(); - } -} +class ApplicationConfiguration {} diff --git a/mongodb/security/src/test/java/example/springdata/mongodb/security/PersonRepositoryIntegrationTest.java b/mongodb/security/src/test/java/example/springdata/mongodb/security/PersonRepositoryIntegrationTest.java index a0616833..1eda1264 100644 --- a/mongodb/security/src/test/java/example/springdata/mongodb/security/PersonRepositoryIntegrationTest.java +++ b/mongodb/security/src/test/java/example/springdata/mongodb/security/PersonRepositoryIntegrationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,11 +25,11 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.authority.SimpleGrantedAuthority; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test for {@link PersonRepository}. @@ -37,8 +37,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Thomas Darimont * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class PersonRepositoryIntegrationTest { @Autowired PersonRepository repository; diff --git a/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/MongoTestConfiguration.java b/mongodb/text-search/src/main/java/example/springdata/mongodb/textsearch/MongoTestConfiguration.java similarity index 88% rename from mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/MongoTestConfiguration.java rename to mongodb/text-search/src/main/java/example/springdata/mongodb/textsearch/MongoTestConfiguration.java index 1c0d4442..078e36fc 100644 --- a/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/MongoTestConfiguration.java +++ b/mongodb/text-search/src/main/java/example/springdata/mongodb/textsearch/MongoTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,7 +18,7 @@ package example.springdata.mongodb.textsearch; import javax.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; @@ -31,13 +31,12 @@ import org.springframework.data.repository.init.Jackson2RepositoryPopulatorFacto * @author Oliver Gierke */ @Configuration -@EnableAutoConfiguration +@SpringBootApplication public class MongoTestConfiguration { @Autowired MongoOperations operations; - @Bean - public Jackson2RepositoryPopulatorFactoryBean repositoryPopulator() { + public @Bean Jackson2RepositoryPopulatorFactoryBean repositoryPopulator() { Jackson2RepositoryPopulatorFactoryBean factoryBean = new Jackson2RepositoryPopulatorFactoryBean(); factoryBean.setResources(new Resource[] { new ClassPathResource("spring-blog.atom.json") }); diff --git a/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchRepositoryTests.java b/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchRepositoryTests.java index f6d94fd9..03b27239 100644 --- a/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchRepositoryTests.java +++ b/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,10 +22,10 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.mongodb.core.mapping.TextScore; import org.springframework.data.mongodb.core.query.TextCriteria; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests showing the text search functionality using repositories. @@ -34,8 +34,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke * @author Thomas Darimont */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { MongoTestConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootTest public class TextSearchRepositoryTests { @Autowired BlogPostRepository repo; diff --git a/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchTemplateTests.java b/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchTemplateTests.java index 4cd520f1..fe41db73 100644 --- a/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchTemplateTests.java +++ b/mongodb/text-search/src/test/java/example/springdata/mongodb/textsearch/TextSearchTemplateTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,18 +23,18 @@ import java.util.List; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.mongodb.core.MongoOperations; import org.springframework.data.mongodb.core.query.TextCriteria; import org.springframework.data.mongodb.core.query.TextQuery; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * @author Christoph Strobl * @author Thomas Darimont */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { MongoTestConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootTest public class TextSearchTemplateTests { @Autowired MongoOperations operations; diff --git a/mongodb/text-search/src/test/resources/application.properties b/mongodb/text-search/src/test/resources/application.properties new file mode 100644 index 00000000..e9170be4 --- /dev/null +++ b/mongodb/text-search/src/test/resources/application.properties @@ -0,0 +1 @@ +logging.level.example.springdata=INFO diff --git a/mongodb/text-search/src/test/resources/logback.xml b/mongodb/text-search/src/test/resources/logback.xml deleted file mode 100644 index f4b3ab75..00000000 --- a/mongodb/text-search/src/test/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - %d %5p %40.40c:%4L - %m%n - - - - - - - - - - diff --git a/multi-store/src/main/java/example/springdata/multistore/ApplicationConfiguration.java b/multi-store/src/main/java/example/springdata/multistore/ApplicationConfiguration.java index e27b09cc..59fcedeb 100644 --- a/multi-store/src/main/java/example/springdata/multistore/ApplicationConfiguration.java +++ b/multi-store/src/main/java/example/springdata/multistore/ApplicationConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,10 +15,7 @@ */ package example.springdata.multistore; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; -import org.springframework.data.jpa.repository.config.EnableJpaRepositories; -import org.springframework.data.mongodb.repository.config.EnableMongoRepositories; +import org.springframework.boot.autoconfigure.SpringBootApplication; import com.mongodb.MongoClient; @@ -28,9 +25,5 @@ import com.mongodb.MongoClient; * * @author Oliver Gierke */ -@Configuration -@EnableAutoConfiguration -// TODO: Remove explicit activation once Spring Boot has a more lenient repository detection -@EnableJpaRepositories -@EnableMongoRepositories +@SpringBootApplication public class ApplicationConfiguration {} diff --git a/multi-store/src/test/java/example/springdata/multistore/ApplicationConfigurationTest.java b/multi-store/src/test/java/example/springdata/multistore/ApplicationConfigurationTest.java index a5bb666a..66eff2b5 100644 --- a/multi-store/src/test/java/example/springdata/multistore/ApplicationConfigurationTest.java +++ b/multi-store/src/test/java/example/springdata/multistore/ApplicationConfigurationTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,26 +18,26 @@ package example.springdata.multistore; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; +import example.springdata.multistore.customer.Customer; +import example.springdata.multistore.shop.Order; + import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.ApplicationContext; import org.springframework.data.jpa.repository.support.JpaEntityInformation; import org.springframework.data.mongodb.repository.query.MongoEntityInformation; import org.springframework.data.repository.support.Repositories; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import example.springdata.multistore.customer.Customer; -import example.springdata.multistore.shop.Order; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test to check repository interfaces are assigned to the correct store modules. * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class ApplicationConfigurationTest { @Autowired ApplicationContext context; diff --git a/redis/cluster-sentinel/src/test/java/example/springdata/redis/sentinel/RedisSentinelApplicationConfig.java b/redis/cluster-sentinel/src/main/java/example/springdata/redis/sentinel/RedisSentinelApplication.java similarity index 84% rename from redis/cluster-sentinel/src/test/java/example/springdata/redis/sentinel/RedisSentinelApplicationConfig.java rename to redis/cluster-sentinel/src/main/java/example/springdata/redis/sentinel/RedisSentinelApplication.java index 79c476dc..a38192ef 100644 --- a/redis/cluster-sentinel/src/test/java/example/springdata/redis/sentinel/RedisSentinelApplicationConfig.java +++ b/redis/cluster-sentinel/src/main/java/example/springdata/redis/sentinel/RedisSentinelApplication.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,10 @@ import org.springframework.util.StopWatch; /** * @author Christoph Strobl + * @author Oliver Gierke */ @Configuration -public class RedisSentinelApplicationConfig { +public class RedisSentinelApplication { static final RedisSentinelConfiguration SENTINEL_CONFIG = new RedisSentinelConfiguration().master("mymaster") // .sentinel("localhost", 26379) // @@ -43,14 +44,9 @@ public class RedisSentinelApplicationConfig { public static void main(String[] args) throws Exception { - ApplicationContext context = SpringApplication.run(RedisSentinelApplicationConfig.class, args); - - RedisConnectionFactory factory = context.getBean(RedisConnectionFactory.class); - - StringRedisTemplate template = new StringRedisTemplate(); - template.setConnectionFactory(factory); - template.afterPropertiesSet(); + ApplicationContext context = SpringApplication.run(RedisSentinelApplication.class, args); + StringRedisTemplate template = context.getBean(StringRedisTemplate.class); template.opsForValue().set("loop-forever", "0"); StopWatch stopWatch = new StopWatch(); @@ -58,10 +54,13 @@ public class RedisSentinelApplicationConfig { while (true) { try { + String value = "IT:= " + template.opsForValue().increment("loop-forever", 1); printBackFromErrorStateInfoIfStopWatchIsRunning(stopWatch); System.out.println(value); + } catch (RuntimeException e) { + System.err.println(e.getCause().getMessage()); startStopWatchIfNotRunning(stopWatch); } @@ -70,21 +69,22 @@ public class RedisSentinelApplicationConfig { } } - @Bean - public RedisConnectionFactory connectionFactory() { + public @Bean StringRedisTemplate redisTemplate() { + return new StringRedisTemplate(connectionFactory()); + } + + public @Bean RedisConnectionFactory connectionFactory() { return new JedisConnectionFactory(sentinelConfig()); } - @Bean - public RedisSentinelConfiguration sentinelConfig() { + public @Bean RedisSentinelConfiguration sentinelConfig() { return SENTINEL_CONFIG; } /** * Clear database before shut down. */ - @PreDestroy - public void flushTestDb() { + public @PreDestroy void flushTestDb() { factory.getConnection().flushDb(); } diff --git a/redis/cluster-sentinel/src/main/resources/application.properties b/redis/cluster-sentinel/src/main/resources/application.properties new file mode 100644 index 00000000..b5c5e0b7 --- /dev/null +++ b/redis/cluster-sentinel/src/main/resources/application.properties @@ -0,0 +1 @@ +logging.level.root=INFO diff --git a/redis/cluster-sentinel/src/test/resources/logback.xml b/redis/cluster-sentinel/src/test/resources/logback.xml deleted file mode 100644 index 06e36318..00000000 --- a/redis/cluster-sentinel/src/test/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - %d %5p %40.40c:%4L - %m%n - - - - - - - - \ No newline at end of file diff --git a/redis/example/src/test/java/example/springdata/redis/RedisTestConfiguration.java b/redis/example/src/test/java/example/springdata/redis/RedisTestConfiguration.java index 406fea7c..a5d57692 100644 --- a/redis/example/src/test/java/example/springdata/redis/RedisTestConfiguration.java +++ b/redis/example/src/test/java/example/springdata/redis/RedisTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,13 @@ package example.springdata.redis; import javax.annotation.PreDestroy; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.Configuration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.redis.connection.RedisConnectionFactory; /** * @author Christoph Strobl */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication public class RedisTestConfiguration { @Autowired RedisConnectionFactory factory; @@ -34,8 +32,7 @@ public class RedisTestConfiguration { /** * Clear database before shut down. */ - @PreDestroy - public void flushTestDb() { + public @PreDestroy void flushTestDb() { factory.getConnection().flushDb(); } } diff --git a/redis/example/src/test/java/example/springdata/redis/commands/KeyOperationsTests.java b/redis/example/src/test/java/example/springdata/redis/commands/KeyOperationsTests.java index 93284e45..dd5d3f42 100644 --- a/redis/example/src/test/java/example/springdata/redis/commands/KeyOperationsTests.java +++ b/redis/example/src/test/java/example/springdata/redis/commands/KeyOperationsTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package example.springdata.redis.commands; +import example.springdata.redis.test.util.RequiresRedisServer; + import java.util.Iterator; import java.util.Set; import java.util.UUID; @@ -24,25 +26,22 @@ import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.redis.connection.RedisConnection; import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.Cursor; import org.springframework.data.redis.core.ScanOptions; import org.springframework.data.redis.serializer.RedisSerializer; import org.springframework.data.redis.serializer.StringRedisSerializer; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import example.springdata.redis.RedisTestConfiguration; -import example.springdata.redis.test.util.RequiresRedisServer; +import org.springframework.test.context.junit4.SpringRunner; /** * Show usage of operations on redis keys using low level API provided by {@link RedisConnection}. * * @author Christoph Strobl */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { RedisTestConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootApplication public class KeyOperationsTests { // we only want to run this tests when redis is up an running diff --git a/redis/example/src/test/resources/application.properties b/redis/example/src/test/resources/application.properties new file mode 100644 index 00000000..bac6605c --- /dev/null +++ b/redis/example/src/test/resources/application.properties @@ -0,0 +1 @@ +logging.level.root=WARN diff --git a/redis/example/src/test/resources/logback.xml b/redis/example/src/test/resources/logback.xml deleted file mode 100644 index 61c86dd9..00000000 --- a/redis/example/src/test/resources/logback.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - %d %5p %40.40c:%4L - %m%n - - - - - - - - \ No newline at end of file diff --git a/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java b/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java index d72d6153..48cf0e12 100644 --- a/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java +++ b/redis/repositories/src/test/java/example/springdata/redis/repositories/PersonRepositoryTests.java @@ -35,7 +35,7 @@ import org.junit.Test; import org.junit.rules.RuleChain; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; @@ -49,7 +49,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke */ @RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = ApplicationConfiguration.class) +@SpringBootTest(classes = ApplicationConfiguration.class) public class PersonRepositoryTests { /** diff --git a/rest/headers/src/main/java/example/springdata/rest/headers/Application.java b/rest/headers/src/main/java/example/springdata/rest/headers/Application.java index f15c66fa..9f0bebbf 100644 --- a/rest/headers/src/main/java/example/springdata/rest/headers/Application.java +++ b/rest/headers/src/main/java/example/springdata/rest/headers/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -38,8 +38,7 @@ public class Application { @Autowired CustomerRepository customers; - @PostConstruct - public void init() { + public @PostConstruct void init() { customers.save(new Customer("Dave", "Matthews", Gender.MALE, // new Address("4711 Some Place", "54321", "Charlottesville", "VA"))); } diff --git a/rest/headers/src/test/java/example/springdata/rest/headers/ApplicationIntegrationTests.java b/rest/headers/src/test/java/example/springdata/rest/headers/ApplicationIntegrationTests.java index 746f9fae..73973f94 100644 --- a/rest/headers/src/test/java/example/springdata/rest/headers/ApplicationIntegrationTests.java +++ b/rest/headers/src/test/java/example/springdata/rest/headers/ApplicationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,15 +18,11 @@ package example.springdata.rest.headers; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import example.springdata.rest.headers.Application; -import example.springdata.rest.headers.Customer; -import example.springdata.rest.headers.CustomerRepository; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests to bootstrap the application. @@ -34,8 +30,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke * @soundtrack The Intersphere - Out of phase (Live at Alte Feuerwache Mannheim) */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class ApplicationIntegrationTests { @Autowired CustomerRepository repository; diff --git a/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java b/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java index 4f162055..9bf2e09a 100644 --- a/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java +++ b/rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,21 +21,16 @@ import static org.springframework.restdocs.RestDocumentation.*; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; -import example.springdata.rest.headers.Application; -import example.springdata.rest.headers.Customer; -import example.springdata.rest.headers.CustomerRepository; - import java.net.URI; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockHttpServletResponse; import org.springframework.restdocs.config.RestDocumentationConfigurer; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -45,9 +40,8 @@ import org.springframework.web.util.UriTemplate; * @author Oliver Gierke * @soundtrack The Intersphere - Out of phase (Live at Alte Feuerwache Mannheim) */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class WebIntegrationTests { @Autowired WebApplicationContext context; diff --git a/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java b/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java index c1027ae6..121c3593 100644 --- a/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java +++ b/rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -24,8 +24,8 @@ import lombok.extern.slf4j.Slf4j; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration test to show the usage of repositories backed by different stores. @@ -33,8 +33,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Oliver Gierke */ @Slf4j -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class ApplicationIntegrationTests { @Autowired PersonRepository personRepository; diff --git a/rest/projections/src/main/java/example/springdata/rest/projections/Application.java b/rest/projections/src/main/java/example/springdata/rest/projections/Application.java index 1bee6db1..d2f85585 100644 --- a/rest/projections/src/main/java/example/springdata/rest/projections/Application.java +++ b/rest/projections/src/main/java/example/springdata/rest/projections/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,12 +23,12 @@ import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; /** * @author Oliver Gierke */ -@EnableAutoConfiguration +@SpringBootApplication public class Application { @Autowired CustomerRepository customers; @@ -38,8 +38,7 @@ public class Application { SpringApplication.run(Application.class, args); } - @PostConstruct - public void init() { + public @PostConstruct void init() { Customer dave = customers.save(new Customer("Dave", "Matthews", Gender.MALE, // new Address("4711 Some Place", "54321", "Charlottesville", "VA"))); diff --git a/rest/projections/src/test/java/example/springdata/rest/projections/ApplicationIntegrationTests.java b/rest/projections/src/test/java/example/springdata/rest/projections/ApplicationIntegrationTests.java index a5b42b64..7307d9ee 100644 --- a/rest/projections/src/test/java/example/springdata/rest/projections/ApplicationIntegrationTests.java +++ b/rest/projections/src/test/java/example/springdata/rest/projections/ApplicationIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -18,23 +18,19 @@ package example.springdata.rest.projections; import static org.hamcrest.Matchers.*; import static org.junit.Assert.*; -import example.springdata.rest.projections.Application; -import example.springdata.rest.projections.Order; -import example.springdata.rest.projections.OrderRepository; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests to bootstrap the application. * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class ApplicationIntegrationTests { @Autowired OrderRepository repository; diff --git a/rest/security/src/main/java/example/springdata/rest/security/Application.java b/rest/security/src/main/java/example/springdata/rest/security/Application.java index 421686ee..9fc898f2 100644 --- a/rest/security/src/main/java/example/springdata/rest/security/Application.java +++ b/rest/security/src/main/java/example/springdata/rest/security/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,8 +19,14 @@ import javax.annotation.PostConstruct; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; -import org.springframework.context.annotation.ComponentScan; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; +import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.core.context.SecurityContextHolder; /** @@ -28,8 +34,7 @@ import org.springframework.security.core.context.SecurityContextHolder; * * @author Greg Turnquist */ -@ComponentScan -@EnableAutoConfiguration +@SpringBootApplication public class Application { @Autowired ItemRepository itemRepository; @@ -42,8 +47,7 @@ public class Application { /** * Pre-load the system with employees and items. */ - @PostConstruct - public void init() { + public @PostConstruct void init() { employeeRepository.save(new Employee("Bilbo", "Baggins", "thief")); employeeRepository.save(new Employee("Frodo", "Baggins", "ring bearer")); @@ -60,4 +64,55 @@ public class Application { SecurityContextHolder.clearContext(); } + + /** + * This application is secured at both the URL level for some parts, and the method level for other parts. The URL + * security is shown inside this code, while method-level annotations are enabled at by + * {@link EnableGlobalMethodSecurity}. + * + * @author Greg Turnquist + * @author Oliver Gierke + */ + @Configuration + @EnableGlobalMethodSecurity(prePostEnabled = true) + @EnableWebSecurity + static class SecurityConfiguration extends WebSecurityConfigurerAdapter { + + /** + * This section defines the user accounts which can be used for authentication as well as the roles each user has. + * + * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) + */ + @Override + protected void configure(AuthenticationManagerBuilder auth) throws Exception { + + auth.inMemoryAuthentication().// + withUser("greg").password("turnquist").roles("USER").and().// + withUser("ollie").password("gierke").roles("USER", "ADMIN"); + } + + /** + * This section defines the security policy for the app. + *

+ *

+ * NOTE: GET is not shown which defaults to permitted. + * + * @param http + * @throws Exception + * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) + */ + @Override + protected void configure(HttpSecurity http) throws Exception { + + http.httpBasic().and().authorizeRequests().// + antMatchers(HttpMethod.POST, "/employees").hasRole("ADMIN").// + antMatchers(HttpMethod.PUT, "/employees/**").hasRole("ADMIN").// + antMatchers(HttpMethod.PATCH, "/employees/**").hasRole("ADMIN").and().// + csrf().disable(); + } + } } diff --git a/rest/security/src/main/java/example/springdata/rest/security/SecurityConfiguration.java b/rest/security/src/main/java/example/springdata/rest/security/SecurityConfiguration.java deleted file mode 100644 index 1ed49c03..00000000 --- a/rest/security/src/main/java/example/springdata/rest/security/SecurityConfiguration.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright 2014-2015 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package example.springdata.rest.security; - -import org.springframework.context.annotation.Configuration; -import org.springframework.http.HttpMethod; -import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; -import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; -import org.springframework.security.config.annotation.web.builders.HttpSecurity; -import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; -import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; - -/** - * This application is secured at both the URL level for some parts, and the method level for other parts. The URL - * security is shown inside this code, while method-level annotations are enabled at by - * {@link EnableGlobalMethodSecurity}. - * - * @author Greg Turnquist - * @author Oliver Gierke - */ -@Configuration -@EnableGlobalMethodSecurity(prePostEnabled = true) -@EnableWebSecurity -public class SecurityConfiguration extends WebSecurityConfigurerAdapter { - - /** - * This section defines the user accounts which can be used for authentication as well as the roles each user has. - * - * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder) - */ - @Override - protected void configure(AuthenticationManagerBuilder auth) throws Exception { - - auth.inMemoryAuthentication().// - withUser("greg").password("turnquist").roles("USER").and().// - withUser("ollie").password("gierke").roles("USER", "ADMIN"); - } - - /** - * This section defines the security policy for the app. - *

- *

- * NOTE: GET is not shown which defaults to permitted. - * - * @param http - * @throws Exception - * @see org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter#configure(org.springframework.security.config.annotation.web.builders.HttpSecurity) - */ - @Override - protected void configure(HttpSecurity http) throws Exception { - - http.httpBasic().and().authorizeRequests().// - antMatchers(HttpMethod.POST, "/employees").hasRole("ADMIN").// - antMatchers(HttpMethod.PUT, "/employees/**").hasRole("ADMIN").// - antMatchers(HttpMethod.PATCH, "/employees/**").hasRole("ADMIN").and().// - csrf().disable(); - } -} diff --git a/rest/security/src/test/java/example/springdata/rest/security/MethodLevelSecurityTests.java b/rest/security/src/test/java/example/springdata/rest/security/MethodLevelSecurityTests.java index 777851c4..9475687e 100644 --- a/rest/security/src/test/java/example/springdata/rest/security/MethodLevelSecurityTests.java +++ b/rest/security/src/test/java/example/springdata/rest/security/MethodLevelSecurityTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,21 +17,15 @@ package example.springdata.rest.security; import static org.junit.Assert.*; -import example.springdata.rest.security.Application; -import example.springdata.rest.security.Item; -import example.springdata.rest.security.ItemRepository; -import example.springdata.rest.security.SecurityConfiguration; -import example.springdata.rest.security.SecurityUtils; - import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.access.AccessDeniedException; import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException; import org.springframework.security.core.context.SecurityContextHolder; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; /** * Collection of test cases used to verify method-level security. @@ -39,8 +33,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; * @author Greg Turnquist * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { Application.class, SecurityConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootTest public class MethodLevelSecurityTests { @Autowired ItemRepository itemRepository; diff --git a/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java b/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java index 3e3daa0c..af3adaef 100644 --- a/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java +++ b/rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java @@ -26,15 +26,14 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.hateoas.MediaTypes; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.security.crypto.codec.Base64; import org.springframework.security.web.FilterChainProxy; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.web.context.WebApplicationContext; @@ -46,9 +45,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; * @author Greg Turnquist * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@SpringApplicationConfiguration(classes = { Application.class, SecurityConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootTest public class UrlLevelSecurityTests { static final String PAYLOAD = "{\"firstName\": \"Saruman\", \"lastName\": \"the White\", " + "\"title\": \"Wizard\"}"; diff --git a/rest/starbucks/src/main/java/example/springdata/rest/stores/web/StoresController.java b/rest/starbucks/src/main/java/example/springdata/rest/stores/web/StoresController.java index 19e3d1fc..6e552710 100644 --- a/rest/starbucks/src/main/java/example/springdata/rest/stores/web/StoresController.java +++ b/rest/starbucks/src/main/java/example/springdata/rest/stores/web/StoresController.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,6 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.data.geo.Distance; @@ -47,7 +46,7 @@ import org.springframework.web.bind.annotation.RequestParam; * @author Oliver Gierke */ @Controller -@RequiredArgsConstructor(onConstructor = @__(@Autowired)) +@RequiredArgsConstructor class StoresController { private static final List DISTANCES = Arrays.asList(new Distance(0.5, MILES), new Distance(1, MILES), diff --git a/rest/starbucks/src/test/java/example/springdata/rest/stores/StarbucksClient.java b/rest/starbucks/src/test/java/example/springdata/rest/stores/StarbucksClient.java index 6120cbc8..3ea7c729 100644 --- a/rest/starbucks/src/test/java/example/springdata/rest/stores/StarbucksClient.java +++ b/rest/starbucks/src/test/java/example/springdata/rest/stores/StarbucksClient.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,20 +17,20 @@ package example.springdata.rest.stores; import static org.springframework.hateoas.MediaTypes.*; +import lombok.extern.slf4j.Slf4j; + import java.net.URI; import java.util.HashMap; import java.util.Map; import java.util.stream.StreamSupport; -import lombok.extern.slf4j.Slf4j; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.boot.test.WebIntegrationTest; +import org.springframework.boot.context.embedded.LocalServerPort; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.context.annotation.Bean; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; @@ -45,7 +45,7 @@ import org.springframework.hateoas.mvc.TypeReferences.PagedResourcesType; import org.springframework.hateoas.mvc.TypeReferences.ResourceType; import org.springframework.hateoas.mvc.TypeReferences.ResourcesType; import org.springframework.http.RequestEntity; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.web.client.RestOperations; import org.springframework.web.client.RestTemplate; @@ -54,9 +54,8 @@ import org.springframework.web.client.RestTemplate; * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebIntegrationTest(randomPort = true) -@SpringApplicationConfiguration +@RunWith(SpringRunner.class) +@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) @Slf4j public class StarbucksClient { @@ -69,7 +68,7 @@ public class StarbucksClient { } } - @Value("${local.server.port}") String port; + @LocalServerPort int port; private static final String SERVICE_URI = "http://localhost:%s/api"; diff --git a/rest/starbucks/src/test/java/example/springdata/rest/stores/StoreRepositoryIntegrationTests.java b/rest/starbucks/src/test/java/example/springdata/rest/stores/StoreRepositoryIntegrationTests.java index c20e1343..a189a63d 100644 --- a/rest/starbucks/src/test/java/example/springdata/rest/stores/StoreRepositoryIntegrationTests.java +++ b/rest/starbucks/src/test/java/example/springdata/rest/stores/StoreRepositoryIntegrationTests.java @@ -25,23 +25,21 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.domain.Page; import org.springframework.data.domain.PageRequest; import org.springframework.data.geo.Distance; import org.springframework.data.geo.Metrics; import org.springframework.data.geo.Point; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests for {@link StoreRepository}. * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = Application.class) public class StoreRepositoryIntegrationTests { @Autowired StoreRepository repository; diff --git a/rest/uri-customization/src/main/java/example/springdata/rest/uris/Application.java b/rest/uri-customization/src/main/java/example/springdata/rest/uris/Application.java index 3d8d5b91..75d79f2f 100644 --- a/rest/uri-customization/src/main/java/example/springdata/rest/uris/Application.java +++ b/rest/uri-customization/src/main/java/example/springdata/rest/uris/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,7 +23,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.data.map.repository.config.EnableMapRepositories; /** - * Applicatoin class to bootstrap the app. + * Application class to bootstrap the app. * * @author Oliver Gierke */ @@ -37,8 +37,7 @@ public class Application { @Autowired UserRepository repository; - @PostConstruct - public void init() { + public @PostConstruct void init() { repository.save(new User("olivergierke")); repository.save(new User("starbucksman")); diff --git a/rest/uri-customization/src/test/java/example/springdata/rest/uris/WebIntegrationTests.java b/rest/uri-customization/src/test/java/example/springdata/rest/uris/WebIntegrationTests.java index e54cc79f..01c75e9e 100644 --- a/rest/uri-customization/src/test/java/example/springdata/rest/uris/WebIntegrationTests.java +++ b/rest/uri-customization/src/test/java/example/springdata/rest/uris/WebIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,9 +23,8 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; @@ -36,21 +35,17 @@ import org.springframework.web.context.WebApplicationContext; * @author Oliver Gierke * @soundtrack Clueso - Gewinner (Stadtrandlichter Live) */ -@RunWith(SpringJUnit4ClassRunner.class) -@WebAppConfiguration -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest public class WebIntegrationTests { @Autowired WebApplicationContext context; - @Autowired UserRepository users; MockMvc mvc; @Before public void setUp() { - - this.mvc = MockMvcBuilders.webAppContextSetup(context).// - build(); + this.mvc = MockMvcBuilders.webAppContextSetup(context).build(); } @Test diff --git a/solr/example/src/test/java/example/springdata/solr/AdvancedSolrRepositoryTests.java b/solr/example/src/test/java/example/springdata/solr/AdvancedSolrRepositoryTests.java index bc247eac..315e31bc 100644 --- a/solr/example/src/test/java/example/springdata/solr/AdvancedSolrRepositoryTests.java +++ b/solr/example/src/test/java/example/springdata/solr/AdvancedSolrRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,12 +20,17 @@ import static org.junit.Assert.*; import static org.springframework.data.solr.core.query.Criteria.*; import static org.springframework.data.solr.core.query.ExistsFunction.*; +import example.springdata.solr.product.Product; +import example.springdata.solr.product.ProductRepository; +import example.springdata.solr.test.util.RequiresSolrServer; + import java.util.Arrays; import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.context.annotation.Configuration; import org.springframework.data.domain.PageRequest; import org.springframework.data.repository.CrudRepository; @@ -35,19 +40,14 @@ import org.springframework.data.solr.core.query.Query; import org.springframework.data.solr.core.query.SimpleQuery; import org.springframework.data.solr.core.query.result.HighlightPage; import org.springframework.data.solr.repository.Boost; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import example.springdata.solr.product.Product; -import example.springdata.solr.product.ProductRepository; -import example.springdata.solr.test.util.RequiresSolrServer; +import org.springframework.test.context.junit4.SpringRunner; /** * @author Christoph Strobl * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration +@RunWith(SpringRunner.class) +@SpringBootTest public class AdvancedSolrRepositoryTests { public static @ClassRule RequiresSolrServer requiresRunningServer = RequiresSolrServer.onLocalhost(); @@ -81,10 +81,8 @@ public class AdvancedSolrRepositoryTests { HighlightPage products = repository.findByDescriptionStartingWith("play", new PageRequest(0, 10)); - products.getHighlighted().forEach( - entry -> entry.getHighlights().forEach( - highligh -> System.out.println(entry.getEntity().getId() + " | " + highligh.getField() + ":\t" - + highligh.getSnipplets()))); + products.getHighlighted().forEach(entry -> entry.getHighlights().forEach(highligh -> System.out + .println(entry.getEntity().getId() + " | " + highligh.getField() + ":\t" + highligh.getSnipplets()))); } /** diff --git a/solr/example/src/test/java/example/springdata/solr/BasicSolrRepositoryTests.java b/solr/example/src/test/java/example/springdata/solr/BasicSolrRepositoryTests.java index 57e2c042..286e87c9 100644 --- a/solr/example/src/test/java/example/springdata/solr/BasicSolrRepositoryTests.java +++ b/solr/example/src/test/java/example/springdata/solr/BasicSolrRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014-2015 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,21 +15,21 @@ */ package example.springdata.solr; +import example.springdata.solr.product.ProductRepository; +import example.springdata.solr.test.util.RequiresSolrServer; + import org.junit.ClassRule; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import example.springdata.solr.product.ProductRepository; -import example.springdata.solr.test.util.RequiresSolrServer; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * @author Christoph Strobl */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { SolrTestConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SolrTestConfiguration.class) public class BasicSolrRepositoryTests { public static @ClassRule RequiresSolrServer requiresRunningServer = RequiresSolrServer.onLocalhost(); diff --git a/solr/example/src/test/java/example/springdata/solr/SolrTestConfiguration.java b/solr/example/src/test/java/example/springdata/solr/SolrTestConfiguration.java index 29fe78a5..66784456 100644 --- a/solr/example/src/test/java/example/springdata/solr/SolrTestConfiguration.java +++ b/solr/example/src/test/java/example/springdata/solr/SolrTestConfiguration.java @@ -24,9 +24,8 @@ import javax.annotation.PreDestroy; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; import org.springframework.data.repository.CrudRepository; import org.springframework.data.solr.core.SolrTemplate; @@ -34,30 +33,26 @@ import org.springframework.data.solr.core.SolrTemplate; * @author Christoph Strobl * @author Oliver Gierke */ -@Configuration -@EnableAutoConfiguration +@SpringBootApplication public class SolrTestConfiguration { - private @Autowired CrudRepository repo; + @Autowired CrudRepository repo; - @Bean - public SolrTemplate solrTemplate() { + public @Bean SolrTemplate solrTemplate() { return new SolrTemplate(new HttpSolrClient("http://localhost:8983/solr"), "collection1"); } /** * Remove test data when context is shut down. */ - @PreDestroy - public void deleteDocumentsOnShutdown() { + public @PreDestroy void deleteDocumentsOnShutdown() { repo.deleteAll(); } /** * Initialize Solr instance with test data once context has started. */ - @PostConstruct - public void initWithTestData() { + public @PostConstruct void initWithTestData() { doInitTestData(repo); } diff --git a/solr/example/src/test/resources/application.properties b/solr/example/src/test/resources/application.properties new file mode 100644 index 00000000..bac6605c --- /dev/null +++ b/solr/example/src/test/resources/application.properties @@ -0,0 +1 @@ +logging.level.root=WARN diff --git a/solr/example/src/test/resources/logback.xml b/solr/example/src/test/resources/logback.xml deleted file mode 100644 index a8128ca5..00000000 --- a/solr/example/src/test/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - %d %5p %40.40c:%4L - %m%n - - - - - - - - - - \ No newline at end of file diff --git a/solr/managed-schema/src/test/java/example/springdata/solr/SolrRepositoryTests.java b/solr/managed-schema/src/test/java/example/springdata/solr/SolrRepositoryTests.java index 5ed4115e..6ebb1d89 100644 --- a/solr/managed-schema/src/test/java/example/springdata/solr/SolrRepositoryTests.java +++ b/solr/managed-schema/src/test/java/example/springdata/solr/SolrRepositoryTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,22 +15,22 @@ */ package example.springdata.solr; -import org.junit.ClassRule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - import example.springdata.solr.product.ManagedProduct; import example.springdata.solr.product.ProductRepository; import example.springdata.solr.test.util.RequiresSolrServer; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + /** * @author Christoph Strobl */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = { SolrTestConfiguration.class }) +@RunWith(SpringRunner.class) +@SpringBootTest public class SolrRepositoryTests { public static @ClassRule RequiresSolrServer requiresRunningServer = RequiresSolrServer.onLocalhost(); @@ -40,8 +40,8 @@ public class SolrRepositoryTests { /** * Adds missing fields to the schema.
* By default the fields {@literal id} and {@literal _version_} are present.
- * Check fields using ../solr/collection1/schema/fields
+ * Check fields using + * ../solr/collection1/schema/fields
*
* NOTE: requires Solr to run in managed schema mode. */ diff --git a/solr/managed-schema/src/test/java/example/springdata/solr/SolrTestConfiguration.java b/solr/managed-schema/src/test/java/example/springdata/solr/SolrTestConfiguration.java index 6b4a3cce..9127076f 100644 --- a/solr/managed-schema/src/test/java/example/springdata/solr/SolrTestConfiguration.java +++ b/solr/managed-schema/src/test/java/example/springdata/solr/SolrTestConfiguration.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,17 +15,18 @@ */ package example.springdata.solr; +import example.springdata.solr.product.ProductRepository; + import javax.annotation.PreDestroy; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.impl.HttpSolrClient; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.solr.repository.config.EnableSolrRepositories; -import example.springdata.solr.product.ProductRepository; - /** * {@link Configuration} class enabling schema support for solr.
*
@@ -34,22 +35,20 @@ import example.springdata.solr.product.ProductRepository; * * @author Christoph Strobl */ -@Configuration +@SpringBootApplication @EnableSolrRepositories(schemaCreationSupport = true, multicoreSupport = true) public class SolrTestConfiguration { @Autowired ProductRepository repo; - @Bean - public SolrClient solrServer() { + public @Bean SolrClient solrServer() { return new HttpSolrClient("http://localhost:8983/solr"); } /** * Remove test data when context is shut down. */ - @PreDestroy - public void deleteDocumentsOnShutdown() { + public @PreDestroy void deleteDocumentsOnShutdown() { repo.deleteAll(); } } diff --git a/solr/managed-schema/src/test/resources/application.properties b/solr/managed-schema/src/test/resources/application.properties new file mode 100644 index 00000000..bac6605c --- /dev/null +++ b/solr/managed-schema/src/test/resources/application.properties @@ -0,0 +1 @@ +logging.level.root=WARN diff --git a/solr/managed-schema/src/test/resources/logback.xml b/solr/managed-schema/src/test/resources/logback.xml deleted file mode 100644 index 65fefdd2..00000000 --- a/solr/managed-schema/src/test/resources/logback.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - %d %5p %40.40c:%4L - %m%n - - - - - - - - - - \ No newline at end of file diff --git a/web/example/src/main/java/example/Application.java b/web/example/src/main/java/example/Application.java index 7d3443b4..225a18bb 100644 --- a/web/example/src/main/java/example/Application.java +++ b/web/example/src/main/java/example/Application.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,10 @@ */ package example; +import example.users.Password; +import example.users.UserManagement; +import example.users.Username; + import java.util.stream.IntStream; import javax.annotation.PostConstruct; @@ -29,10 +33,6 @@ import org.springframework.data.web.config.EnableSpringDataWebSupport; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; import org.springframework.security.crypto.password.PasswordEncoder; -import example.users.Password; -import example.users.UserManagement; -import example.users.Username; - /** * Central Spring Boot application class to bootstrap the application. Excludes Spring Security auto-configuration as we * don't need it for the example but only want to use a {@link PasswordEncoder} (see {@link #passwordEncoder()}). diff --git a/web/example/src/test/java/example/users/AbstractIntegrationTests.java b/web/example/src/test/java/example/users/AbstractIntegrationTests.java index 5912f6b3..e4e211e1 100644 --- a/web/example/src/test/java/example/users/AbstractIntegrationTests.java +++ b/web/example/src/test/java/example/users/AbstractIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2015 the original author or authors. + * Copyright 2015-2016 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,16 +16,14 @@ package example.users; import org.junit.runner.RunWith; -import org.springframework.boot.test.SpringApplicationConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import example.Application; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; /** * Integration tests to bootstrap the application. * * @author Oliver Gierke */ -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = Application.class) +@RunWith(SpringRunner.class) +@SpringBootTest public abstract class AbstractIntegrationTests {} diff --git a/web/querydsl/src/main/java/example/users/Application.java b/web/querydsl/src/main/java/example/users/Application.java index f09cbfb1..f85da8e0 100644 --- a/web/querydsl/src/main/java/example/users/Application.java +++ b/web/querydsl/src/main/java/example/users/Application.java @@ -21,7 +21,6 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.context.annotation.Bean; -import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; import org.thymeleaf.dialect.springdata.SpringDataDialect; @@ -36,16 +35,6 @@ public class Application extends WebMvcConfigurerAdapter { SpringApplication.run(Application.class, args); } - @Override - public void addResourceHandlers(ResourceHandlerRegistry registry) { - - // Configure resource handler explicitly to enable non-versioned - // Webjars in Thymeleaf templates - registry.addResourceHandler("/webjars/**").// - addResourceLocations("classpath:/META-INF/resources/webjars/").// - resourceChain(true); - } - @Bean SpringDataDialect springDataDialect() { return new SpringDataDialect(); @@ -55,11 +44,6 @@ public class Application extends WebMvcConfigurerAdapter { @PostConstruct void initialize() throws Exception { - - // Import demo users from local CSV - new UserInitializer(repo).initLocally(); - - // Import demo users from remote service - // new UserInitializer(repo).initRemote(100); + new UserInitializer(repo).init(); } } diff --git a/web/querydsl/src/main/java/example/users/UserInitializer.java b/web/querydsl/src/main/java/example/users/UserInitializer.java index e83b3c9f..04e9686c 100644 --- a/web/querydsl/src/main/java/example/users/UserInitializer.java +++ b/web/querydsl/src/main/java/example/users/UserInitializer.java @@ -34,9 +34,7 @@ import org.springframework.batch.item.file.separator.DefaultRecordSeparatorPolic import org.springframework.batch.item.file.transform.DelimitedLineTokenizer; import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.Resource; -import org.springframework.core.io.UrlResource; import org.springframework.util.StringUtils; -import org.springframework.web.util.UriTemplate; /** * Initialize {@link UserRepository} with sample data. @@ -47,12 +45,9 @@ import org.springframework.web.util.UriTemplate; @RequiredArgsConstructor public class UserInitializer { - private static final UriTemplate REMOTE_TEMPLATE = new UriTemplate( - "https://randomuser.me/api/?results={numberOfUsers}&format=csv&nat=US"); - private final UserRepository repository; - public void initLocally() throws Exception { + public void init() throws Exception { List users = readUsers(new ClassPathResource("randomuser.me.csv")); @@ -60,14 +55,6 @@ public class UserInitializer { repository.save(users); } - public void initRemote(int numberOfUsers) throws Exception { - - List users = readUsers(new UrlResource(REMOTE_TEMPLATE.expand(numberOfUsers))); - - repository.deleteAll(); - repository.save(users); - } - private static List readUsers(Resource resource) throws Exception { Scanner scanner = new Scanner(resource.getInputStream());