Search in sources :

Example 66 with Job

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

the class MissingPluginJobIT method testForPluginMissingStep.

/**
 * Given a job having an entry which's plugin is missing in current Kettle installation.
 * When this job is executed, then execution should fail.
 */
@Test
public void testForPluginMissingStep() throws Exception {
    InputStream is = new FileInputStream(new File(this.getClass().getResource("missing_plugin_job.kjb").getFile()));
    JobMeta meta = new JobMeta(is, null, null);
    Job job = new Job(null, meta);
    Result result = new Result();
    job.execute(0, result);
    assertFalse(result.getResult());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Job(org.pentaho.di.job.Job) File(java.io.File) FileInputStream(java.io.FileInputStream) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Example 67 with Job

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

the class JobEntryLogTable method getLogRecord.

/**
 * This method calculates all the values that are required
 *
 * @param id
 *          the id to use or -1 if no id is needed
 * @param status
 *          the log status to use
 * @param subject
 *          the object to log
 * @param parent
 *          the parent to which the object belongs
 */
public RowMetaAndData getLogRecord(LogStatus status, Object subject, Object parent) {
    if (subject == null || subject instanceof JobEntryCopy) {
        JobEntryCopy jobEntryCopy = (JobEntryCopy) subject;
        Job parentJob = (Job) parent;
        RowMetaAndData row = new RowMetaAndData();
        for (LogTableField field : fields) {
            if (field.isEnabled()) {
                Object value = null;
                if (subject != null) {
                    JobEntryInterface jobEntry = jobEntryCopy.getEntry();
                    JobTracker jobTracker = parentJob.getJobTracker();
                    JobTracker entryTracker = jobTracker.findJobTracker(jobEntryCopy);
                    JobEntryResult jobEntryResult = null;
                    if (entryTracker != null) {
                        jobEntryResult = entryTracker.getJobEntryResult();
                    }
                    Result result = null;
                    if (jobEntryResult != null) {
                        result = jobEntryResult.getResult();
                    }
                    switch(ID.valueOf(field.getId())) {
                        case ID_BATCH:
                            value = new Long(parentJob.getBatchId());
                            break;
                        case CHANNEL_ID:
                            value = jobEntry.getLogChannel().getLogChannelId();
                            break;
                        case LOG_DATE:
                            value = new Date();
                            break;
                        case JOBNAME:
                            value = parentJob.getJobname();
                            break;
                        case JOBENTRYNAME:
                            value = jobEntry.getName();
                            break;
                        case LINES_READ:
                            value = new Long(result != null ? result.getNrLinesRead() : 0);
                            break;
                        case LINES_WRITTEN:
                            value = new Long(result != null ? result.getNrLinesWritten() : 0);
                            break;
                        case LINES_UPDATED:
                            value = new Long(result != null ? result.getNrLinesUpdated() : 0);
                            break;
                        case LINES_INPUT:
                            value = new Long(result != null ? result.getNrLinesInput() : 0);
                            break;
                        case LINES_OUTPUT:
                            value = new Long(result != null ? result.getNrLinesOutput() : 0);
                            break;
                        case LINES_REJECTED:
                            value = new Long(result != null ? result.getNrLinesRejected() : 0);
                            break;
                        case ERRORS:
                            value = new Long(result != null ? result.getNrErrors() : 0);
                            break;
                        case RESULT:
                            value = new Boolean(result != null ? result.getResult() : false);
                            break;
                        case NR_RESULT_FILES:
                            value = new Long(result != null && result.getResultFiles() != null ? result.getResultFiles().size() : 0);
                            break;
                        case NR_RESULT_ROWS:
                            value = new Long(result != null && result.getRows() != null ? result.getRows().size() : 0);
                            break;
                        case LOG_FIELD:
                            if (result != null) {
                                value = result.getLogText();
                            }
                            break;
                        case COPY_NR:
                            value = new Long(jobEntryCopy.getNr());
                            break;
                        default:
                            break;
                    }
                }
                row.addValue(field.getFieldName(), field.getDataType(), value);
                row.getRowMeta().getValueMeta(row.size() - 1).setLength(field.getLength());
            }
        }
        return row;
    } else {
        return null;
    }
}
Also used : JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) RowMetaAndData(org.pentaho.di.core.RowMetaAndData) JobEntryInterface(org.pentaho.di.job.entry.JobEntryInterface) JobTracker(org.pentaho.di.core.gui.JobTracker) Job(org.pentaho.di.job.Job) Date(java.util.Date) JobEntryResult(org.pentaho.di.job.JobEntryResult) Result(org.pentaho.di.core.Result) JobEntryResult(org.pentaho.di.job.JobEntryResult)

Example 68 with Job

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

the class GetJobStatusServletTest method testGetJobStatusServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class, Job.class })
public void testGetJobStatusServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Job mockJob = PowerMockito.mock(Job.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(GetJobStatusServlet.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);
    PowerMockito.when(mockJob.getJobname()).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    PowerMockito.when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
    PowerMockito.when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
    PowerMockito.when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
    getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(out.toString().contains(ServletTestUtils.BAD_STRING_TO_TEST));
    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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 69 with Job

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

the class GetJobStatusServletTest method testGetJobStatus.

@Test
@PrepareForTest({ Job.class })
public void testGetJobStatus() throws ServletException, IOException {
    KettleLogStore.init();
    CarteStatusCache cacheMock = mock(CarteStatusCache.class);
    getJobStatusServlet.cache = cacheMock;
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Job mockJob = PowerMockito.mock(Job.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
    ServletOutputStream outMock = mock(ServletOutputStream.class);
    String id = "123";
    String logId = "logId";
    String useXml = "Y";
    when(mockHttpServletRequest.getContextPath()).thenReturn(GetJobStatusServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter("id")).thenReturn(id);
    when(mockHttpServletRequest.getParameter("xml")).thenReturn(useXml);
    when(mockHttpServletResponse.getOutputStream()).thenReturn(outMock);
    when(mockJobMap.findJob(id)).thenReturn(mockJob);
    PowerMockito.when(mockJob.getJobname()).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    PowerMockito.when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
    PowerMockito.when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
    PowerMockito.when(mockJob.isFinished()).thenReturn(true);
    PowerMockito.when(mockJob.getLogChannelId()).thenReturn(logId);
    PowerMockito.when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
    getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    when(cacheMock.get(logId, 0)).thenReturn(new byte[] { 0, 1, 2 });
    getJobStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    verify(cacheMock, times(2)).get(logId, 0);
    verify(cacheMock, times(1)).put(eq(logId), anyString(), eq(0));
    verify(mockJob.getLogChannel(), times(1));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) JobMeta(org.pentaho.di.job.JobMeta) ServletOutputStream(javax.servlet.ServletOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) CarteStatusCache(org.pentaho.di.www.cache.CarteStatusCache) Matchers.anyString(org.mockito.Matchers.anyString) Point(org.pentaho.di.core.gui.Point) Job(org.pentaho.di.job.Job) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 70 with Job

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

the class RemoveJobServletTest method testRemoveJobServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testRemoveJobServletEscapesHtmlWhenTransFound() 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(RemoveJobServlet.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));
    removeJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H3", 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