use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiControllerTest method testQueryFailAsSaturnJobExceptionThrows.
@Test
public void testQueryFailAsSaturnJobExceptionThrows() throws Exception {
String customErrMsg = "some exception throws";
willThrow(new SaturnJobConsoleHttpException(400, customErrMsg)).given(restApiService).getRestAPIJobInfo("domain", "job1");
MvcResult result = mvc.perform(get("/rest/v1/domain/jobs/job1")).andExpect(status().isBadRequest()).andReturn();
assertEquals("error msg is not equal", customErrMsg, fetchErrorMessage(result));
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class JobOperationRestApiControllerTest method testCreateFailAsSaturnHttpJobExceptionThrows.
@Test
public void testCreateFailAsSaturnHttpJobExceptionThrows() throws Exception {
String customErrMsg = "some exception throws";
willThrow(new SaturnJobConsoleHttpException(400, customErrMsg)).given(restApiService).createJob(any(String.class), any(JobConfig.class));
JobEntity jobEntity = constructJobEntity("job1");
MvcResult result = mvc.perform(post("/rest/v1/domain/jobs").contentType(MediaType.APPLICATION_JSON).content(jobEntity.toJSON())).andExpect(status().isBadRequest()).andReturn();
String message = fetchErrorMessage(result);
assertEquals("error message not equal", customErrMsg, message);
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImplTest method testRunAtOnceFailAsJobStatusIsNotReady.
@Test
public void testRunAtOnceFailAsJobStatusIsNotReady() throws SaturnJobConsoleException {
// prepare
String jobName = "testJob";
when(jobService.getJobStatus(TEST_NAME_SPACE_NAME, jobName)).thenReturn(JobStatus.RUNNING);
// run
try {
restApiService.runJobAtOnce(TEST_NAME_SPACE_NAME, jobName, null);
} catch (SaturnJobConsoleHttpException e) {
assertEquals("status code is not 400", 400, e.getStatusCode());
assertEquals("error message is not equals", "job's status is not {READY}", e.getMessage());
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImplTest method testStopAtOnceFailForMsgJobAsJobIsEnable.
@Test
public void testStopAtOnceFailForMsgJobAsJobIsEnable() throws SaturnJobConsoleException {
// prepare
String jobName = "testJob";
when(jobService.getJobStatus(TEST_NAME_SPACE_NAME, jobName)).thenReturn(JobStatus.STOPPING);
List<JobServer> servers = Lists.newArrayList();
JobServer jobServer = createJobServer("job1");
servers.add(jobServer);
when(jobService.getJobServers(TEST_NAME_SPACE_NAME, jobName)).thenReturn(servers);
List<String> serverNameList = getJobServerNameList(servers);
when(jobService.getJobServerList(TEST_NAME_SPACE_NAME, jobName)).thenReturn(serverNameList);
// run
try {
restApiService.stopJobAtOnce(TEST_NAME_SPACE_NAME, jobName);
} catch (SaturnJobConsoleHttpException e) {
assertEquals("status code is not 400", 400, e.getStatusCode());
assertEquals("error message is not equals", "job cannot be stopped while it is enable", e.getMessage());
}
}
use of com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException in project Saturn by vipshop.
the class RestApiServiceImplTest method testRunAtOnceFailAsNoExecutorFound.
@Test
public void testRunAtOnceFailAsNoExecutorFound() throws SaturnJobConsoleException {
// prepare
String jobName = "testJob";
when(jobService.getJobStatus(TEST_NAME_SPACE_NAME, jobName)).thenReturn(JobStatus.READY);
List<JobServer> servers = Lists.newArrayList();
when(jobService.getJobServers(TEST_NAME_SPACE_NAME, jobName)).thenReturn(servers);
// run
try {
restApiService.runJobAtOnce(TEST_NAME_SPACE_NAME, jobName, null);
} catch (SaturnJobConsoleHttpException e) {
assertEquals("status code is not 400", 400, e.getStatusCode());
assertEquals("error message is not equals", "no executor found for this job", e.getMessage());
}
}
Aggregations