Search in sources :

Example 6 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_ActionClassJobParam.

@Test
public void testCreateJobScheduleRequest_ActionClassJobParam() throws Exception {
    String jobName = "JOB";
    String actionClass = "com.pentaho.Action";
    Map<String, Serializable> params = new HashMap<>();
    params.put(QuartzScheduler.RESERVEDMAPKEY_ACTIONCLASS, actionClass);
    Job job = mock(Job.class);
    CronJobTrigger trigger = mock(CronJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    when(job.getJobParams()).thenReturn(params);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertEquals(actionClass, jobScheduleRequest.getActionClass());
    assertEquals(actionClass, jobScheduleRequest.getJobParameters().get(0).getValue());
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) CronJobTrigger(org.pentaho.platform.api.scheduler2.CronJobTrigger) Test(org.junit.Test)

Example 7 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class ScheduleExportUtilTest method testCreateJobScheduleRequest_NoStreamProvider.

@Test
public void testCreateJobScheduleRequest_NoStreamProvider() throws Exception {
    String jobName = "JOB";
    Job job = mock(Job.class);
    SimpleJobTrigger trigger = mock(SimpleJobTrigger.class);
    when(job.getJobTrigger()).thenReturn(trigger);
    when(job.getJobName()).thenReturn(jobName);
    Map<String, Serializable> params = new HashMap<>();
    params.put("directory", "/home/admin");
    params.put("transformation", "myTransform");
    HashMap<String, String> pdiParams = new HashMap<>();
    pdiParams.put("pdiParam", "pdiParamValue");
    params.put(ScheduleExportUtil.RUN_PARAMETERS_KEY, pdiParams);
    when(job.getJobParams()).thenReturn(params);
    JobScheduleRequest jobScheduleRequest = ScheduleExportUtil.createJobScheduleRequest(job);
    assertNotNull(jobScheduleRequest);
    assertEquals(jobName, jobScheduleRequest.getJobName());
    assertEquals(trigger, jobScheduleRequest.getSimpleJobTrigger());
    assertEquals("/home/admin/myTransform.ktr", jobScheduleRequest.getInputFile());
    assertEquals("/home/admin/myTransform*", jobScheduleRequest.getOutputFile());
    assertEquals("pdiParamValue", jobScheduleRequest.getPdiParameters().get("pdiParam"));
}
Also used : SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 8 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testCreateJobException.

@Test
public void testCreateJobException() throws Exception {
    List<JobScheduleParam> jobParameters = new ArrayList<>();
    JobScheduleParam jobScheduleParam1 = mock(JobScheduleParam.class);
    doReturn("name1").when(jobScheduleParam1).getName();
    doReturn("value1").when(jobScheduleParam1).getValue();
    jobParameters.add(jobScheduleParam1);
    Job job = mock(Job.class);
    JobScheduleRequest scheduleRequest = mock(JobScheduleRequest.class);
    doReturn("className").when(scheduleRequest).getActionClass();
    doReturn("jobName").when(scheduleRequest).getJobName();
    doReturn(jobParameters).when(scheduleRequest).getJobParameters();
    doNothing().when(scheduleRequest).setJobName(nullable(String.class));
    doReturn(true).when(schedulerService).isPdiFile(nullable(RepositoryFile.class));
    SchedulerOutputPathResolver schedulerOutputPathResolver = mock(SchedulerOutputPathResolver.class);
    SimpleJobTrigger simpleJobTrigger = mock(SimpleJobTrigger.class);
    RepositoryFile repositoryFile = mock(RepositoryFile.class);
    Map<String, Serializable> metadata = mock(Map.class);
    doReturn(metadata).when(schedulerService.repository).getFileMetadata(nullable(String.class));
    doReturn(true).when(metadata).containsKey(RepositoryFile.SCHEDULABLE_KEY);
    doReturn(simpleJobTrigger).when(scheduleRequest).getSimpleJobTrigger();
    doReturn(false).when(schedulerService.policy).isAllowed(SchedulerAction.NAME);
    doReturn("file.ext").when(scheduleRequest).getInputFile();
    doReturn(repositoryFile).when(schedulerService.repository).getFile(nullable(String.class));
    // Test 1
    try {
        schedulerService.createJob(scheduleRequest);
        fail();
    } catch (SecurityException e) {
    // Should catch it
    }
    // Test 2
    doReturn(true).when(schedulerService.policy).isAllowed(SchedulerAction.NAME);
    doReturn("false").when(metadata).get(RepositoryFile.SCHEDULABLE_KEY);
    try {
        schedulerService.createJob(scheduleRequest);
        fail();
    } catch (IllegalAccessException e) {
    // Should catch it
    }
    // Test 3
    doReturn("").when(scheduleRequest).getInputFile();
    doThrow(new ClassNotFoundException()).when(schedulerService).getAction(nullable(String.class));
    try {
        schedulerService.createJob(scheduleRequest);
        fail();
    } catch (RuntimeException e) {
    // Should catch it
    }
    verify(scheduleRequest, times(7)).getSimpleJobTrigger();
    verify(scheduleRequest, times(3)).getInputFile();
    verify(schedulerService.policy, times(3)).isAllowed(SchedulerAction.NAME);
    verify(schedulerService.repository, times(1)).getFile(nullable(String.class));
    verify(scheduleRequest, times(1)).getJobName();
    verify(scheduleRequest, times(2)).setJobName(nullable(String.class));
    verify(scheduleRequest, times(7)).getActionClass();
    verify(schedulerService.repository, times(1)).getFileMetadata(nullable(String.class));
    verify(schedulerService, times(1)).isPdiFile(nullable(RepositoryFile.class));
    verify(schedulerService, times(1)).handlePDIScheduling(nullable(RepositoryFile.class), any(HashMap.class), any(HashMap.class));
    verify(scheduleRequest, times(7)).getActionClass();
    verify(schedulerService).getAction(nullable(String.class));
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) Serializable(java.io.Serializable) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SchedulerOutputPathResolver(org.pentaho.platform.web.http.api.resources.SchedulerOutputPathResolver) SimpleJobTrigger(org.pentaho.platform.api.scheduler2.SimpleJobTrigger) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 9 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testAddBlockout.

@Test
public void testAddBlockout() throws Exception {
    JobScheduleRequest jobScheduleRequest = mock(JobScheduleRequest.class);
    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());
    doReturn(jobMock).when(schedulerService).createJob(any(JobScheduleRequest.class));
    Job job = schedulerService.addBlockout(jobScheduleRequest);
    assertNotNull(job);
    assertEquals(2, jobScheduleParams.size());
    verify(schedulerService).canAdminister();
    verify(jobScheduleRequest).setActionClass(nullable(String.class));
    verify(jobScheduleRequest, times(2)).getJobParameters();
    verify(schedulerService).createJob(any(JobScheduleRequest.class));
}
Also used : JobScheduleParam(org.pentaho.platform.web.http.api.resources.JobScheduleParam) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) JobScheduleRequest(org.pentaho.platform.web.http.api.resources.JobScheduleRequest) Test(org.junit.Test)

