Search in sources :

Example 81 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testAddBlockoutException.

@Test
public void testAddBlockoutException() throws Exception {
    // Test 1
    JobScheduleRequest jobScheduleRequest = mock(JobScheduleRequest.class);
    doReturn(false).when(schedulerService).canAdminister();
    try {
        schedulerService.addBlockout(jobScheduleRequest);
        fail();
    } catch (IllegalAccessException e) {
    // Should catch exception
    }
    // Test 2
    Job jobMock = mock(Job.class);
    JobScheduleParam jobScheduleParamMock1 = mock(JobScheduleParam.class);
    JobScheduleParam jobScheduleParamMock2 = mock(JobScheduleParam.class);
    List<JobScheduleParam> jobScheduleParams = new ArrayList<>();
    doReturn(true).when(schedulerService).canAdminister();
    doNothing().when(jobScheduleRequest).setActionClass(nullable(String.class));
    doReturn(jobScheduleParams).when(jobScheduleRequest).getJobParameters();
    doReturn(jobScheduleParamMock1).when(schedulerService).getJobScheduleParam(nullable(String.class), nullable(String.class));
    doReturn(jobScheduleParamMock2).when(schedulerService).getJobScheduleParam(nullable(String.class), anyLong());
    doThrow(new IOException()).when(schedulerService).createJob(jobScheduleRequest);
    try {
        schedulerService.addBlockout(jobScheduleRequest);
        fail();
    } catch (IOException e) {
    // Should catch exception
    }
    // Test 3
    doThrow(new SchedulerException("")).when(schedulerService).createJob(jobScheduleRequest);
    try {
        schedulerService.addBlockout(jobScheduleRequest);
        fail();
    } catch (SchedulerException e) {
    // Should catch exception
    }
    verify(schedulerService, times(3)).canAdminister();
    verify(jobScheduleRequest, times(2)).setActionClass(nullable(String.class));
    verify(jobScheduleRequest, times(4)).getJobParameters();
    verify(schedulerService, times(2)).createJob(any(JobScheduleRequest.class));
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) SchedulerException(org.pentaho.platform.api.scheduler2.SchedulerException) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 82 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testGetJobInfoError.

@Test
public void testGetJobInfoError() throws Exception {
    String jobId = "jobId";
    Job mockJob = mock(Job.class);
    doReturn(mockJob).when(schedulerService).getJob(jobId);
    IPentahoSession mockPentahoSession = mock(IPentahoSession.class);
    doReturn(mockPentahoSession).when(schedulerService).getSession();
    String sessionName = "sessionName";
    doReturn(sessionName).when(mockPentahoSession).getName();
    String username = "username";
    doReturn(username).when(mockJob).getUserName();
    try {
        schedulerService.getJobInfo(jobId);
        fail();
    } catch (RuntimeException e) {
    // Expected
    }
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 83 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testGetContentCleanerJob.

@Test
public void testGetContentCleanerJob() throws Exception {
    IJobFilter jobFilter = mock(IJobFilter.class);
    List<Job> jobs = new ArrayList<>();
    IPentahoSession session = mock(IPentahoSession.class);
    doReturn(session).when(schedulerService).getSession();
    doReturn("sessionName").when(session).getName();
    doReturn(true).when(schedulerService.policy).isAllowed(AdministerSecurityAction.NAME);
    doReturn(jobFilter).when(schedulerService).getJobFilter(anyBoolean(), nullable(String.class));
    doReturn(jobs).when(schedulerService.scheduler).getJobs(any(IJobFilter.class));
    // Test 1
    Job job = schedulerService.getContentCleanerJob();
    assertNull(job);
    // Test 2
    Job job1 = mock(Job.class);
    jobs.add(job1);
    job = schedulerService.getContentCleanerJob();
    assertNotNull(job);
    verify(schedulerService, times(2)).getSession();
    verify(session, times(2)).getName();
    verify(schedulerService.policy, times(2)).isAllowed(AdministerSecurityAction.NAME);
    verify(schedulerService.scheduler, times(2)).getJobs(any(IJobFilter.class));
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 84 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testGetJobStateError.

@Test
public void testGetJobStateError() throws Exception {
    JobRequest mockJobRequest = mock(JobRequest.class);
    String jobId = "jobId";
    doReturn(jobId).when(mockJobRequest).getJobId();
    IPentahoSession mockSession = mock(IPentahoSession.class);
    doReturn(mockSession).when(schedulerService).getSession();
    Job mockJob = mock(Job.class);
    doReturn(mockJob).when(schedulerService).getJob(jobId);
    String username = "username";
    doReturn(username).when(mockJob).getUserName();
    String sessionName = "notUsername";
    doReturn(sessionName).when(mockSession).getName();
    doReturn(false).when(schedulerService).isScheduleAllowed();
    try {
        schedulerService.getJobState(mockJobRequest);
        fail();
    } catch (UnsupportedOperationException e) {
    // Expected
    }
}
Also used : JobRequest(org.pentaho.platform.web.http.api.resources.JobRequest) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Example 85 with Job

use of com.google.cloud.dataproc.v1beta2.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testRemoveJob.

@Test
public void testRemoveJob() throws SchedulerException {
    Job job = mock(Job.class);
    doReturn(job).when(schedulerService).getJob(nullable(String.class));
    doReturn(true).when(schedulerService).isScheduleAllowed();
    doNothing().when(schedulerService.scheduler).removeJob(nullable(String.class));
    schedulerService.removeJob("job-id");
}
Also used : Job(org.pentaho.platform.api.scheduler2.Job) Test(org.junit.Test)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)94 Test (org.junit.Test)69 Serializable (java.io.Serializable)25 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)21 HashMap (java.util.HashMap)20 ArrayList (java.util.ArrayList)19 JobScheduleRequest (org.pentaho.platform.web.http.api.resources.JobScheduleRequest)19 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)18 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)17 Date (java.util.Date)14 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)14 Job (com.google.cloud.video.transcoder.v1.Job)13 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)13 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)12 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 AudioStream (com.google.cloud.video.transcoder.v1.AudioStream)8 JobConfig (com.google.cloud.video.transcoder.v1.JobConfig)8 VideoStream (com.google.cloud.video.transcoder.v1.VideoStream)8 Map (java.util.Map)8 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)8