Search in sources :

Example 51 with SaturnJobConsoleHttpException

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));
}
Also used : SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 52 with SaturnJobConsoleHttpException

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);
}
Also used : SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) MvcResult(org.springframework.test.web.servlet.MvcResult) RestApiJobConfig(com.vip.saturn.job.console.domain.RestApiJobConfig) JobConfig(com.vip.saturn.job.console.domain.JobConfig) Test(org.junit.Test) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) AbstractSaturnConsoleTest(com.vip.saturn.job.console.AbstractSaturnConsoleTest)

Example 53 with SaturnJobConsoleHttpException

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());
    }
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Test(org.junit.Test)

Example 54 with SaturnJobConsoleHttpException

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());
    }
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Test(org.junit.Test)

Example 55 with SaturnJobConsoleHttpException

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());
    }
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) SaturnJobConsoleHttpException(com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException) Test(org.junit.Test)

Aggregations

SaturnJobConsoleHttpException (com.vip.saturn.job.console.exception.SaturnJobConsoleHttpException)68 SaturnJobConsoleException (com.vip.saturn.job.console.exception.SaturnJobConsoleException)40 ResponseEntity (org.springframework.http.ResponseEntity)30 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)24 Test (org.junit.Test)15 HttpHeaders (org.springframework.http.HttpHeaders)13 Audit (com.vip.saturn.job.console.aop.annotation.Audit)12 JobConfig (com.vip.saturn.job.console.domain.JobConfig)10 Matchers.anyString (org.mockito.Matchers.anyString)8 NamespaceDomainInfo (com.vip.saturn.job.console.domain.NamespaceDomainInfo)7 AbstractSaturnConsoleTest (com.vip.saturn.job.console.AbstractSaturnConsoleTest)5 CurrentJobConfig (com.vip.saturn.job.console.mybatis.entity.CurrentJobConfig)5 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)5 MvcResult (org.springframework.test.web.servlet.MvcResult)5 Transactional (org.springframework.transaction.annotation.Transactional)5 NamespaceInfo (com.vip.saturn.job.console.mybatis.entity.NamespaceInfo)4 AlarmInfo (com.vip.saturn.job.integrate.entity.AlarmInfo)4 ParseException (java.text.ParseException)4 Map (java.util.Map)4 ZkCluster (com.vip.saturn.job.console.domain.ZkCluster)3