Package de.mospace.lang

Examples of de.mospace.lang.RunnableQueue$Job


  @Test
  public void testGetJobInfo() throws Exception {
    String jobId = "jobId";

    Job mockJob = mock( Job.class );
    doReturn( mockJob ).when( schedulerService ).getJob( jobId );

    ISecurityHelper mockSecurityHelper = mock( ISecurityHelper.class );
    doReturn( mockSecurityHelper ).when( schedulerService ).getSecurityHelper();

    IPentahoSession mockPentahoSession = mock( IPentahoSession.class );
    doReturn( mockPentahoSession ).when( schedulerService ).getSession();

    String sessionName = "sessionName";
    doReturn( sessionName ).when( mockPentahoSession ).getName();
    doReturn( sessionName ).when( mockJob ).getUserName();

    Map<String, Serializable> mockJobParams = mock( Map.class );
    doReturn( mockJobParams ).when( mockJob ).getJobParams();

    Set<String> jobParamsKeyset = new HashSet<String>();
    doReturn( jobParamsKeyset ).when( mockJobParams ).keySet();

    String jobParamKey = "key";
    jobParamsKeyset.add( jobParamKey );

    String value = "value";
    String[] testArray = new String[]{value};
    doReturn( testArray ).when( mockJobParams ).get( jobParamKey );

    // Test 1
    doReturn( true ).when( mockSecurityHelper ).isPentahoAdministrator( mockPentahoSession );

    Job testJob = schedulerService.getJobInfo( jobId );
    assertEquals( mockJob, testJob );

    // Test 2
    doReturn( false ).when( mockSecurityHelper ).isPentahoAdministrator( mockPentahoSession );
    testJob = schedulerService.getJobInfo( jobId );
View Full Code Here


  @Test
  public void testGetJobInfoError() throws Exception {
    String jobId = "jobId";

    Job mockJob = mock( Job.class );
    doReturn( mockJob ).when( schedulerService ).getJob( jobId );

    ISecurityHelper mockSecurityHelper = mock( ISecurityHelper.class );
    doReturn( mockSecurityHelper ).when( schedulerService ).getSecurityHelper();
View Full Code Here

  @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<JobScheduleParam>();

    doReturn( true ).when( schedulerService ).isScheduleAllowed();
    doNothing().when( jobScheduleRequest ).setActionClass( anyString() );
    doReturn( jobScheduleParams ).when( jobScheduleRequest ).getJobParameters();
    doReturn( jobScheduleParamMock1 ).when( schedulerService ).getJobScheduleParam( anyString(), anyString() );
    doReturn( jobScheduleParamMock2 ).when( schedulerService ).getJobScheduleParam( anyString(), anyLong() );
    doNothing().when( schedulerService ).updateStartDateForTimeZone( jobScheduleRequest );
    doReturn( jobMock ).when( schedulerService ).createJob( any( JobScheduleRequest.class ) );

    Job job = schedulerService.addBlockout( jobScheduleRequest );

    assertNotNull( job );
    assertEquals( 2, jobScheduleParams.size() );

    verify( schedulerService ).isScheduleAllowed();
View Full Code Here

    } 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<JobScheduleParam>();
View Full Code Here

  @Test
  public void testUpdateBlockout() throws Exception {

    String jobId = "jobId";
    JobScheduleRequest jobScheduleRequest = mock( JobScheduleRequest.class );
    Job jobMock = mock( Job.class );

    doReturn( true ).when( schedulerService ).isScheduleAllowed();
    doReturn( true ).when( schedulerService ).removeJob( anyString() );
    doReturn( jobMock ).when( schedulerService ).addBlockout( jobScheduleRequest );

    Job job = schedulerService.updateBlockout( jobId, jobScheduleRequest );

    assertNotNull( job );

    verify( schedulerService ).isScheduleAllowed();
    verify( schedulerService ).removeJob( anyString() );
View Full Code Here

  @Test
  public void testUpdateBlockoutException() throws Exception {

    String jobId = "jobId";
    JobScheduleRequest jobScheduleRequest = mock( JobScheduleRequest.class );
    Job job = mock( Job.class );

    // Test 1
    doReturn( false ).when( schedulerService ).isScheduleAllowed();

    try {
View Full Code Here

    jobTrigger.setMinuteRecurrence( startingMinute );

    jobTrigger.setSecondRecurrence( recurrenceList );
    System.out.println( jobTrigger.toString() );
    String jobName = "complexJob1";
    Job job = scheduler.createJob( jobName, TestAction.class, new HashMap<String, Serializable>(), jobTrigger );
    Assert.assertTrue( job.getJobName().contains( jobName ) );
    Assert.assertEquals( job.getSchedulableClass(), TestAction.class.getName() );
    Assert.assertEquals( job.getJobTrigger().toString(), jobTrigger.toString() );

    jobTrigger.setSecondRecurrence( sequentialRecurrence );
    jobName = "complexJob2";
    job = scheduler.createJob( jobName, TestAction2.class, new HashMap<String, Serializable>(), jobTrigger );
    Assert.assertTrue( job.getJobName().contains( jobName ) );
    Assert.assertEquals( job.getSchedulableClass(), TestAction2.class.getName() );
    Assert.assertEquals( job.getJobTrigger().toString(), jobTrigger.toString() );

    jobTrigger.setSecondRecurrence( incrementalRecurrence );
    jobName = "complexJob3";
    job = scheduler.createJob( jobName, TestAction3.class, new HashMap<String, Serializable>(), jobTrigger );
    Assert.assertTrue( job.getJobName().contains( jobName ) );
    Assert.assertEquals( job.getSchedulableClass(), TestAction3.class.getName() );
    Assert.assertEquals( job.getJobTrigger().toString(), jobTrigger.toString() );

    //
    // Wait for the jobs to complete, then check that each action executed the correct number of times
    //
    sleep( 60 );
View Full Code Here

    SimpleJobTrigger repeater = new SimpleJobTrigger();
    repeater.setStartTime( new Date() );
    repeater.setRepeatInterval( 5 );
    repeater.setRepeatCount( 20 );

    Job job = scheduler.createJob( "testName", TestAction.class, new HashMap<String, Serializable>(), repeater );

    sleep( 12 );

    Assert.assertTrue( "Job did not run the correct number of times", TestAction.counter >= 2 );

    repeater = new SimpleJobTrigger();
    repeater.setStartTime( new Date() );
    repeater.setRepeatInterval( 20 );
    repeater.setRepeatCount( 3 );

    int count = TestAction.counter;
    System.out.println( "updating job! " + new Date() );
    scheduler.updateJob( job.getJobId(), new HashMap<String, Serializable>(), repeater );
    List<Job> jobs = scheduler.getJobs( null );
    Assert.assertEquals( "Unexpected number of scheduled jobs", 1, jobs.size() );
    SimpleJobTrigger simpleJobTrigger = (SimpleJobTrigger) jobs.get( 0 ).getJobTrigger();
    Assert.assertEquals( 20, simpleJobTrigger.getRepeatInterval() );
    Assert.assertEquals( 3, simpleJobTrigger.getRepeatCount() );
View Full Code Here

    }
    ComplexJobTrigger complexJobTrigger = new ComplexJobTrigger();
    complexJobTrigger.setHourlyRecurrence( (ITimeRecurrence) null );
    complexJobTrigger.setMinuteRecurrence( startingMin );
    complexJobTrigger.setSecondRecurrence( startingSec );
    Job job = scheduler.createJob( jobName, TestAction.class, jobParams, complexJobTrigger );
    scheduler.pauseJob( job.getJobId() );
    sleep( 30 );
    Assert.assertEquals( counter, TestAction.counter );
    Assert.assertEquals( 1, scheduler.getJobs( null ).size() );
    scheduler.resumeJob( job.getJobId() );
    sleep( 30 );
    Assert.assertTrue( counter != TestAction.counter );
    scheduler.removeJob( job.getJobId() );
    Assert.assertEquals( 0, scheduler.getJobs( null ).size() );
  }
View Full Code Here

    int startEndCounter = TestAction.counter;
    int startCounter = TestAction2.counter;
    int endCounter = TestAction3.counter;

    Job job = scheduler.createJob("startEndJob", TestAction.class, jobParams, startEndJobTrigger);
    Job job2 = scheduler.createJob( "startJob", TestAction2.class, jobParams, startJobTrigger );
    Job job3 = scheduler.createJob( "endJob", TestAction3.class, jobParams, endJobTrigger );
    try{

      sleep( 10 );
      Assert.assertEquals( startEndCounter, TestAction.counter );
      Assert.assertEquals( startCounter, TestAction2.counter );
      Assert.assertTrue( endCounter != TestAction3.counter );
      endCounter = TestAction3.counter;
      sleep( 20 );
      Assert.assertTrue( startEndCounter != TestAction.counter );
      Assert.assertTrue( startCounter != TestAction2.counter );
      Assert.assertTrue( endCounter != TestAction3.counter );
      sleep( 60 );
      startEndCounter = TestAction.counter;
      startCounter = TestAction2.counter;
      endCounter = TestAction3.counter;
      sleep( 30 );
      Assert.assertEquals( startEndCounter, TestAction.counter );
      Assert.assertTrue( startCounter != TestAction2.counter );
      Assert.assertEquals( endCounter, TestAction3.counter );
    }
    catch( Throwable ex ){
      TestCase.fail();
    }
    finally{
      scheduler.removeJob( job.getJobId() );
      scheduler.removeJob( job2.getJobId() );
      scheduler.removeJob( job3.getJobId() );
    }
    Assert.assertEquals( 0, scheduler.getJobs( null ).size() );
  }
View Full Code Here

TOP

Related Classes of de.mospace.lang.RunnableQueue$Job

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.