Migrated modules to parent-boot-2 usign spring-boot 2.1:

spring-mvc-forms-thymeleaf
spring-rest
spring-rest-angular
spring-rest-query-language
spring-rest-shell
spring-rest-simple
spring-rest-template
spring-resttemplate
spring-security-mvc-boot
spring-security-openid
spring-security-sso
spring-security-thymeleaf
This commit is contained in:
geroza
2018-12-11 12:17:29 -02:00
parent 743949afe6
commit 99dd82d2ff
22 changed files with 58 additions and 67 deletions

View File

@@ -8,10 +8,10 @@
<packaging>war</packaging>
<parent>
<artifactId>parent-boot-2.0-temp</artifactId>
<artifactId>parent-boot-2</artifactId>
<groupId>com.baeldung</groupId>
<version>0.0.1-SNAPSHOT</version>
<relativePath>../parent-boot-2.0-temp</relativePath>
<relativePath>../parent-boot-2</relativePath>
</parent>
<dependencies>

View File

@@ -6,12 +6,12 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.web.filter.ShallowEtagHeaderFilter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@SpringBootApplication
@EnableAutoConfiguration
@Import(PersistenceConfig.class)
public class Application extends WebMvcConfigurerAdapter {
public class Application implements WebMvcConfigurer {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);

View File

@@ -1,62 +1,66 @@
package org.baeldung.web.service;
import static io.restassured.RestAssured.given;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsCollectionContaining.hasItems;
import static org.hamcrest.core.IsEqual.equalTo;
import org.apache.commons.lang3.RandomStringUtils;
import org.baeldung.web.main.Application;
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.web.server.LocalServerPort;
import org.springframework.test.context.junit4.SpringRunner;
import static io.restassured.RestAssured.given;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsCollectionContaining.hasItems;
import static org.hamcrest.core.IsEqual.equalTo;
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.DEFINED_PORT)
@SpringBootTest(classes = Application.class, webEnvironment = WebEnvironment.RANDOM_PORT)
public class StudentServiceIntegrationTest {
@LocalServerPort
int port;
private static final String ENDPOINT = "http://localhost:8080/student/get";
private static final String ENDPOINT = "http://localhost:%s/student/get";
@Test
public void givenRequestForStudents_whenPageIsOne_expectContainsNames() {
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat()
given().params("page", "0", "size", "2").get(String.format(ENDPOINT, port)).then().assertThat()
.body("content.name", hasItems("Bryan", "Ben"));
}
@Test
public void givenRequestForStudents_whenSizeIsTwo_expectTwoItems() {
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("size", equalTo(2));
given().params("page", "0", "size", "2").get(String.format(ENDPOINT, port)).then().assertThat().body("size", equalTo(2));
}
@Test
public void givenRequestForStudents_whenSizeIsTwo_expectNumberOfElementsTwo() {
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("numberOfElements", equalTo(2));
given().params("page", "0", "size", "2").get(String.format(ENDPOINT, port)).then().assertThat().body("numberOfElements", equalTo(2));
}
@Test
public void givenRequestForStudents_whenResourcesAreRetrievedPaged_thenExpect200() {
given().params("page", "0", "size", "2").get(ENDPOINT).then().statusCode(200);
given().params("page", "0", "size", "2").get(String.format(ENDPOINT, port)).then().statusCode(200);
}
@Test
public void givenRequestForStudents_whenPageOfResourcesAreRetrievedOutOfBounds_thenExpect500() {
given().params("page", "1000", "size", "2").get(ENDPOINT).then().statusCode(500);
given().params("page", "1000", "size", "2").get(String.format(ENDPOINT, port)).then().statusCode(500);
}
@Test
public void givenRequestForStudents_whenPageNotValid_thenExpect500() {
given().params("page", RandomStringUtils.randomNumeric(5), "size", "2").get(ENDPOINT).then().statusCode(500);
given().params("page", RandomStringUtils.randomNumeric(5), "size", "2").get(String.format(ENDPOINT, port)).then().statusCode(500);
}
@Test
public void givenRequestForStudents_whenPageSizeIsFive_expectFiveItems() {
given().params("page", "0", "size", "5").get(ENDPOINT).then().body("content.size()", is(5));
given().params("page", "0", "size", "5").get(String.format(ENDPOINT, port)).then().body("content.size()", is(5));
}
@Test
public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() {
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("first", equalTo(true));
given().params("page", "0", "size", "2").get(String.format(ENDPOINT, port)).then().assertThat().body("first", equalTo(true));
}
}