parent
d47658b982
commit
9f77e62faa
@ -0,0 +1,25 @@
|
|||||||
|
package com.xxl.job.admin.controller;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
import org.springframework.test.context.web.WebAppConfiguration;
|
||||||
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||||
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
|
|
||||||
|
@WebAppConfiguration
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(locations = {"classpath*:spring/*.xml"})
|
||||||
|
public class AbstractSpringMvcTest {
|
||||||
|
@Autowired
|
||||||
|
private WebApplicationContext applicationContext;
|
||||||
|
protected MockMvc mockMvc;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.applicationContext).build();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,22 @@
|
|||||||
|
package com.xxl.job.admin.controller;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
|
public class IndexControllerTest extends AbstractSpringMvcTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogin() throws Exception {
|
||||||
|
MvcResult ret = mockMvc.perform(
|
||||||
|
post("/login")
|
||||||
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
.param("userName", "admin")
|
||||||
|
.param("password", "123456")
|
||||||
|
).andReturn();
|
||||||
|
|
||||||
|
System.out.println(ret.getResponse().getContentAsString());
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,52 @@
|
|||||||
|
package com.xxl.job.admin.controller;
|
||||||
|
|
||||||
|
import com.xxl.job.admin.core.model.XxlJobInfo;
|
||||||
|
import org.codehaus.jackson.map.ObjectMapper;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.springframework.http.MediaType;
|
||||||
|
import org.springframework.test.web.servlet.MvcResult;
|
||||||
|
|
||||||
|
import javax.servlet.http.Cookie;
|
||||||
|
|
||||||
|
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
|
||||||
|
|
||||||
|
public class JobInfoControllerTest extends AbstractSpringMvcTest {
|
||||||
|
Cookie cookie;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void login() throws Exception {
|
||||||
|
MvcResult ret = mockMvc.perform(
|
||||||
|
post("/login")
|
||||||
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
.param("userName", "admin")
|
||||||
|
.param("password", "123456")
|
||||||
|
).andReturn();
|
||||||
|
cookie = ret.getResponse().getCookie("LOGIN_IDENTITY");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testAdd() throws Exception {
|
||||||
|
XxlJobInfo jobInfo = new XxlJobInfo();
|
||||||
|
jobInfo.setJobGroup(1);
|
||||||
|
jobInfo.setJobDesc("autoEnquiryStatisPerWeek");
|
||||||
|
jobInfo.setExecutorRouteStrategy("FIRST");
|
||||||
|
jobInfo.setJobCron("0 0 1 ? * MON");
|
||||||
|
jobInfo.setGlueType("BEAN");
|
||||||
|
jobInfo.setExecutorHandler("AutoEnquriy");
|
||||||
|
jobInfo.setExecutorBlockStrategy("SERIAL_EXECUTION");
|
||||||
|
jobInfo.setExecutorFailStrategy("FAIL_ALARM");
|
||||||
|
jobInfo.setAuthor("listening");
|
||||||
|
|
||||||
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
|
String jobInfoStr = mapper.writeValueAsString(jobInfo);
|
||||||
|
MvcResult ret = mockMvc.perform(
|
||||||
|
post("/jobinfo/add")
|
||||||
|
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
.content(jobInfoStr)
|
||||||
|
.cookie(cookie)
|
||||||
|
).andReturn();
|
||||||
|
|
||||||
|
System.out.println(ret.getResponse().getContentAsString());
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue