Search in sources :

Example 11 with IJobFilter

use of org.pentaho.platform.api.scheduler2.IJobFilter in project pentaho-platform by pentaho.

the class DefaultSchedulerServiceTest method testGetJobsAdminUser.

@Test
public void testGetJobsAdminUser() throws Exception {
    when(policy.isAllowed(anyString())).thenReturn(true);
    when(iPentahoSessionMock.getName()).thenReturn("admin");
    defaultSchedulerService.getJobs();
    verify(iSchedulerMock).getJobs((IJobFilter) filterCaptor.capture());
    IJobFilter filter = (IJobFilter) filterCaptor.getValue();
    assertNotNull(filter);
    List<Job> testJobs = getJobs();
    List<Job> filteredJobs = new ArrayList<>();
    for (Job job : testJobs) {
        if (filter.accept(job)) {
            filteredJobs.add(job);
            assertNotEquals("BlockoutAction", job.getJobName());
        }
    }
    assertEquals(10, filteredJobs.size());
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with IJobFilter

use of org.pentaho.platform.api.scheduler2.IJobFilter in project pentaho-platform by pentaho.

the class DefaultSchedulerServiceTest method testGetJobsNonAdminUser.

@Test
public void testGetJobsNonAdminUser() throws Exception {
    when(policy.isAllowed(anyString())).thenReturn(false);
    when(iPentahoSessionMock.getName()).thenReturn("testUser1");
    defaultSchedulerService.getJobs();
    verify(iSchedulerMock).getJobs((IJobFilter) filterCaptor.capture());
    IJobFilter filter = (IJobFilter) filterCaptor.getValue();
    assertNotNull(filter);
    List<Job> testJobs = getJobs();
    List<Job> filteredJobs = new ArrayList<>();
    for (Job job : testJobs) {
        if (filter.accept(job)) {
            filteredJobs.add(job);
        }
    }
    assertEquals(1, filteredJobs.size());
    assertEquals("testJobName1", filteredJobs.get(0).getJobName());
    assertEquals("testUser1", filteredJobs.get(0).getUserName());
}
Also used : IJobFilter(org.pentaho.platform.api.scheduler2.IJobFilter) ArrayList(java.util.ArrayList) Job(org.pentaho.platform.api.scheduler2.Job) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Job (org.pentaho.platform.api.scheduler2.Job)12 IJobFilter (org.pentaho.platform.api.scheduler2.IJobFilter)11 Test (org.junit.Test)8 ArrayList (java.util.ArrayList)7 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 Serializable (java.io.Serializable)3 IJobTrigger (org.pentaho.platform.api.scheduler2.IJobTrigger)3 IScheduler (org.pentaho.platform.api.scheduler2.IScheduler)3 SchedulerException (org.pentaho.platform.api.scheduler2.SchedulerException)3 Date (java.util.Date)2 ComplexJobTrigger (org.pentaho.platform.api.scheduler2.ComplexJobTrigger)2 SimpleJobTrigger (org.pentaho.platform.api.scheduler2.SimpleJobTrigger)2 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)2 CronTrigger (org.quartz.CronTrigger)2 SimpleTrigger (org.quartz.SimpleTrigger)2 Trigger (org.quartz.Trigger)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 JobTrigger (org.pentaho.platform.api.scheduler2.JobTrigger)1