Browse Source

update escheduler-api unit test

pull/3/MERGE
lidongdai 5 years ago
parent
commit
7992f5303d
  1. 8
      escheduler-api/src/main/java/cn/escheduler/api/service/ResourcesService.java
  2. 12
      escheduler-api/src/test/java/cn/escheduler/api/controller/ProcessDefinitionControllerTest.java
  3. 34
      escheduler-api/src/test/java/cn/escheduler/api/controller/ProcessInstanceControllerTest.java
  4. 19
      escheduler-api/src/test/java/cn/escheduler/api/controller/ProjectControllerTest.java
  5. 43
      escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java
  6. 32
      escheduler-api/src/test/java/cn/escheduler/api/controller/ResourcesControllerTest.java
  7. 32
      escheduler-api/src/test/java/cn/escheduler/api/controller/SchedulerControllerTest.java
  8. 28
      escheduler-api/src/test/java/cn/escheduler/api/controller/TaskInstanceControllerTest.java
  9. 29
      escheduler-api/src/test/java/cn/escheduler/api/controller/TenantControllerTest.java
  10. 27
      escheduler-api/src/test/java/cn/escheduler/api/controller/UsersControllerTest.java
  11. 2
      escheduler-dao/src/test/java/cn/escheduler/dao/mapper/WorkerGroupMapperTest.java

8
escheduler-api/src/main/java/cn/escheduler/api/service/ResourcesService.java

@ -27,6 +27,7 @@ import cn.escheduler.common.utils.HadoopUtils;
import cn.escheduler.common.utils.PropertyUtils; import cn.escheduler.common.utils.PropertyUtils;
import cn.escheduler.dao.mapper.*; import cn.escheduler.dao.mapper.*;
import cn.escheduler.dao.model.Resource; import cn.escheduler.dao.model.Resource;
import cn.escheduler.dao.model.Tenant;
import cn.escheduler.dao.model.UdfFunc; import cn.escheduler.dao.model.UdfFunc;
import cn.escheduler.dao.model.User; import cn.escheduler.dao.model.User;
import org.apache.commons.collections.BeanMap; import org.apache.commons.collections.BeanMap;
@ -441,7 +442,9 @@ public class ResourcesService extends BaseService {
putMsg(result, Status.RESOURCE_EXIST); putMsg(result, Status.RESOURCE_EXIST);
} else { } else {
// query tenant // query tenant
String tenantCode = tenantMapper.queryById(loginUser.getTenantId()).getTenantCode(); Tenant tenant = tenantMapper.queryById(loginUser.getTenantId());
if(tenant != null){
String tenantCode = tenant.getTenantCode();
try { try {
String hdfsFilename = getHdfsFileName(type,tenantCode,name); String hdfsFilename = getHdfsFileName(type,tenantCode,name);
@ -454,6 +457,9 @@ public class ResourcesService extends BaseService {
logger.error(e.getMessage(),e); logger.error(e.getMessage(),e);
putMsg(result,Status.HDFS_OPERATION_ERROR); putMsg(result,Status.HDFS_OPERATION_ERROR);
} }
}else{
putMsg(result,Status.TENANT_NOT_EXIST);
}
} }

12
escheduler-api/src/test/java/cn/escheduler/api/controller/ProcessDefinitionControllerTest.java

@ -20,22 +20,13 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@ -44,7 +35,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
/** /**
* process definition controller test * process definition controller test
*/ */
@Ignore
public class ProcessDefinitionControllerTest extends AbstractControllerTest{ public class ProcessDefinitionControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(ProcessDefinitionControllerTest.class); private static Logger logger = LoggerFactory.getLogger(ProcessDefinitionControllerTest.class);
@ -69,7 +59,7 @@ public class ProcessDefinitionControllerTest extends AbstractControllerTest{
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.PROJECT_NOT_FOUNT.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
} }

34
escheduler-api/src/test/java/cn/escheduler/api/controller/ProcessInstanceControllerTest.java

@ -20,55 +20,35 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore /**
@RunWith(SpringRunner.class) * process instance controller test
@SpringBootTest */
public class ProcessInstanceControllerTest { public class ProcessInstanceControllerTest extends AbstractControllerTest {
private static Logger logger = LoggerFactory.getLogger(ProcessInstanceControllerTest.class); private static Logger logger = LoggerFactory.getLogger(ProcessInstanceControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void queryTaskListByProcessId() throws Exception { public void queryTaskListByProcessId() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/task-list-by-process-id","project_test1") MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/instance/task-list-by-process-id","project_test1")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82") .header(SESSION_ID, sessionId)
.param("processInstanceId","1370")) .param("processInstanceId","-1"))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.PROJECT_NOT_FOUNT,result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
} }

19
escheduler-api/src/test/java/cn/escheduler/api/controller/ProjectControllerTest.java

