Search in sources :

Example 16 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class StartJobServletIT method testStartJobServletEscapesHtmlWhenTransFound.

@Test
public void testStartJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Job mockJob = mock(Job.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
    mockJob.setName(ServletTestUtils.BAD_STRING);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StartJobServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockJobMap.getJob(any(CarteObjectEntry.class))).thenReturn(mockJob);
    when(mockJob.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING);
    when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
    when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
    when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
    startJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JobMeta(org.pentaho.di.job.JobMeta) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Job(org.pentaho.di.job.Job) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) Test(org.junit.Test)

Example 17 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class CopyFilesIT method testLocalFileCopy.

/**
 * Tests copying a folder contents. The folders used are created in the Java's temp location using unique folder and
 * file names.
 *
 * @throws Exception
 */
@Test
public void testLocalFileCopy() throws Exception {
    String sourceFolder = TestUtilities.createTempFolder("testLocalFileCopy_source");
    String destinationFolder = TestUtilities.createTempFolder("testLocalFileCopy_destination");
    if (Utils.isEmpty(sourceFolder) || Utils.isEmpty(destinationFolder)) {
        fail("Could not create the source and/or destination folder(s).");
    }
    // create a text file named testLocalFileCopy with a delimiter of ;
    TestUtilities.writeTextFile(sourceFolder, "testLocalFileCopy", ";");
    // the parent job
    Job parentJob = new Job();
    // Set up the job entry to do wildcard copy
    JobEntryCopyFiles jobEntry = new JobEntryCopyFiles("Job entry copy files");
    jobEntry.source_filefolder = new String[] { sourceFolder };
    jobEntry.destination_filefolder = new String[] { destinationFolder };
    jobEntry.wildcard = new String[] { "" };
    jobEntry.setParentJob(parentJob);
    // Check the result for errors.
    Result result = jobEntry.execute(createStartJobEntryResult(), 1);
    if (result.getNrErrors() != 0) {
        fail(result.getLogText());
    }
}
Also used : Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 18 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class JobEntrySFTPIT method getFile_WhenDestinationIsSetViaVariable.

@Test
public void getFile_WhenDestinationIsSetViaVariable() throws Exception {
    final String localDir = TestUtils.createTempDir();
    KettleVFS.getFileObject(localDir).createFolder();
    final String myVar = "my-var";
    final String sftpDir = "job-entry-sftp-test";
    final String fileName = "file.txt";
    uploadFile(sftpDir, fileName);
    JobEntrySFTP job = new JobEntrySFTP();
    job.setVariable(myVar, localDir);
    Job parent = mock(Job.class);
    when(parent.isStopped()).thenReturn(false);
    job.setParentJob(parent);
    job.setLogLevel(LogLevel.NOTHING);
    job.setUserName(server.getUsername());
    job.setPassword(server.getPassword());
    job.setServerName("localhost");
    job.setServerPort(Integer.toString(server.getPort()));
    job.setScpDirectory(sftpDir);
    job.setTargetDirectory(String.format("${%s}", myVar));
    job.execute(new Result(), 1);
    FileObject downloaded = KettleVFS.getFileObject(localDir + "/" + fileName);
    assertTrue(downloaded.exists());
    downloaded.delete();
}
Also used : FileObject(org.apache.commons.vfs2.FileObject) Job(org.pentaho.di.job.Job) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 19 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class JobEntryTransIntIT method testPDI14676.

/*
   * Tests whether the job can force a transformation to stop, when the job is asked to stop.
   * A timeout parameter is required, to avoid a failed unit test from running forever.
   */
@Test(timeout = 30000)
public void testPDI14676() throws KettleException, IOException, InterruptedException {
    String transFilename = createPDI14676Transformation();
    // Setup Job
    JobEntrySpecial startEntry = new JobEntrySpecial("Start", true, false);
    JobEntryCopy startCopy = new JobEntryCopy(startEntry);
    startCopy.setLocation(50, 50);
    startCopy.setDrawn();
    JobEntryTrans transEntry = new JobEntryTrans("PDI-13676 example");
    transEntry.setSpecificationMethod(ObjectLocationSpecificationMethod.FILENAME);
    transEntry.setFileName(transFilename);
    JobEntryCopy transCopy = new JobEntryCopy(transEntry);
    transCopy.setLocation(200, 50);
    transCopy.setDrawn();
    JobMeta jobMeta = new JobMeta();
    jobMeta.addJobEntry(startCopy);
    jobMeta.addJobEntry(transCopy);
    jobMeta.addJobHop(new JobHopMeta(startCopy, transCopy));
    // Run job
    Job jobInstance = new Job(null, jobMeta);
    jobInstance.start();
    // Allow job startup time
    while (!jobInstance.isActive()) {
        if (jobInstance.isStopped() || jobInstance.isFinished()) {
            break;
        }
        Thread.sleep(10);
    }
    // Let the job run for a short period
    Thread.sleep(300);
    assertFalse(jobInstance.isStopped());
    assertFalse(jobInstance.isFinished());
    // Tell the job to stop.
    jobInstance.stopAll();
    assertTrue(jobInstance.isStopped());
    // Allow the job's thread to stop and be cleaned up
    while (!jobInstance.isFinished() || jobInstance.isActive()) {
        Thread.sleep(10);
    }
    // Ensure that the job and the thread have both stopped
    assertTrue(jobInstance.isFinished());
    assertFalse(jobInstance.isAlive());
}
Also used : JobEntrySpecial(org.pentaho.di.job.entries.special.JobEntrySpecial) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobMeta(org.pentaho.di.job.JobMeta) JobHopMeta(org.pentaho.di.job.JobHopMeta) Job(org.pentaho.di.job.Job) Test(org.junit.Test)

Example 20 with Job

use of org.pentaho.di.job.Job in project pentaho-kettle by pentaho.

the class StartJobServletTest method testStartJobServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testStartJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Job mockJob = mock(Job.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
    mockJob.setName(ServletTestUtils.BAD_STRING_TO_TEST);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StartJobServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockJobMap.getJob(any(CarteObjectEntry.class))).thenReturn(mockJob);
    when(mockJob.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
    when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
    when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
    startJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JobMeta(org.pentaho.di.job.JobMeta) StringWriter(java.io.StringWriter) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Job(org.pentaho.di.job.Job) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Job (org.pentaho.di.job.Job)95 JobMeta (org.pentaho.di.job.JobMeta)44 Test (org.junit.Test)35 Result (org.pentaho.di.core.Result)22 KettleException (org.pentaho.di.core.exception.KettleException)20 PrintWriter (java.io.PrintWriter)17 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)17 Trans (org.pentaho.di.trans.Trans)14 IOException (java.io.IOException)11 Before (org.junit.Before)11 Point (org.pentaho.di.core.gui.Point)11 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)11 JobExecutionConfiguration (org.pentaho.di.job.JobExecutionConfiguration)10 Repository (org.pentaho.di.repository.Repository)10 ArrayList (java.util.ArrayList)9 ServletException (javax.servlet.ServletException)9 HttpServletRequest (javax.servlet.http.HttpServletRequest)9 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 SimpleLoggingObject (org.pentaho.di.core.logging.SimpleLoggingObject)9 JobConfiguration (org.pentaho.di.job.JobConfiguration)9