From f9706e0e014413dcd12470321d7bd448ebd7cc35 Mon Sep 17 00:00:00 2001 From: Filip Izydorczyk Date: Thu, 8 Oct 2020 15:24:23 +0200 Subject: [PATCH] Tests works --- .../controllers/CommisionControllerTest.java | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java index fded47a..bf371d7 100755 --- a/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java +++ b/restservice/src/test/java/com/plannaplan/controllers/CommisionControllerTest.java @@ -4,6 +4,7 @@ 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.ContextConfiguration; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; @@ -12,6 +13,8 @@ import org.springframework.web.context.WebApplicationContext; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import java.nio.charset.Charset; + import com.plannaplan.entities.User; import com.plannaplan.services.UserService; import com.plannaplan.types.UserRoles; @@ -36,6 +39,8 @@ public class CommisionControllerTest { private static final String ADD_COMMISION_ENDPOINT = "/api/v1/commisions/add"; private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions"; private static final String TEST_COMMISIONS_EMAIL = "commisions@notexisting.domain"; + private static final MediaType APPLICATION_JSON_UTF8 = new MediaType(MediaType.APPLICATION_JSON.getType(), + MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8")); @Test public void shouldReturn4xxAddingCommision() throws Exception { @@ -45,13 +50,23 @@ public class CommisionControllerTest { } @Test - public void shouldReturnOkAddingCommision() throws Exception { + public void shouldFailedAddingCommisionDueToNoArgs() throws Exception { this.checkUser(); final String token = this.service.login(TEST_COMMISIONS_EMAIL); MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token)) - .andExpect(status().isOk()); + .andExpect(status().is4xxClientError()); + } + + @Test + public void shouldReturnOkAddingCommision() throws Exception { + this.checkUser(); + final String token = this.service.login(TEST_COMMISIONS_EMAIL); + + MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build(); + mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token) + .contentType(APPLICATION_JSON_UTF8).content("[]")).andExpect(status().isOk()); } @Test