diff --git a/persistence-modules/java-cockroachdb/src/test/java/com/baeldung/cockroachdb/ArticleRepositoryIntegrationTest.java b/persistence-modules/java-cockroachdb/src/test/java/com/baeldung/cockroachdb/ArticleRepositoryLiveTest.java similarity index 99% rename from persistence-modules/java-cockroachdb/src/test/java/com/baeldung/cockroachdb/ArticleRepositoryIntegrationTest.java rename to persistence-modules/java-cockroachdb/src/test/java/com/baeldung/cockroachdb/ArticleRepositoryLiveTest.java index 9eb00b3651..eda9ca15e4 100644 --- a/persistence-modules/java-cockroachdb/src/test/java/com/baeldung/cockroachdb/ArticleRepositoryIntegrationTest.java +++ b/persistence-modules/java-cockroachdb/src/test/java/com/baeldung/cockroachdb/ArticleRepositoryLiveTest.java @@ -16,7 +16,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -public class ArticleRepositoryIntegrationTest { +public class ArticleRepositoryLiveTest { private static final String TABLE_NAME = "articles"; diff --git a/persistence-modules/spring-data-dynamodb/pom.xml b/persistence-modules/spring-data-dynamodb/pom.xml index b1b7c8237b..b19c3b9c93 100644 --- a/persistence-modules/spring-data-dynamodb/pom.xml +++ b/persistence-modules/spring-data-dynamodb/pom.xml @@ -5,8 +5,8 @@ spring-boot-dynamodb 0.0.1-SNAPSHOT jar - Spring Boot Actuator - This is simple boot application for Spring boot actuator test + spring-boot-dynamodb + This is simple boot application for Spring boot dynamodb test parent-boot-1 diff --git a/persistence-modules/spring-data-dynamodb/src/main/java/com/baeldung/spring/data/dynamodb/config/DynamoDBConfig.java b/persistence-modules/spring-data-dynamodb/src/main/java/com/baeldung/spring/data/dynamodb/config/DynamoDBConfig.java index 271c1e29ab..9278c0a12e 100644 --- a/persistence-modules/spring-data-dynamodb/src/main/java/com/baeldung/spring/data/dynamodb/config/DynamoDBConfig.java +++ b/persistence-modules/spring-data-dynamodb/src/main/java/com/baeldung/spring/data/dynamodb/config/DynamoDBConfig.java @@ -1,14 +1,18 @@ package com.baeldung.spring.data.dynamodb.config; +import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.util.StringUtils; +import org.springframework.web.servlet.handler.HandlerMappingIntrospector; + import com.amazonaws.auth.AWSCredentials; import com.amazonaws.auth.BasicAWSCredentials; import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; import com.amazonaws.services.dynamodbv2.AmazonDynamoDBClient; -import org.socialsignin.spring.data.dynamodb.repository.config.EnableDynamoDBRepositories; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.util.StringUtils; @Configuration @EnableDynamoDBRepositories(basePackages = "com.baeldung.spring.data.dynamodb.repositories") @@ -22,6 +26,9 @@ public class DynamoDBConfig { @Value("${amazon.aws.secretkey}") private String amazonAWSSecretKey; + + @Autowired + private ApplicationContext context; @Bean public AmazonDynamoDB amazonDynamoDB() { @@ -37,4 +44,8 @@ public class DynamoDBConfig { return new BasicAWSCredentials(amazonAWSAccessKey, amazonAWSSecretKey); } + @Bean(name = "mvcHandlerMappingIntrospector") + public HandlerMappingIntrospector mvcHandlerMappingIntrospector() { + return new HandlerMappingIntrospector(context); + } } diff --git a/persistence-modules/spring-data-redis/pom.xml b/persistence-modules/spring-data-redis/pom.xml index c5e0049e83..cef12f5be7 100644 --- a/persistence-modules/spring-data-redis/pom.xml +++ b/persistence-modules/spring-data-redis/pom.xml @@ -70,6 +70,11 @@ spring-data-commons ${spring-data-commons.version} + + com.github.kstyrc + embedded-redis + ${embedded-redis.version} + @@ -79,6 +84,7 @@ 2.9.0 0.10.0 2.0.3.RELEASE + 0.6 diff --git a/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java b/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java index 4ea8bb4bc0..62a7886f46 100644 --- a/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java +++ b/persistence-modules/spring-data-redis/src/main/java/com/baeldung/spring/data/redis/config/RedisConfig.java @@ -1,8 +1,10 @@ package com.baeldung.spring.data.redis.config; +import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.ComponentScan; import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.PropertySource; import org.springframework.data.redis.connection.jedis.JedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.listener.ChannelTopic; @@ -18,6 +20,7 @@ import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber; @Configuration @ComponentScan("com.baeldung.spring.data.redis") @EnableRedisRepositories(basePackages = "com.baeldung.spring.data.redis.repo") +@PropertySource("classpath:application.properties") public class RedisConfig { @Bean diff --git a/persistence-modules/spring-data-redis/src/main/resources/application.properties b/persistence-modules/spring-data-redis/src/main/resources/application.properties new file mode 100644 index 0000000000..49886b3b70 --- /dev/null +++ b/persistence-modules/spring-data-redis/src/main/resources/application.properties @@ -0,0 +1,2 @@ +spring.redis.host=localhost +spring.redis.port=6379 \ No newline at end of file diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java index 01dbfcff4d..5bc70069c5 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/RedisMessageListenerIntegrationTest.java @@ -1,24 +1,44 @@ package com.baeldung.spring.data.redis; -import com.baeldung.spring.data.redis.config.RedisConfig; -import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber; -import com.baeldung.spring.data.redis.queue.RedisMessagePublisher; -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 java.util.UUID; - import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.util.UUID; + +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +import com.baeldung.spring.data.redis.config.RedisConfig; +import com.baeldung.spring.data.redis.queue.RedisMessagePublisher; +import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber; + @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = RedisConfig.class) +@DirtiesContext(classMode = ClassMode.AFTER_CLASS) public class RedisMessageListenerIntegrationTest { + private static redis.embedded.RedisServer redisServer; + @Autowired private RedisMessagePublisher redisMessagePublisher; + + @BeforeClass + public static void startRedisServer() throws IOException { + redisServer = new redis.embedded.RedisServer(6379); + redisServer.start(); + } + + @AfterClass + public static void stopRedisServer() throws IOException { + redisServer.stop(); + } @Test public void testOnMessage() throws Exception { diff --git a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java index 66ef3c21b2..48832a8de9 100644 --- a/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java +++ b/persistence-modules/spring-data-redis/src/test/java/com/baeldung/spring/data/redis/repo/StudentRepositoryIntegrationTest.java @@ -3,13 +3,17 @@ package com.baeldung.spring.data.redis.repo; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; +import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.Map; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.annotation.DirtiesContext; +import org.springframework.test.annotation.DirtiesContext.ClassMode; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -18,10 +22,24 @@ import com.baeldung.spring.data.redis.model.Student; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = RedisConfig.class) +@DirtiesContext(classMode = ClassMode.AFTER_CLASS) public class StudentRepositoryIntegrationTest { @Autowired private StudentRepository studentRepository; + + private static redis.embedded.RedisServer redisServer; + + @BeforeClass + public static void startRedisServer() throws IOException { + redisServer = new redis.embedded.RedisServer(6379); + redisServer.start(); + } + + @AfterClass + public static void stopRedisServer() throws IOException { + redisServer.stop(); + } @Test public void whenSavingStudent_thenAvailableOnRetrieval() throws Exception { diff --git a/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/BatchJobApplication.java b/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/BatchJobApplication.java index f717f0f644..30f6ff6897 100644 --- a/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/BatchJobApplication.java +++ b/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/BatchJobApplication.java @@ -1,12 +1,10 @@ package org.baeldung.spring.cloud; -import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.task.configuration.EnableTask; @EnableTask -@EnableBatchProcessing @SpringBootApplication public class BatchJobApplication { diff --git a/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/JobConfiguration.java b/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/JobConfiguration.java index dc6a5e2827..7ce867b60a 100644 --- a/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/JobConfiguration.java +++ b/spring-cloud-data-flow/batch-job/src/main/java/org/baeldung/spring/cloud/JobConfiguration.java @@ -2,9 +2,9 @@ package org.baeldung.spring.cloud; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - import org.springframework.batch.core.Job; import org.springframework.batch.core.StepContribution; +import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing; import org.springframework.batch.core.configuration.annotation.JobBuilderFactory; import org.springframework.batch.core.configuration.annotation.StepBuilderFactory; import org.springframework.batch.core.scope.context.ChunkContext; @@ -15,6 +15,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration +@EnableBatchProcessing public class JobConfiguration { private static final Log logger = LogFactory.getLog(JobConfiguration.class); diff --git a/spring-cloud-data-flow/batch-job/src/test/java/org/baeldung/spring/cloud/BatchJobApplicationIntegrationTest.java b/spring-cloud-data-flow/batch-job/src/test/java/org/baeldung/spring/cloud/BatchJobApplicationIntegrationTest.java index f8dfdec197..1f77351acc 100644 --- a/spring-cloud-data-flow/batch-job/src/test/java/org/baeldung/spring/cloud/BatchJobApplicationIntegrationTest.java +++ b/spring-cloud-data-flow/batch-job/src/test/java/org/baeldung/spring/cloud/BatchJobApplicationIntegrationTest.java @@ -3,10 +3,12 @@ package org.baeldung.spring.cloud; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; @RunWith(SpringRunner.class) @SpringBootTest +@ContextConfiguration(classes = JobConfiguration.class) public class BatchJobApplicationIntegrationTest { @Test diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml index 27e327110a..cbd495908a 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/pom.xml @@ -18,6 +18,7 @@ 3.0.1 + 0.6 @@ -57,6 +58,11 @@ org.springframework.boot spring-boot-starter-data-redis + + com.github.kstyrc + embedded-redis + ${embedded-redis.version} + diff --git a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/BookReviewsApiIntegrationTest.java b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/BookReviewsApiIntegrationTest.java index d25e0bee20..98cda102e9 100644 --- a/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/BookReviewsApiIntegrationTest.java +++ b/spring-cloud/spring-cloud-rest/spring-cloud-rest-reviews-api/src/test/java/org/baeldung/BookReviewsApiIntegrationTest.java @@ -1,13 +1,33 @@ package org.baeldung; +import java.io.IOException; + +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.test.context.junit4.SpringRunner; +import redis.embedded.RedisServer; @RunWith(SpringRunner.class) @SpringBootTest public class BookReviewsApiIntegrationTest { + + private static RedisServer redisServer; + private static int port; + + @BeforeClass + public static void setUp() throws IOException { + + redisServer = new RedisServer(6379); + redisServer.start(); + } + + @AfterClass + public static void destroy() { + redisServer.stop(); + } @Test public void contextLoads() { diff --git a/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorIntegrationTest.java b/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorIntegrationTest.java index 11d9daf3bf..5de53192df 100644 --- a/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorIntegrationTest.java +++ b/spring-core/src/test/java/com/baeldung/dependson/processor/FileProcessorIntegrationTest.java @@ -5,7 +5,6 @@ import static org.junit.Assert.assertTrue; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.BeanCreationException; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ContextConfiguration; @@ -30,7 +29,7 @@ public class FileProcessorIntegrationTest { assertTrue(file.getText().endsWith("processed")); } - @Test(expected=NoSuchBeanDefinitionException.class) + @Test(expected=BeanCreationException.class) public void whenDependentBeanNotAvailable_ThrowsNoSuchBeanDefinitionException(){ context.getBean("dummyFileProcessor"); } diff --git a/spring-cucumber/src/test/java/com/baeldung/CucumberIntegrationTest.java b/spring-cucumber/src/test/java/com/baeldung/CucumberIntegrationTest.java index 56eb810c09..f48ab410ca 100644 --- a/spring-cucumber/src/test/java/com/baeldung/CucumberIntegrationTest.java +++ b/spring-cucumber/src/test/java/com/baeldung/CucumberIntegrationTest.java @@ -1,10 +1,11 @@ package com.baeldung; +import org.junit.runner.RunWith; + import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; -import org.junit.runner.RunWith; @RunWith(Cucumber.class) @CucumberOptions(features = "src/test/resources") -public class CucumberIntegrationTest { +public class CucumberIntegrationTest extends SpringIntegrationTest{ } \ No newline at end of file diff --git a/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java b/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java index f4d47d7871..8655a02469 100644 --- a/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java +++ b/spring-cucumber/src/test/java/com/baeldung/SpringIntegrationTest.java @@ -5,16 +5,17 @@ import java.util.HashMap; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.http.HttpMethod; import org.springframework.http.client.ClientHttpResponse; import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.web.client.ResponseErrorHandler; import org.springframework.web.client.RestTemplate; //@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(classes = SpringDemoApplication.class) -@WebAppConfiguration +@SpringBootTest(classes = SpringDemoApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT) +@ContextConfiguration public class SpringIntegrationTest { static ResponseResults latestResponse = null; diff --git a/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionLiveTest.java similarity index 98% rename from spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java rename to spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionLiveTest.java index 2b1f6d4d4f..702c1521da 100644 --- a/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionIntegrationTest.java +++ b/spring-data-rest/src/test/java/com/baeldung/projection/SpringDataProjectionLiveTest.java @@ -25,7 +25,7 @@ import com.baeldung.repositories.BookRepository; @RunWith(SpringRunner.class) @SpringBootTest(classes = SpringDataRestApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT) -public class SpringDataProjectionIntegrationTest { +public class SpringDataProjectionLiveTest { private static final String BOOK_ENDPOINT = "http://localhost:8080/books"; private static final String AUTHOR_ENDPOINT = "http://localhost:8080/authors"; diff --git a/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsIntegrationTest.java index e3fe60d487..196dc18d9e 100644 --- a/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsIntegrationTest.java +++ b/spring-data-rest/src/test/java/com/baeldung/relationships/SpringDataRelationshipsIntegrationTest.java @@ -1,15 +1,14 @@ package com.baeldung.relationships; -import com.baeldung.SpringDataRestApplication; -import com.baeldung.models.Address; -import com.baeldung.models.Author; -import com.baeldung.models.Book; -import com.baeldung.models.Library; +import static org.junit.Assert.assertEquals; + import org.json.JSONArray; +import org.json.JSONException; import org.json.JSONObject; 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.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; import org.springframework.boot.test.web.client.TestRestTemplate; @@ -18,21 +17,27 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit4.SpringRunner; -import org.json.JSONException; -import static org.junit.Assert.assertEquals; +import com.baeldung.SpringDataRestApplication; +import com.baeldung.models.Address; +import com.baeldung.models.Author; +import com.baeldung.models.Book; +import com.baeldung.models.Library; @RunWith(SpringRunner.class) -@SpringBootTest(classes = SpringDataRestApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT) +@SpringBootTest(classes = SpringDataRestApplication.class, webEnvironment = WebEnvironment.RANDOM_PORT) public class SpringDataRelationshipsIntegrationTest { @Autowired private TestRestTemplate template; + + @Value("${local.server.port}") + private int port; - private static final String BOOK_ENDPOINT = "http://localhost:8080/books/"; - private static final String AUTHOR_ENDPOINT = "http://localhost:8080/authors/"; - private static final String ADDRESS_ENDPOINT = "http://localhost:8080/addresses/"; - private static final String LIBRARY_ENDPOINT = "http://localhost:8080/libraries/"; + private static final String BOOK_ENDPOINT = "http://localhost:%s/books/"; + private static final String AUTHOR_ENDPOINT = "http://localhost:%s/authors/"; + private static final String ADDRESS_ENDPOINT = "http://localhost:%s/addresses/"; + private static final String LIBRARY_ENDPOINT = "http://localhost:%s/libraries/"; private static final String LIBRARY_NAME = "My Library"; private static final String AUTHOR_NAME = "George Orwell"; @@ -40,17 +45,17 @@ public class SpringDataRelationshipsIntegrationTest { @Test public void whenSaveOneToOneRelationship_thenCorrect() throws JSONException { Library library = new Library(LIBRARY_NAME); - template.postForEntity(LIBRARY_ENDPOINT, library, Library.class); + template.postForEntity(String.format(LIBRARY_ENDPOINT, port), library, Library.class); Address address = new Address("Main street, nr 1"); - template.postForEntity(ADDRESS_ENDPOINT, address, Address.class); + template.postForEntity(String.format(ADDRESS_ENDPOINT, port), address, Address.class); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.add("Content-type", "text/uri-list"); - HttpEntity httpEntity = new HttpEntity<>(ADDRESS_ENDPOINT + "/1", requestHeaders); - template.exchange(LIBRARY_ENDPOINT + "/1/libraryAddress", HttpMethod.PUT, httpEntity, String.class); + HttpEntity httpEntity = new HttpEntity<>(String.format(ADDRESS_ENDPOINT, port) + "/1", requestHeaders); + template.exchange(String.format(LIBRARY_ENDPOINT, port) + "/1/libraryAddress", HttpMethod.PUT, httpEntity, String.class); - ResponseEntity libraryGetResponse = template.getForEntity(ADDRESS_ENDPOINT + "/1/library", Library.class); + ResponseEntity libraryGetResponse = template.getForEntity(String.format(ADDRESS_ENDPOINT, port) + "/1/library", Library.class); assertEquals("library is incorrect", libraryGetResponse.getBody() .getName(), LIBRARY_NAME); } @@ -58,21 +63,21 @@ public class SpringDataRelationshipsIntegrationTest { @Test public void whenSaveOneToManyRelationship_thenCorrect() throws JSONException{ Library library = new Library(LIBRARY_NAME); - template.postForEntity(LIBRARY_ENDPOINT, library, Library.class); + template.postForEntity(String.format(LIBRARY_ENDPOINT, port), library, Library.class); Book book1 = new Book("Dune"); - template.postForEntity(BOOK_ENDPOINT, book1, Book.class); + template.postForEntity(String.format(BOOK_ENDPOINT, port), book1, Book.class); Book book2 = new Book("1984"); - template.postForEntity(BOOK_ENDPOINT, book2, Book.class); + template.postForEntity(String.format(BOOK_ENDPOINT, port), book2, Book.class); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.add("Content-type", "text/uri-list"); - HttpEntity bookHttpEntity = new HttpEntity<>(LIBRARY_ENDPOINT + "/1", requestHeaders); - template.exchange(BOOK_ENDPOINT + "/1/library", HttpMethod.PUT, bookHttpEntity, String.class); - template.exchange(BOOK_ENDPOINT + "/2/library", HttpMethod.PUT, bookHttpEntity, String.class); + HttpEntity bookHttpEntity = new HttpEntity<>(String.format(LIBRARY_ENDPOINT, port) + "/1", requestHeaders); + template.exchange(String.format(BOOK_ENDPOINT, port) + "/1/library", HttpMethod.PUT, bookHttpEntity, String.class); + template.exchange(String.format(BOOK_ENDPOINT, port) + "/2/library", HttpMethod.PUT, bookHttpEntity, String.class); - ResponseEntity libraryGetResponse = template.getForEntity(BOOK_ENDPOINT + "/1/library", Library.class); + ResponseEntity libraryGetResponse = template.getForEntity(String.format(BOOK_ENDPOINT, port) + "/1/library", Library.class); assertEquals("library is incorrect", libraryGetResponse.getBody() .getName(), LIBRARY_NAME); } @@ -80,20 +85,20 @@ public class SpringDataRelationshipsIntegrationTest { @Test public void whenSaveManyToManyRelationship_thenCorrect() throws JSONException{ Author author1 = new Author(AUTHOR_NAME); - template.postForEntity(AUTHOR_ENDPOINT, author1, Author.class); + template.postForEntity(String.format(AUTHOR_ENDPOINT, port), author1, Author.class); Book book1 = new Book("Animal Farm"); - template.postForEntity(BOOK_ENDPOINT, book1, Book.class); + template.postForEntity(String.format(BOOK_ENDPOINT, port), book1, Book.class); Book book2 = new Book("1984"); - template.postForEntity(BOOK_ENDPOINT, book2, Book.class); + template.postForEntity(String.format(BOOK_ENDPOINT, port), book2, Book.class); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.add("Content-type", "text/uri-list"); - HttpEntity httpEntity = new HttpEntity<>(BOOK_ENDPOINT + "/1\n" + BOOK_ENDPOINT + "/2", requestHeaders); - template.exchange(AUTHOR_ENDPOINT + "/1/books", HttpMethod.PUT, httpEntity, String.class); + HttpEntity httpEntity = new HttpEntity<>(String.format(BOOK_ENDPOINT, port) + "/1\n" + String.format(BOOK_ENDPOINT, port) + "/2", requestHeaders); + template.exchange(String.format(AUTHOR_ENDPOINT, port) + "/1/books", HttpMethod.PUT, httpEntity, String.class); - String jsonResponse = template.getForObject(BOOK_ENDPOINT + "/1/authors", String.class); + String jsonResponse = template.getForObject(String.format(BOOK_ENDPOINT, port) + "/1/authors", String.class); JSONObject jsonObj = new JSONObject(jsonResponse).getJSONObject("_embedded"); JSONArray jsonArray = jsonObj.getJSONArray("authors"); assertEquals("author is incorrect", jsonArray.getJSONObject(0) diff --git a/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java b/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java index bc321bc686..4c936ffc1c 100644 --- a/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java +++ b/spring-data-rest/src/test/java/com/baeldung/validator/SpringDataRestValidatorIntegrationTest.java @@ -1,31 +1,33 @@ package com.baeldung.validator; -import com.baeldung.SpringDataRestApplication; -import com.baeldung.models.WebsiteUser; -import com.fasterxml.jackson.databind.ObjectMapper; -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.http.MediaType; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import org.springframework.test.context.web.WebAppConfiguration; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.web.context.WebApplicationContext; - import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.redirectedUrl; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.setup.MockMvcBuilders.webAppContextSetup; +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.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.web.context.WebApplicationContext; + +import com.baeldung.SpringDataRestApplication; +import com.baeldung.models.WebsiteUser; +import com.fasterxml.jackson.databind.ObjectMapper; + @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest(classes = SpringDataRestApplication.class) -@WebAppConfiguration +@SpringBootTest(classes = SpringDataRestApplication.class, webEnvironment = SpringBootTest.WebEnvironment.MOCK) +@AutoConfigureMockMvc public class SpringDataRestValidatorIntegrationTest { public static final String URL = "http://localhost"; + @Autowired private MockMvc mockMvc; @Autowired diff --git a/spring-jenkins-pipeline/pom.xml b/spring-jenkins-pipeline/pom.xml index 9c3b6f14ed..bbc07a4091 100644 --- a/spring-jenkins-pipeline/pom.xml +++ b/spring-jenkins-pipeline/pom.xml @@ -29,6 +29,12 @@ spring-boot-starter-test test + + de.flapdoodle.embed + de.flapdoodle.embed.mongo + ${de.flapdoodle.embed.mongo.version} + test + @@ -73,6 +79,7 @@ UTF-8 1.8 2.17 + 2.0.0 diff --git a/spring-jenkins-pipeline/src/test/java/com/baeldung/SomeIntegrationTest.java b/spring-jenkins-pipeline/src/test/java/com/baeldung/SomeIntegrationTest.java index 092ebb93fd..477a7d2adb 100644 --- a/spring-jenkins-pipeline/src/test/java/com/baeldung/SomeIntegrationTest.java +++ b/spring-jenkins-pipeline/src/test/java/com/baeldung/SomeIntegrationTest.java @@ -13,7 +13,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import static org.junit.Assert.assertNotEquals; @RunWith(SpringJUnit4ClassRunner.class) -@SpringBootTest +@SpringBootTest(classes = {SpringJenkinsPipelineApplication.class, TestMongoConfig.class }) public class SomeIntegrationTest { @Autowired private StudentRepository studentRepository; diff --git a/spring-jenkins-pipeline/src/test/java/com/baeldung/TestMongoConfig.java b/spring-jenkins-pipeline/src/test/java/com/baeldung/TestMongoConfig.java new file mode 100644 index 0000000000..a85491cf7e --- /dev/null +++ b/spring-jenkins-pipeline/src/test/java/com/baeldung/TestMongoConfig.java @@ -0,0 +1,11 @@ +package com.baeldung; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.mongo.embedded.EmbeddedMongoAutoConfiguration; +import org.springframework.context.annotation.Configuration; + +@Configuration +@EnableAutoConfiguration(exclude = { EmbeddedMongoAutoConfiguration.class }) +public class TestMongoConfig { + +} \ No newline at end of file diff --git a/spring-mvc-simple/pom.xml b/spring-mvc-simple/pom.xml index 08eab59540..be433b0d6d 100644 --- a/spring-mvc-simple/pom.xml +++ b/spring-mvc-simple/pom.xml @@ -122,6 +122,14 @@ json ${json.version} + + org.apache.maven.surefire + surefire-logger-api + ${maven-surefire-plugin.version} + + test + true + diff --git a/spring-rest/src/test/java/org/baeldung/resttemplate/RestTemplateIntegrationTest.java b/spring-rest/src/test/java/org/baeldung/resttemplate/RestTemplateLiveTest.java similarity index 97% rename from spring-rest/src/test/java/org/baeldung/resttemplate/RestTemplateIntegrationTest.java rename to spring-rest/src/test/java/org/baeldung/resttemplate/RestTemplateLiveTest.java index e0c24c32b1..4f00bebdf4 100644 --- a/spring-rest/src/test/java/org/baeldung/resttemplate/RestTemplateIntegrationTest.java +++ b/spring-rest/src/test/java/org/baeldung/resttemplate/RestTemplateLiveTest.java @@ -21,7 +21,7 @@ import com.baeldung.transfer.LoginForm; @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = RestClientConfig.class) -public class RestTemplateIntegrationTest { +public class RestTemplateLiveTest { @Autowired RestTemplate restTemplate; diff --git a/spring-session/pom.xml b/spring-session/pom.xml index 4c256663b0..277b033f43 100644 --- a/spring-session/pom.xml +++ b/spring-session/pom.xml @@ -30,6 +30,15 @@ org.springframework.boot spring-boot-starter-web + + com.github.kstyrc + embedded-redis + ${embedded-redis.version} + + + + 0.6 + \ No newline at end of file diff --git a/spring-session/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java b/spring-session/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java index 84dd2bc139..f739aeb3ab 100644 --- a/spring-session/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java +++ b/spring-session/src/test/java/com/baeldung/spring/session/SessionControllerIntegrationTest.java @@ -1,27 +1,55 @@ package com.baeldung.spring.session; -import org.junit.Before; -import org.junit.Test; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.http.*; -import redis.clients.jedis.Jedis; - -import java.util.Set; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.io.IOException; +import java.util.Set; + +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; +import org.springframework.boot.test.web.client.TestRestTemplate; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.test.context.junit4.SpringRunner; + +import redis.clients.jedis.Jedis; +import redis.embedded.RedisServer; + +@RunWith(SpringRunner.class) +@SpringBootTest(classes = SessionWebApplication.class, webEnvironment = WebEnvironment.DEFINED_PORT) public class SessionControllerIntegrationTest { private Jedis jedis; + private static RedisServer redisServer; private TestRestTemplate testRestTemplate; private TestRestTemplate testRestTemplateWithAuth; private String testUrl = "http://localhost:8080/"; + @BeforeClass + public static void startRedisServer() throws IOException { + redisServer = new RedisServer(6379); + redisServer.start(); + } + + @AfterClass + public static void stopRedisServer() throws IOException { + redisServer.stop(); + } + @Before public void clearRedisData() { + testRestTemplate = new TestRestTemplate(); - testRestTemplateWithAuth = new TestRestTemplate("admin", "password", null); + testRestTemplateWithAuth = new TestRestTemplate("admin", "password"); jedis = new Jedis("localhost", 6379); jedis.flushAll(); diff --git a/spring-userservice/pom.xml b/spring-userservice/pom.xml index c372beaa3c..a6acfe3fc6 100644 --- a/spring-userservice/pom.xml +++ b/spring-userservice/pom.xml @@ -217,11 +217,11 @@ 4.2.6.RELEASE - 1.4.2.RELEASE + 1.5.14.RELEASE 3.21.0-GA - 5.2.5.Final + 5.2.10.Final 5.1.40 1.10.5.RELEASE 1.4.193 diff --git a/spring-userservice/src/main/resources/persistence-derby.properties b/spring-userservice/src/main/resources/persistence-derby.properties index e808fdc288..b76c5de12f 100644 --- a/spring-userservice/src/main/resources/persistence-derby.properties +++ b/spring-userservice/src/main/resources/persistence-derby.properties @@ -7,6 +7,6 @@ jdbc.pass=tutorialpass # hibernate.X hibernate.dialect=org.hibernate.dialect.DerbyDialect hibernate.show_sql=false -hibernate.hbm2ddl.auto=create +hibernate.hbm2ddl.auto=update hibernate.cache.use_second_level_cache=false hibernate.cache.use_query_cache=false \ No newline at end of file diff --git a/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java b/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java index f46a3a070f..1cd38228b8 100644 --- a/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java +++ b/spring-userservice/src/test/java/org/baeldung/userservice/CustomUserDetailsServiceIntegrationTest.java @@ -1,5 +1,10 @@ package org.baeldung.userservice; +import static org.junit.Assert.assertEquals; + +import java.util.logging.Level; +import java.util.logging.Logger; + import org.baeldung.custom.config.MvcConfig; import org.baeldung.custom.config.PersistenceDerbyJPAConfig; import org.baeldung.custom.config.SecSecurityConfig; @@ -8,22 +13,16 @@ import org.baeldung.web.MyUserDto; 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.dao.DuplicateKeyException; +import org.springframework.boot.test.context.SpringBootTest; import org.springframework.security.authentication.AuthenticationProvider; import org.springframework.security.authentication.BadCredentialsException; import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; import org.springframework.security.core.Authentication; -import org.springframework.security.core.userdetails.UsernameNotFoundException; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.context.web.WebAppConfiguration; -import static org.junit.Assert.*; -import java.util.logging.Level; -import java.util.logging.Logger; - -@RunWith(SpringJUnit4ClassRunner.class) -@SpringApplicationConfiguration(classes = { MvcConfig.class, PersistenceDerbyJPAConfig.class, SecSecurityConfig.class }) +@RunWith(SpringRunner.class) +@SpringBootTest(classes = { MvcConfig.class, PersistenceDerbyJPAConfig.class, SecSecurityConfig.class }) @WebAppConfiguration public class CustomUserDetailsServiceIntegrationTest {