StringEntity buildSchedulerRequestEntity( AbstractMeta meta )
          throws UnsupportedEncodingException, UnknownParamException {

    String filename = getFullPath( meta );

    JobScheduleRequest jobScheduleRequest = new JobScheduleRequest();
    jobScheduleRequest.setInputFile( filename );

    // Set the log level
    if ( meta.getLogLevel() != null ) {
      JobScheduleParam jobScheduleParam = new JobScheduleParam();
      jobScheduleParam.setName( "logLevel" );
      jobScheduleParam.setType( STRING_TYPE );
      jobScheduleParam.setStringValue( Arrays.asList( meta.getLogLevel().getCode() ) );
      jobScheduleRequest.getJobParameters().add( jobScheduleParam );
    }

    // Set the clearing log param
    JobScheduleParam jobScheduleParamClearingLog = new JobScheduleParam();
    jobScheduleParamClearingLog.setName( "clearLog" );
    jobScheduleParamClearingLog.setType( STRING_TYPE );
    jobScheduleParamClearingLog
      .setStringValue( Arrays.asList( String.valueOf( meta.isClearingLog() ) ) );
    jobScheduleRequest.getJobParameters().add( jobScheduleParamClearingLog );

    // Set the safe mode enabled param
    JobScheduleParam jobScheduleParamSafeModeEnable = new JobScheduleParam();
    jobScheduleParamSafeModeEnable.setName( "runSafeMode" );
    jobScheduleParamSafeModeEnable.setType( STRING_TYPE );
    jobScheduleParamSafeModeEnable
      .setStringValue( Arrays.asList( String.valueOf( meta.isSafeModeEnabled() ) ) );
    jobScheduleRequest.getJobParameters().add( jobScheduleParamSafeModeEnable );


    // Set the gathering metrics param
    JobScheduleParam jobScheduleParamGatheringMetricsParam = new JobScheduleParam();
    jobScheduleParamGatheringMetricsParam.setName( "gatheringMetrics" );
    jobScheduleParamGatheringMetricsParam.setType( STRING_TYPE );
    jobScheduleParamGatheringMetricsParam
      .setStringValue( Arrays.asList( String.valueOf( meta.isGatheringMetrics() ) ) );
    jobScheduleRequest.getJobParameters().add( jobScheduleParamGatheringMetricsParam );

    if ( meta instanceof JobMeta ) {
      JobMeta jobMeta = (JobMeta) meta;

      if ( jobMeta.getStartCopyName() != null ) {
        // Set the start step name
        JobScheduleParam jobScheduleParamStartStepName = new JobScheduleParam();
        jobScheduleParamStartStepName.setName( "startCopyName" );
        jobScheduleParamStartStepName.setType( STRING_TYPE );
        jobScheduleParamStartStepName.setStringValue( Arrays.asList( jobMeta.getStartCopyName() ) );
        jobScheduleRequest.getJobParameters().add( jobScheduleParamStartStepName );
      }

      // Set the expanding remote job param
      JobScheduleParam jobScheduleParamExpandingRemoteJob = new JobScheduleParam();
      jobScheduleParamExpandingRemoteJob.setName( "expandingRemoteJob" );
      jobScheduleParamExpandingRemoteJob.setType( STRING_TYPE );
      jobScheduleParamExpandingRemoteJob
        .setStringValue( Arrays.asList( String.valueOf( jobMeta.isExpandingRemoteJob() ) ) );
      jobScheduleRequest.getJobParameters().add( jobScheduleParamExpandingRemoteJob );
    }

    // Set the PDI parameters
    if ( meta.listParameters() != null ) {
      for ( String param : meta.listParameters() ) {
        jobScheduleRequest.getPdiParameters().put( param, meta.getParameterValue( param ) );
      }
    }

    // Marshal object to string
    StringWriter sw = new StringWriter();
    String jobScheduleRequestString = null;
    try {
      JAXBContext jc = JAXBContext.newInstance( JobScheduleRequest.class );
      Marshaller marshaller = jc.createMarshaller();
      marshaller.marshal( jobScheduleRequest, sw );
      jobScheduleRequestString = sw.toString();
    } catch ( JAXBException e ) {
      repository.getLog().logError( BaseMessages.getString( PKG, "SchedulerRequest.error.marshal" ), e.getMessage() );
    }

    return new StringEntity( jobScheduleRequestString );
  }
@Test
  @SuppressWarnings( "ResultOfMethodCallIgnored" )
  public void testBuildSchedulerRequestEntity() throws UnknownParamException, UnsupportedEncodingException {
    AbstractMeta meta = mock( JobMeta.class );
    RepositoryDirectoryInterface repositoryDirectory = mock( RepositoryDirectoryInterface.class );

    doReturn( repositoryDirectory ).when( meta ).getRepositoryDirectory();
    doReturn( TEST_REPOSITORY_DIRECTORY ).when( repositoryDirectory ).getPath();
    doReturn( TEST_JOB_NAME ).when( meta ).getName();
    doReturn( JOB_EXTENSION ).when( meta ).getDefaultExtension();

    doReturn( LogLevel.getLogLevelForCode( TEST_LOG_LEVEL_PARAM_VALUE ) ).when( meta ).getLogLevel();
    doReturn( Boolean.valueOf( TEST_CLEAR_LOG_PARAM_VALUE ) ).when( meta ).isClearingLog();
    doReturn( Boolean.valueOf( TEST_RUN_SAFE_MODE_PARAM_VALUE ) ).when( meta ).isSafeModeEnabled();
    doReturn( Boolean.valueOf( TEST_GATHERING_METRICS_PARAM_VALUE ) ).when( meta ).isGatheringMetrics();
    doReturn( TEST_START_COPY_NAME_PARAM_VALUE ).when( (JobMeta) meta ).getStartCopyName();
    doReturn( Boolean.valueOf( TEST_EXPANDING_REMOTE_JOB_PARAM_VALUE ) ).when( (JobMeta) meta ).isExpandingRemoteJob();

    doReturn( ARRAY_WITH_TEST_PDI_PARAM_NAME ).when( meta ).listParameters();
    doReturn( TEST_PDI_PARAM_VALUE ).when( meta ).getParameterValue( TEST_PDI_PARAM_NAME );

    doCallRealMethod().when( schedulerRequest ).buildSchedulerRequestEntity( meta );

    assertTrue( compareContentOfStringEntities( schedulerRequest.buildSchedulerRequestEntity( meta ),
            new StringEntity( REFERENCE_TEST_REQUEST ) ) );
  }