JobInfoControllerTest.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.xxl.job.admin.controller;
  2. import com.xxl.job.admin.service.LoginService;
  3. import org.junit.Before;
  4. import org.junit.Test;
  5. import org.springframework.http.MediaType;
  6. import org.springframework.test.web.servlet.MvcResult;
  7. import org.springframework.util.LinkedMultiValueMap;
  8. import org.springframework.util.MultiValueMap;
  9. import javax.servlet.http.Cookie;
  10. import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
  11. public class JobInfoControllerTest extends AbstractSpringMvcTest {
  12. private Cookie cookie;
  13. @Before
  14. public void login() throws Exception {
  15. MvcResult ret = mockMvc.perform(
  16. post("/login")
  17. .contentType(MediaType.APPLICATION_FORM_URLENCODED)
  18. .param("userName", "admin")
  19. .param("password", "123456")
  20. ).andReturn();
  21. cookie = ret.getResponse().getCookie(LoginService.LOGIN_IDENTITY_KEY);
  22. }
  23. @Test
  24. public void testAdd() throws Exception {
  25. MultiValueMap<String, String> parameters = new LinkedMultiValueMap<String, String>();
  26. parameters.add("jobGroup", "1");
  27. MvcResult ret = mockMvc.perform(
  28. post("/jobinfo/pageList")
  29. .contentType(MediaType.APPLICATION_FORM_URLENCODED)
  30. //.content(paramsJson)
  31. .params(parameters)
  32. .cookie(cookie)
  33. ).andReturn();
  34. System.out.println(ret.getResponse().getContentAsString());
  35. }
  36. }