@ -17,314 +17,259 @@
package org.apache.dolphinscheduler.api.controller ;
package org.apache.dolphinscheduler.api.controller ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.enums.Status ;
import org.apache.dolphinscheduler.api.service.ProcessDefinitionService ;
import org.apache.dolphinscheduler.api.utils.Result ;
import org.apache.dolphinscheduler.api.utils.Result ;
import org.apache.dolphinscheduler.common.Constants ;
import org.apache.dolphinscheduler.common.enums.ReleaseState ;
import org.apache.dolphinscheduler.common.enums.ReleaseState ;
import org.apache.dolphinscheduler.common.utils.JSONUtils ;
import org.apache.dolphinscheduler.common.enums.UserType ;
import org.junit.Assert ;
import org.apache.dolphinscheduler.common.model.TaskNode ;
import org.junit.Ignore ;
import org.apache.dolphinscheduler.dao.entity.ProcessDefinition ;
import org.junit.Test ;
import org.apache.dolphinscheduler.dao.entity.User ;
import org.junit.* ;
import org.junit.runner.RunWith ;
import org.mockito.InjectMocks ;
import org.mockito.Mock ;
import org.mockito.Mockito ;
import org.mockito.junit.MockitoJUnitRunner ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import org.springframework.http.MediaType ;
import java.text.MessageFormat ;
import org.springframework.test.web.servlet.MvcResult ;
import java.util.ArrayList ;
import org.springframework.util.LinkedMultiValueMap ;
import java.util.HashMap ;
import org.springframework.util.MultiValueMap ;
import java.util.List ;
import java.util.Map ;
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.result.MockMvcResultMatchers.content ;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status ;
/ * *
/ * *
* process definition controller test
* process definition controller test
* /
* /
public class ProcessDefinitionControllerTest extends AbstractControllerTest {
@RunWith ( MockitoJUnitRunner . Silent . class )
public class ProcessDefinitionControllerTest {
private static Logger logger = LoggerFactory . getLogger ( ProcessDefinitionControllerTest . class ) ;
private static Logger logger = LoggerFactory . getLogger ( ProcessDefinitionControllerTest . class ) ;
@InjectMocks
private ProcessDefinitionController processDefinitionController ;
@Mock
private ProcessDefinitionService processDefinitionService ;
protected User user ;
@Before
public void before ( ) {
User loginUser = new User ( ) ;
loginUser . setId ( 1 ) ;
loginUser . setUserType ( UserType . GENERAL_USER ) ;
loginUser . setUserName ( "admin" ) ;
user = loginUser ;
}
@Test
@Test
public void testCreateProcessDefinition ( ) throws Exception {
public void testCreateProcessDefinition ( ) throws Exception {
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}" ;
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}" ;
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ;
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ;
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
String projectName = "test" ;
paramsMap . add ( "name" , "dag_test" ) ;
String name = "dag_test" ;
paramsMap . add ( "processDefinitionJson" , json ) ;
String description = "desc test" ;
paramsMap . add ( "locations" , locations ) ;
String connects = "[]" ;
paramsMap . add ( "connects" , "[]" ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
paramsMap . add ( "description" , "desc test" ) ;
putMsg ( result , Status . SUCCESS ) ;
result . put ( "processDefinitionId" , 1 ) ;
MvcResult mvcResult = mockMvc . perform ( post ( "/projects/{projectName}/process/save" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isCreated ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
Mockito . when ( processDefinitionService . createProcessDefinition ( user , projectName , name , json ,
description , locations , connects ) ) . thenReturn ( result ) ;
@Test
Result response = processDefinitionController . createProcessDefinition ( user , projectName , name , json ,
public void testVerifyProccessDefinitionName ( ) throws Exception {
locations , connects , description ) ;
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
paramsMap . add ( "name" , "dag_test" ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/verify-name" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_EXIST . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
@Test
private void putMsg ( Map < String , Object > result , Status status , Object . . . statusParams ) {
public void testVerifyProccessDefinitionNameNotExit ( ) throws Exception {
result . put ( Constants . STATUS , status ) ;
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
if ( statusParams ! = null & & statusParams . length > 0 ) {
paramsMap . add ( "name" , "dag_test_1" ) ;
result . put ( Constants . MSG , MessageFormat . format ( status . getMsg ( ) , statusParams ) ) ;
} else {
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/verify-name" , "cxc_1113" )
result . put ( Constants . MSG , status . getMsg ( ) ) ;
. header ( SESSION_ID , sessionId )
}
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
@Test
public void testVerifyProcessDefinitionName ( ) throws Exception {
Map < String , Object > result = new HashMap < > ( 5 ) ;
putMsg ( result , Status . PROCESS_INSTANCE_EXIST ) ;
String projectName = "test" ;
String name = "dag_test" ;
Mockito . when ( processDefinitionService . verifyProcessDefinitionName ( user , projectName , name ) ) . thenReturn ( result ) ;
Result response = processDefinitionController . verifyProcessDefinitionName ( user , projectName , name ) ;
Assert . assertEquals ( Status . PROCESS_INSTANCE_EXIST . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
}
@Test
@Test
public void UpdateProccessDefinition ( ) throws Exception {
public void UpdateProcessDefinition ( ) throws Exception {
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}" ;
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}" ;
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ;
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ;
String projectName = "test" ;
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
String name = "dag_test" ;
paramsMap . add ( "name" , "dag_test_update" ) ;
String description = "desc test" ;
paramsMap . add ( "id" , "91" ) ;
String connects = "[]" ;
paramsMap . add ( "processDefinitionJson" , json ) ;
int id = 1 ;
paramsMap . add ( "locations" , locations ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
paramsMap . add ( "connects" , "[]" ) ;
putMsg ( result , Status . SUCCESS ) ;
paramsMap . add ( "description" , "desc test update" ) ;
result . put ( "processDefinitionId" , 1 ) ;
MvcResult mvcResult = mockMvc . perform ( post ( "/projects/{projectName}/process/update" , "cxc_1113" )
Mockito . when ( processDefinitionService . updateProcessDefinition ( user , projectName , id , name , json ,
. header ( SESSION_ID , sessionId )
description , locations , connects ) ) . thenReturn ( result ) ;
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
Result response = processDefinitionController . updateProcessDefinition ( user , projectName , name , id , json ,
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
locations , connects , description ) ;
. andReturn ( ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
@Test
@Test
public void testReleaseProccessDefinition ( ) throws Exception {
public void testReleaseProcessDefinition ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
String projectName = "test" ;
paramsMap . add ( "processId" , "91" ) ;
int id = 1 ;
paramsMap . add ( "releaseState" , String . valueOf ( ReleaseState . OFFLINE ) ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
putMsg ( result , Status . SUCCESS ) ;
MvcResult mvcResult = mockMvc . perform ( post ( "/projects/{projectName}/process/release" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
Mockito . when ( processDefinitionService . releaseProcessDefinition ( user , projectName , id , ReleaseState . OFFLINE . ordinal ( ) ) ) . thenReturn ( result ) ;
. params ( paramsMap ) )
Result response = processDefinitionController . releaseProcessDefinition ( user , projectName , id , ReleaseState . OFFLINE . ordinal ( ) ) ;
. andExpect ( status ( ) . isOk ( ) )
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
@Test
@Test
public void testQueryProccessDefinitionById ( ) throws Exception {
public void testQueryProcessDefinitionById ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
paramsMap . add ( "processId" , "91" ) ;
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}" ;
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/select-by-id" , "cxc_1113" )
String projectName = "test" ;
. header ( SESSION_ID , sessionId )
String name = "dag_test" ;
. params ( paramsMap ) )
String description = "desc test" ;
. andExpect ( status ( ) . isOk ( ) )
String connects = "[]" ;
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
int id = 1 ;
. andReturn ( ) ;
ProcessDefinition processDefinition = new ProcessDefinition ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
processDefinition . setProjectName ( projectName ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
processDefinition . setConnects ( connects ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
processDefinition . setDescription ( description ) ;
processDefinition . setId ( id ) ;
processDefinition . setLocations ( locations ) ;
processDefinition . setName ( name ) ;
processDefinition . setProcessDefinitionJson ( json ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
putMsg ( result , Status . SUCCESS ) ;
result . put ( Constants . DATA_LIST , processDefinition ) ;
Mockito . when ( processDefinitionService . queryProcessDefinitionById ( user , projectName , id ) ) . thenReturn ( result ) ;
Result response = processDefinitionController . queryProcessDefinitionById ( user , projectName , id ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
}
}
@Test
@Test
public void testQueryProccessDefinitionList ( ) throws Exception {
public void testQueryProcessDefinitionList ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/list" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
String projectName = "test" ;
List < ProcessDefinition > resourceList = getDefinitionList ( ) ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
putMsg ( result , Status . SUCCESS ) ;
result . put ( Constants . DATA_LIST , resourceList ) ;
@Test
public void testQueryProcessDefinitionListPaging ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
paramsMap . add ( "pageNo" , "1" ) ;
paramsMap . add ( "searchVal" , "test" ) ;
paramsMap . add ( "userId" , "" ) ;
paramsMap . add ( "pageSize" , "1" ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/list-paging" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
@Test
Mockito . when ( processDefinitionService . queryProcessDefinitionList ( user , projectName ) ) . thenReturn ( result ) ;
public void testViewTree ( ) throws Exception {
Result response = processDefinitionController . queryProcessDefinitionList ( user , projectName ) ;
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
paramsMap . add ( "processId" , "91" ) ;
paramsMap . add ( "limit" , "30" ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/view-tree" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
@Test
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
public void testGetNodeListByDefinitionId ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
paramsMap . add ( "processDefinitionId" , "40" ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/gen-task-list" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
@Test
public List < ProcessDefinition > getDefinitionList ( ) {
public void testGetNodeListByDefinitionIdList ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
paramsMap . add ( "processDefinitionIdList" , "40,90,91" ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/get-task-list" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
List < ProcessDefinition > resourceList = new ArrayList < > ( ) ;
String json = "{\"globalParams\":[],\"tasks\":[{\"type\":\"SHELL\",\"id\":\"tasks-36196\",\"name\":\"ssh_test1\",\"params\":{\"resourceList\":[],\"localParams\":[],\"rawScript\":\"aa=\\\"1234\\\"\\necho ${aa}\"},\"desc\":\"\",\"runFlag\":\"NORMAL\",\"dependence\":{},\"maxRetryTimes\":\"0\",\"retryInterval\":\"1\",\"timeout\":{\"strategy\":\"\",\"interval\":null,\"enable\":false},\"taskInstancePriority\":\"MEDIUM\",\"workerGroupId\":-1,\"preTasks\":[]}],\"tenantId\":-1,\"timeout\":0}" ;
String locations = "{\"tasks-36196\":{\"name\":\"ssh_test1\",\"targetarr\":\"\",\"x\":141,\"y\":70}}" ;
String projectName = "test" ;
String name = "dag_test" ;
String description = "desc test" ;
String connects = "[]" ;
int id = 1 ;
ProcessDefinition processDefinition = new ProcessDefinition ( ) ;
processDefinition . setProjectName ( projectName ) ;
processDefinition . setConnects ( connects ) ;
processDefinition . setDescription ( description ) ;
processDefinition . setId ( id ) ;
processDefinition . setLocations ( locations ) ;
processDefinition . setName ( name ) ;
processDefinition . setProcessDefinitionJson ( json ) ;
String name2 = "dag_test" ;
int id2 = 2 ;
ProcessDefinition processDefinition2 = new ProcessDefinition ( ) ;
processDefinition2 . setProjectName ( projectName ) ;
processDefinition2 . setConnects ( connects ) ;
processDefinition2 . setDescription ( description ) ;
processDefinition2 . setId ( id2 ) ;
processDefinition2 . setLocations ( locations ) ;
processDefinition2 . setName ( name2 ) ;
processDefinition2 . setProcessDefinitionJson ( json ) ;
resourceList . add ( processDefinition ) ;
resourceList . add ( processDefinition2 ) ;
return resourceList ;
}
@Ignore
@Test
@Test
public void testExportProcessDefinitionById ( ) throws Exception {
public void testDeleteProcessDefinitionById ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
String projectName = "test" ;
paramsMap . add ( "processDefinitionId" , "91" ) ;
int id = 1 ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/export" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
// .andExpect(status().isOk())
// .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
Map < String , Object > result = new HashMap < > ( 5 ) ;
putMsg ( result , Status . SUCCESS ) ;
@Test
Mockito . when ( processDefinitionService . deleteProcessDefinitionById ( user , projectName , id ) ) . thenReturn ( result ) ;
public void testQueryProccessDefinitionAllByProjectId ( ) throws Exception {
Result response = processDefinitionController . deleteProcessDefinitionById ( user , projectName , id ) ;
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
paramsMap . add ( "projectId" , "9" ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/queryProccessDefinitionAllByProjectId" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
@Test
public void testGetNodeListByDefinitionId ( ) throws Exception {
String projectName = "test" ;
int id = 1 ;
Map < String , Object > result = new HashMap < > ( 5 ) ;
putMsg ( result , Status . SUCCESS ) ;
@Test
Mockito . when ( processDefinitionService . getTaskNodeListByDefinitionId ( id ) ) . thenReturn ( result ) ;
public void testDeleteProcessDefinitionById ( ) throws Exception {
Result response = processDefinitionController . getNodeListByDefinitionId ( user , projectName , id ) ;
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
paramsMap . add ( "processDefinitionId" , "73" ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/delete" , "cxc_1113" )
. header ( SESSION_ID , sessionId )
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
. andReturn ( ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
@Test
@Test
public void testBatchDeleteProcessDefinitionByIds ( ) throws Exception {
public void testGetNodeListByDefinitionIdList ( ) throws Exception {
MultiValueMap < String , String > paramsMap = new LinkedMultiValueMap < > ( ) ;
String projectName = "test" ;
paramsMap . add ( "processDefinitionIds" , "54,62" ) ;
String idList = "1,2,3" ;
MvcResult mvcResult = mockMvc . perform ( get ( "/projects/{projectName}/process/batch-delete" , "cxc_1113" )
Map < String , Object > result = new HashMap < > ( 5 ) ;
. header ( SESSION_ID , sessionId )
putMsg ( result , Status . SUCCESS ) ;
. params ( paramsMap ) )
. andExpect ( status ( ) . isOk ( ) )
Mockito . when ( processDefinitionService . getTaskNodeListByDefinitionIdList ( idList ) ) . thenReturn ( result ) ;
. andExpect ( content ( ) . contentType ( MediaType . APPLICATION_JSON_UTF8 ) )
Result response = processDefinitionController . getNodeListByDefinitionIdList ( user , projectName , idList ) ;
. andReturn ( ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , response . getCode ( ) . intValue ( ) ) ;
Result result = JSONUtils . parseObject ( mvcResult . getResponse ( ) . getContentAsString ( ) , Result . class ) ;
Assert . assertEquals ( Status . SUCCESS . getCode ( ) , result . getCode ( ) . intValue ( ) ) ;
logger . info ( mvcResult . getResponse ( ) . getContentAsString ( ) ) ;
}
}
}
}