@ -16,6 +16,7 @@
* /
* /
package org.apache.dolphinscheduler.api.service ;
package org.apache.dolphinscheduler.api.service ;
import com.alibaba.druid.pool.DruidDataSource ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONArray ;
import com.alibaba.fastjson.JSONObject ;
import com.alibaba.fastjson.JSONObject ;
import org.apache.dolphinscheduler.api.ApiApplicationServer ;
import org.apache.dolphinscheduler.api.ApiApplicationServer ;
@ -28,7 +29,9 @@ import org.apache.dolphinscheduler.common.utils.FileUtils;
import org.apache.dolphinscheduler.common.utils.JSONUtils ;
import org.apache.dolphinscheduler.common.utils.JSONUtils ;
import org.apache.dolphinscheduler.dao.entity.* ;
import org.apache.dolphinscheduler.dao.entity.* ;
import org.apache.dolphinscheduler.dao.mapper.* ;
import org.apache.dolphinscheduler.dao.mapper.* ;
import org.apache.dolphinscheduler.service.bean.SpringApplicationContext ;
import org.apache.dolphinscheduler.service.process.ProcessService ;
import org.apache.dolphinscheduler.service.process.ProcessService ;
import org.apache.dolphinscheduler.service.quartz.QuartzExecutors ;
import org.apache.http.entity.ContentType ;
import org.apache.http.entity.ContentType ;
import org.json.JSONException ;
import org.json.JSONException ;
import org.junit.Assert ;
import org.junit.Assert ;
@ -38,10 +41,12 @@ import org.mockito.InjectMocks;
import org.mockito.Mock ;
import org.mockito.Mock ;
import org.mockito.Mockito ;
import org.mockito.Mockito ;
import org.mockito.junit.MockitoJUnitRunner ;
import org.mockito.junit.MockitoJUnitRunner ;
import org.quartz.Scheduler ;
import org.skyscreamer.jsonassert.JSONAssert ;
import org.skyscreamer.jsonassert.JSONAssert ;
import org.slf4j.Logger ;
import org.slf4j.Logger ;
import org.slf4j.LoggerFactory ;
import org.slf4j.LoggerFactory ;
import org.springframework.boot.test.context.SpringBootTest ;
import org.springframework.boot.test.context.SpringBootTest ;
import org.springframework.context.ApplicationContext ;
import org.springframework.mock.web.MockMultipartFile ;
import org.springframework.mock.web.MockMultipartFile ;
import org.springframework.web.multipart.MultipartFile ;
import org.springframework.web.multipart.MultipartFile ;
@ -274,6 +279,7 @@ public class ProcessDefinitionServiceTest {
@Test
@Test
public void testReleaseProcessDefinition ( ) {
public void testReleaseProcessDefinition ( ) {
String projectName = "project_test1" ;
String projectName = "project_test1" ;
Mockito . when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( getProject ( projectName ) ) ;
Mockito . when ( projectMapper . queryByName ( projectName ) ) . thenReturn ( getProject ( projectName ) ) ;
@ -298,20 +304,21 @@ public class ProcessDefinitionServiceTest {
46 , ReleaseState . ONLINE . getCode ( ) ) ;
46 , ReleaseState . ONLINE . getCode ( ) ) ;
Assert . assertEquals ( Status . SUCCESS , onlineRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . SUCCESS , onlineRes . get ( Constants . STATUS ) ) ;
//process definition offline
List < Schedule > schedules = new ArrayList < > ( ) ;
Schedule schedule = getSchedule ( ) ;
schedules . add ( schedule ) ;
Mockito . when ( scheduleMapper . selectAllByProcessDefineArray ( new int [ ] { 46 } ) ) . thenReturn ( schedules ) ;
Mockito . when ( scheduleMapper . updateById ( schedule ) ) . thenReturn ( 1 ) ;
Map < String , Object > offlineRes = processDefinitionService . releaseProcessDefinition ( loginUser , "project_test1" ,
46 , ReleaseState . OFFLINE . getCode ( ) ) ;
Assert . assertEquals ( Status . SUCCESS , offlineRes . get ( Constants . STATUS ) ) ;
//release error code
//release error code
Map < String , Object > failRes = processDefinitionService . releaseProcessDefinition ( loginUser , "project_test1" ,
Map < String , Object > failRes = processDefinitionService . releaseProcessDefinition ( loginUser , "project_test1" ,
46 , 2 ) ;
46 , 2 ) ;
Assert . assertEquals ( Status . REQUEST_PARAMS_NOT_VALID_ERROR , failRes . get ( Constants . STATUS ) ) ;
Assert . assertEquals ( Status . REQUEST_PARAMS_NOT_VALID_ERROR , failRes . get ( Constants . STATUS ) ) ;
//FIXME has function exit code 1 when exception
//process definition offline
// List<Schedule> schedules = new ArrayList<>();
// Schedule schedule = getSchedule();
// schedules.add(schedule);
// Mockito.when(scheduleMapper.selectAllByProcessDefineArray(new int[]{46})).thenReturn(schedules);
// Mockito.when(scheduleMapper.updateById(schedule)).thenReturn(1);
// Map<String, Object> offlineRes = processDefinitionService.releaseProcessDefinition(loginUser, "project_test1",
// 46, ReleaseState.OFFLINE.getCode());
// Assert.assertEquals(Status.SUCCESS, offlineRes.get(Constants.STATUS));
}
}
@Test
@Test