Example 10 with Job

use of com.google.cloud.video.transcoder.v1.Job in project pentaho-platform by pentaho.

the class SchedulerServiceTest method testGetJobState.

@Test
public void testGetJobState() 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);
    doReturn(Job.JobState.BLOCKED).when(mockJob).getState();
    String username = "username";
    doReturn(username).when(mockJob).getUserName();
    doReturn(username).when(mockSession).getName();
    // Test 1
    doReturn(true).when(schedulerService).isScheduleAllowed();
    Job.JobState testState = schedulerService.getJobState(mockJobRequest);
    assertEquals(Job.JobState.BLOCKED, testState);
    // Test 2
    doReturn(false).when(schedulerService).isScheduleAllowed();
    testState = schedulerService.getJobState(mockJobRequest);
    assertEquals(Job.JobState.BLOCKED, testState);
    verify(mockJobRequest, times(2)).getJobId();
    verify(schedulerService, times(1)).getSession();
    verify(schedulerService, times(2)).getJob(jobId);
    verify(mockJob, times(2)).getState();
    verify(mockJob, times(1)).getUserName();
    verify(mockSession, times(1)).getName();
}
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)

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 TranscoderServiceClient (com.google.cloud.video.transcoder.v1.TranscoderServiceClient)18 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 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)12 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)12 AudioStream (com.google.cloud.video.transcoder.v1.AudioStream)9 JobConfig (com.google.cloud.video.transcoder.v1.JobConfig)9 VideoStream (com.google.cloud.video.transcoder.v1.VideoStream)9 Map (java.util.Map)8 CronJobTrigger (org.pentaho.platform.api.scheduler2.CronJobTrigger)8