Fixed spring-session integration tests (#4650)
This commit is contained in:
parent
3b7cb37379
commit
28166a73de
|
@ -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";
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
<artifactId>spring-boot-dynamodb</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>Spring Boot Actuator</name>
|
||||
<description>This is simple boot application for Spring boot actuator test</description>
|
||||
<name>spring-boot-dynamodb</name>
|
||||
<description>This is simple boot application for Spring boot dynamodb test</description>
|
||||
|
||||
<parent>
|
||||
<artifactId>parent-boot-1</artifactId>
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -70,6 +70,11 @@
|
|||
<artifactId>spring-data-commons</artifactId>
|
||||
<version>${spring-data-commons.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>${embedded-redis.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
|
@ -79,6 +84,7 @@
|
|||
<jedis.version>2.9.0</jedis.version>
|
||||
<nosqlunit.version>0.10.0</nosqlunit.version>
|
||||
<spring-data-commons.version>2.0.3.RELEASE</spring-data-commons.version>
|
||||
<embedded-redis.version>0.6</embedded-redis.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
spring.redis.host=localhost
|
||||
spring.redis.port=6379
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
|
||||
<properties>
|
||||
<rest-assured.version>3.0.1</rest-assured.version>
|
||||
<embedded-redis.version>0.6</embedded-redis.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
@ -57,6 +58,11 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>${embedded-redis.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<dependencyManagement>
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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{
|
||||
}
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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";
|
||||
|
|
@ -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<String> httpEntity = new HttpEntity<>(ADDRESS_ENDPOINT + "/1", requestHeaders);
|
||||
template.exchange(LIBRARY_ENDPOINT + "/1/libraryAddress", HttpMethod.PUT, httpEntity, String.class);
|
||||
HttpEntity<String> 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<Library> libraryGetResponse = template.getForEntity(ADDRESS_ENDPOINT + "/1/library", Library.class);
|
||||
ResponseEntity<Library> 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<String> 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<String> 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<Library> libraryGetResponse = template.getForEntity(BOOK_ENDPOINT + "/1/library", Library.class);
|
||||
ResponseEntity<Library> 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<String> httpEntity = new HttpEntity<>(BOOK_ENDPOINT + "/1\n" + BOOK_ENDPOINT + "/2", requestHeaders);
|
||||
template.exchange(AUTHOR_ENDPOINT + "/1/books", HttpMethod.PUT, httpEntity, String.class);
|
||||
HttpEntity<String> 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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -29,6 +29,12 @@
|
|||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.flapdoodle.embed</groupId>
|
||||
<artifactId>de.flapdoodle.embed.mongo</artifactId>
|
||||
<version>${de.flapdoodle.embed.mongo.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
@ -73,6 +79,7 @@
|
|||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<checkstyle.version>2.17</checkstyle.version>
|
||||
<de.flapdoodle.embed.mongo.version>2.0.0</de.flapdoodle.embed.mongo.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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 {
|
||||
|
||||
}
|
|
@ -122,6 +122,14 @@
|
|||
<artifactId>json</artifactId>
|
||||
<version>${json.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.maven.surefire</groupId>
|
||||
<artifactId>surefire-logger-api</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<!-- to get around bug https://github.com/junit-team/junit5/issues/1367 -->
|
||||
<scope>test</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<pluginManagement>
|
||||
|
|
|
@ -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;
|
|
@ -30,6 +30,15 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.kstyrc</groupId>
|
||||
<artifactId>embedded-redis</artifactId>
|
||||
<version>${embedded-redis.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<properties>
|
||||
<embedded-redis.version>0.6</embedded-redis.version>
|
||||
</properties>
|
||||
|
||||
</project>
|
|
@ -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();
|
||||
|
|
|
@ -217,11 +217,11 @@
|
|||
<properties>
|
||||
<!-- Spring -->
|
||||
<org.springframework.security.version>4.2.6.RELEASE</org.springframework.security.version>
|
||||
<spring-boot.version>1.4.2.RELEASE</spring-boot.version>
|
||||
<spring-boot.version>1.5.14.RELEASE</spring-boot.version>
|
||||
<javassist.version>3.21.0-GA</javassist.version>
|
||||
|
||||
<!-- persistence -->
|
||||
<hibernate.version>5.2.5.Final</hibernate.version>
|
||||
<hibernate.version>5.2.10.Final</hibernate.version>
|
||||
<mysql-connector-java.version>5.1.40</mysql-connector-java.version>
|
||||
<spring-data-jpa.version>1.10.5.RELEASE</spring-data-jpa.version>
|
||||
<h2.version>1.4.193</h2.version>
|
||||
|
|
|
@ -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
|
|
@ -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 {
|
||||
|
||||
|
|
Loading…
Reference in New Issue