Tests works
This commit is contained in:
parent
f9dd6e38c3
commit
f9706e0e01
@ -4,6 +4,7 @@ import org.junit.Test;
|
|||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
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 static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||||
|
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
|
||||||
import com.plannaplan.entities.User;
|
import com.plannaplan.entities.User;
|
||||||
import com.plannaplan.services.UserService;
|
import com.plannaplan.services.UserService;
|
||||||
import com.plannaplan.types.UserRoles;
|
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 ADD_COMMISION_ENDPOINT = "/api/v1/commisions/add";
|
||||||
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions";
|
private static final String GET_COMMISIONS_ENDPOINT = "/api/v1/commisions/getAllCommisions";
|
||||||
private static final String TEST_COMMISIONS_EMAIL = "commisions@notexisting.domain";
|
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
|
@Test
|
||||||
public void shouldReturn4xxAddingCommision() throws Exception {
|
public void shouldReturn4xxAddingCommision() throws Exception {
|
||||||
@ -45,13 +50,23 @@ public class CommisionControllerTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldReturnOkAddingCommision() throws Exception {
|
public void shouldFailedAddingCommisionDueToNoArgs() throws Exception {
|
||||||
this.checkUser();
|
this.checkUser();
|
||||||
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
final String token = this.service.login(TEST_COMMISIONS_EMAIL);
|
||||||
|
|
||||||
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
MockMvc mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
|
||||||
mockMvc.perform(post(ADD_COMMISION_ENDPOINT).header("Authorization", "Bearer " + token))
|
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
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user