Build optimization (#2591)

This commit is contained in:
Grzegorz Piwowarek
2017-09-09 16:55:05 +02:00
committed by GitHub
parent 4589860efb
commit f01d1e257e
9 changed files with 148 additions and 58 deletions

View File

@@ -5,7 +5,6 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>spring-rest-angular</artifactId>
<name>spring-rest-angular</name>
<groupId>com.baeldung</groupId>
<version>1.0</version>
<packaging>war</packaging>

View File

@@ -2,6 +2,7 @@ package com.baeldung.controllers;
import com.baeldung.services.ExampleService;
import com.baeldung.transfer.LoginForm;
import org.baeldung.web.main.Application;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -12,7 +13,6 @@ 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.baeldung.web.main.Application;
import static org.mockito.Mockito.when;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
@@ -21,11 +21,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class ExamplePostControllerRequestUnitTest {
public class ExamplePostControllerRequestIntegrationTest {
MockMvc mockMvc;
@Mock private ExampleService exampleService;
@InjectMocks private ExamplePostController exampleController;
@Mock
private ExampleService exampleService;
@InjectMocks
private ExamplePostController exampleController;
private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
private LoginForm lf = new LoginForm();

View File

@@ -2,6 +2,7 @@ package com.baeldung.controllers;
import com.baeldung.services.ExampleService;
import com.baeldung.transfer.LoginForm;
import org.baeldung.web.main.Application;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -10,7 +11,6 @@ import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.baeldung.web.main.Application;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
@@ -22,12 +22,16 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
@RunWith(SpringRunner.class)
@SpringBootTest(classes = Application.class)
public class ExamplePostControllerResponseUnitTest {
public class ExamplePostControllerResponseIntegrationTest {
private MockMvc mockMvc;
@Mock
private ExampleService exampleService;
@InjectMocks
private ExamplePostController exampleController;
MockMvc mockMvc;
@Mock private ExampleService exampleService;
@InjectMocks private ExamplePostController exampleController;
private final String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
private LoginForm lf = new LoginForm();
@Before
@@ -44,6 +48,7 @@ public class ExamplePostControllerResponseUnitTest {
public void requestBodyTest() {
try {
when(exampleService.fakeAuthenticate(lf)).thenReturn(true);
String jsonBody = "{\"username\": \"username\", \"password\": \"password\"}";
mockMvc
.perform(post("/post/response")
.content(jsonBody)

View File

@@ -1,10 +1,5 @@
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;
@@ -13,6 +8,11 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
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)
public class StudentServiceIntegrationTest {
@@ -21,7 +21,8 @@ public class StudentServiceIntegrationTest {
@Test
public void givenRequestForStudents_whenPageIsOne_expectContainsNames() {
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("content.name", hasItems("Bryan", "Ben"));
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat()
.body("content.name", hasItems("Bryan", "Ben"));
}
@Test
@@ -58,5 +59,4 @@ public class StudentServiceIntegrationTest {
public void givenResourcesExist_whenFirstPageIsRetrieved_thenPageContainsResources() {
given().params("page", "0", "size", "2").get(ENDPOINT).then().assertThat().body("first", equalTo(true));
}
}