Add UserController test

This commit is contained in:
cugurlu
2019-03-18 00:34:26 +01:00
parent 8864320832
commit 2546355eba

View File

@@ -1,63 +1,57 @@
//package greenify.server.rest; package greenify.server.rest;
//
//import greenify.common.UserDto; import static org.mockito.BDDMockito.given;
//import greenify.server.data.model.User; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
//import greenify.server.service.UserService; import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
//import org.junit.Test; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
//import org.junit.runner.RunWith; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; import greenify.common.UserDto;
//import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import greenify.server.service.UserService;
//import org.springframework.boot.test.context.SpringBootTest; import org.junit.Test;
//import org.springframework.boot.test.mock.mockito.MockBean; import org.junit.runner.RunWith;
//import org.springframework.context.ApplicationContext; import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.http.MediaType; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
//import org.springframework.test.context.junit4.SpringRunner; import org.springframework.boot.test.mock.mockito.MockBean;
//import org.springframework.test.web.servlet.MockMvc; import org.springframework.context.ApplicationContext;
//import org.springframework.test.web.servlet.ResultMatcher; import org.springframework.http.MediaType;
//import static org.assertj.core.internal.bytebuddy.matcher.ElementMatchers.is; import org.springframework.test.context.junit4.SpringRunner;
//import static org.hamcrest.Matchers.hasSize; import org.springframework.test.web.servlet.MockMvc;
//import static org.mockito.BDDMockito.given;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; @RunWith(SpringRunner.class)
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; @WebMvcTest(UserController.class)
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; public class UserControllerTest {
//
//@RunWith(SpringRunner.class) @Autowired
//@SpringBootTest private MockMvc mvc;
//@AutoConfigureMockMvc
//@AutoConfigureTestDatabase @Autowired
//public class UserControllerTest { private ApplicationContext applicationContext;
//
// @Autowired @MockBean
// private MockMvc mvc; private UserService userService;
//
// @Autowired @Test
// private ApplicationContext applicationContext; public void registerUserTest() throws Exception {
// given(this.userService.registerUser("name", "password"))
// @MockBean .willReturn(new UserDto(1L, "name"));
// private UserService userService; mvc.perform(get("/registerUser")
// .param("name", "name")
// @Test .param("password", "password")
// public void getVehicleWhenRequestingTextShouldReturnMakeAndModel() throws Exception { .accept(MediaType.APPLICATION_JSON))
// given(this.userService.loginUser("name", "password")) .andDo(print())
// .willReturn(new UserDto(1L, "name")); .andExpect(status().isOk()).andExpect(content().json("{'id':1,'name':'name'}"));
// this.mvc.perform(get("/loginUser").accept(MediaType.APPLICATION_JSON)) }
// .andExpect(status().isOk())
// .andExpect(content() @Test
// .json("name=name, password=password")); public void loginUserTest() throws Exception {
// } given(this.userService.loginUser("ceren", "password"))
// .willReturn(new UserDto(1L, "ceren"));
// mvc.perform(get("/loginUser")
// @Test .param("name", "ceren")
// public void givenEmployees_whenGetEmployees_thenReturnJsonArray() throws Exception { .param("password", "password")
// User alex = new User(1L, "alex", "password", 0); .accept(MediaType.APPLICATION_JSON))
// UserDto user = userService.loginUser("alex", "password"); .andDo(print())
// given(userService.loginUser("alex", "password")).willReturn(user); .andExpect(status().isOk()).andExpect(content().json("{'id':1,'name':'ceren'}"));
// mvc.perform(get("/loginUser") }
// .contentType(MediaType.ALL)) }
// .andExpect(status().isOk())
// .andExpect(jsonPath("$", hasSize(1)))
// .andExpect((ResultMatcher) jsonPath("$[0].name", is(alex.getName())))
// .andExpect((ResultMatcher) jsonPath("$[0].password", is(alex.getPassword())));
// }
//}