@ -20,22 +20,13 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
@ -47,15 +38,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
public class ProjectControllerTest extends AbstractControllerTest{ public class ProjectControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(ProcessInstanceControllerTest.class); private static Logger logger = LoggerFactory.getLogger(ProcessInstanceControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void createProject() throws Exception { public void createProject() throws Exception {
@ -64,7 +47,7 @@ public class ProjectControllerTest extends AbstractControllerTest{
paramsMap.add("desc","the test project"); paramsMap.add("desc","the test project");
MvcResult mvcResult = mockMvc.perform(post("/projects/create") MvcResult mvcResult = mockMvc.perform(post("/projects/create")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82") .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

43
escheduler-api/src/test/java/cn/escheduler/api/controller/QueueControllerTest.java

@ -20,48 +20,31 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore /**
@RunWith(SpringRunner.class) * queue controller test
@SpringBootTest */
public class QueueControllerTest { public class QueueControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(QueueControllerTest.class);
private MockMvc mockMvc;
@Autowired private static Logger logger = LoggerFactory.getLogger(QueueControllerTest.class);
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void queryList() throws Exception { public void queryList() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/queue/list") MvcResult mvcResult = mockMvc.perform(get("/queue/list")
.header("sessionId", "d199af92-d8e0-4f1b-bacb-5b3414567e5c")) .header(SESSION_ID, sessionId))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
@ -81,7 +64,7 @@ public class QueueControllerTest {
paramsMap.add("pageSize","20"); paramsMap.add("pageSize","20");
MvcResult mvcResult = mockMvc.perform(get("/queue/list-paging") MvcResult mvcResult = mockMvc.perform(get("/queue/list-paging")
.header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91") .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -95,11 +78,11 @@ public class QueueControllerTest {
public void createQueue() throws Exception { public void createQueue() throws Exception {
MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>(); MultiValueMap<String, String> paramsMap = new LinkedMultiValueMap<>();
paramsMap.add("queue","ait111134"); paramsMap.add("queue","ait");
paramsMap.add("queueName","aitName1"); paramsMap.add("queueName","ait");
MvcResult mvcResult = mockMvc.perform(post("/queue/create") MvcResult mvcResult = mockMvc.perform(post("/queue/create")
.header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91") .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -107,6 +90,8 @@ public class QueueControllerTest {
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
// Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); // Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
@Test @Test
@ -118,7 +103,7 @@ public class QueueControllerTest {
paramsMap.add("queueName","aitName"); paramsMap.add("queueName","aitName");
MvcResult mvcResult = mockMvc.perform(post("/queue/update") MvcResult mvcResult = mockMvc.perform(post("/queue/update")
.header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91") .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -136,7 +121,7 @@ public class QueueControllerTest {
paramsMap.add("queueName","aitName"); paramsMap.add("queueName","aitName");
MvcResult mvcResult = mockMvc.perform(post("/queue/verify-queue") MvcResult mvcResult = mockMvc.perform(post("/queue/verify-queue")
.header("sessionId", "d4541e0d-0349-4f05-9c68-300176cd3c91") .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

32
escheduler-api/src/test/java/cn/escheduler/api/controller/ResourcesControllerTest.java

@ -22,47 +22,29 @@ import cn.escheduler.common.enums.ResourceType;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore /**
@RunWith(SpringRunner.class) * resources controller test
@SpringBootTest */
public class ResourcesControllerTest { public class ResourcesControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(ResourcesControllerTest.class); private static Logger logger = LoggerFactory.getLogger(ResourcesControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void querytResourceList() throws Exception { public void querytResourceList() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/resources/list") MvcResult mvcResult = mockMvc.perform(get("/resources/list")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82") .header(SESSION_ID, sessionId)
.param("type", ResourceType.FILE.name())) .param("type", ResourceType.FILE.name()))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -84,7 +66,7 @@ public class ResourcesControllerTest {
paramsMap.add("type","FILE"); paramsMap.add("type","FILE");
MvcResult mvcResult = mockMvc.perform(get("/resources/verify-name") MvcResult mvcResult = mockMvc.perform(get("/resources/verify-name")
.header("sessionId", "c24ed9d9-1c20-48a0-bd9c-5cfca14a4dcb") .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
@ -92,7 +74,7 @@ public class ResourcesControllerTest {
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.TENANT_NOT_EXIST.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
} }

32
escheduler-api/src/test/java/cn/escheduler/api/controller/SchedulerControllerTest.java

@ -20,44 +20,26 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore /**
@RunWith(SpringRunner.class) * scheduler controller test
@SpringBootTest */
public class SchedulerControllerTest { public class SchedulerControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class); private static Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void queryScheduleList() throws Exception { public void queryScheduleList() throws Exception {
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/list","project_test1") MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/list","project_test1")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82")) .header(SESSION_ID, sessionId))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
@ -66,10 +48,12 @@ public class SchedulerControllerTest {
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());
} }
@Test @Test
public void previewSchedule() throws Exception { public void previewSchedule() throws Exception {
MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/preview","li_test_1") MvcResult mvcResult = mockMvc.perform(post("/projects/{projectName}/schedule/preview","li_test_1")
.header("sessionId", "c24ed9d9-1c20-48a0-bd9c-5cfca14a4dcb") .header(SESSION_ID, sessionId)
.param("schedule","{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}")) .param("schedule","{'startTime':'2019-06-10 00:00:00','endTime':'2019-06-13 00:00:00','crontab':'0 0 3/6 * * ? *'}"))
.andExpect(status().isCreated()) .andExpect(status().isCreated())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

28
escheduler-api/src/test/java/cn/escheduler/api/controller/TaskInstanceControllerTest.java

@ -20,42 +20,24 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.util.LinkedMultiValueMap; import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap; import org.springframework.util.MultiValueMap;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore /**
@RunWith(SpringRunner.class) * task instance controller test
@SpringBootTest */
public class TaskInstanceControllerTest { public class TaskInstanceControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class); private static Logger logger = LoggerFactory.getLogger(SchedulerControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void queryTaskListPaging() throws Exception { public void queryTaskListPaging() throws Exception {
@ -70,7 +52,7 @@ public class TaskInstanceControllerTest {
paramsMap.add("pageSize","20"); paramsMap.add("pageSize","20");
MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/task-instance/list-paging","project_test1") MvcResult mvcResult = mockMvc.perform(get("/projects/{projectName}/task-instance/list-paging","project_test1")
.header("sessionId", "08fae8bf-fe2d-4fc0-8129-23c37fbfac82") .header(SESSION_ID, sessionId)
.params(paramsMap)) .params(paramsMap))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))

29
escheduler-api/src/test/java/cn/escheduler/api/controller/TenantControllerTest.java

@ -20,50 +20,33 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore /**
@RunWith(SpringRunner.class) * tenant controller test
@SpringBootTest */
public class TenantControllerTest { public class TenantControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(DataAnalysisControllerTest.class); private static Logger logger = LoggerFactory.getLogger(DataAnalysisControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void countTaskState() throws Exception { public void countTaskState() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/tenant/list") MvcResult mvcResult = mockMvc.perform(get("/tenant/list")
.header("sessionId", "d199af92-d8e0-4f1b-bacb-5b3414567e5c")) .header(SESSION_ID, sessionId))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();
Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class); Result result = JSONUtils.parseObject(mvcResult.getResponse().getContentAsString(), Result.class);
Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue()); Assert.assertEquals(Status.SUCCESS.getCode(),result.getCode().intValue());
logger.info(mvcResult.getResponse().getContentAsString()); logger.info(mvcResult.getResponse().getContentAsString());

27
escheduler-api/src/test/java/cn/escheduler/api/controller/UsersControllerTest.java

@ -20,45 +20,28 @@ import cn.escheduler.api.enums.Status;
import cn.escheduler.api.utils.Result; import cn.escheduler.api.utils.Result;
import cn.escheduler.common.utils.JSONUtils; import cn.escheduler.common.utils.JSONUtils;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; import org.springframework.http.MediaType;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.MvcResult;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@Ignore /**
@RunWith(SpringRunner.class) * users controller test
@SpringBootTest */
public class UsersControllerTest { public class UsersControllerTest extends AbstractControllerTest{
private static Logger logger = LoggerFactory.getLogger(QueueControllerTest.class); private static Logger logger = LoggerFactory.getLogger(QueueControllerTest.class);
private MockMvc mockMvc;
@Autowired
private WebApplicationContext webApplicationContext;
@Before
public void setUp() {
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
}
@Test @Test
public void queryList() throws Exception { public void queryList() throws Exception {
MvcResult mvcResult = mockMvc.perform(get("/users/list") MvcResult mvcResult = mockMvc.perform(get("/users/list")
.header("sessionId", "d199af92-d8e0-4f1b-bacb-5b3414567e5c")) .header(SESSION_ID, sessionId))
.andExpect(status().isOk()) .andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andReturn(); .andReturn();

2
escheduler-dao/src/test/java/cn/escheduler/dao/mapper/WorkerGroupMapperTest.java

@ -20,7 +20,6 @@ import cn.escheduler.dao.datasource.ConnectionFactory;
import cn.escheduler.dao.model.WorkerGroup; import cn.escheduler.dao.model.WorkerGroup;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import java.util.Date; import java.util.Date;
@ -29,7 +28,6 @@ import java.util.List;
/** /**
* worker group mapper test * worker group mapper test
*/ */
@Ignore
public class WorkerGroupMapperTest { public class WorkerGroupMapperTest {
WorkerGroupMapper workerGroupMapper; WorkerGroupMapper workerGroupMapper;

Loading…
Cancel
Save