Search in sources :

Example 56 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class RunConfigurationDelegateTest method testUpdateLoadedJobs_Exception.

@Test
public void testUpdateLoadedJobs_Exception() throws Exception {
    JobEntryTrans trans = new JobEntryTrans();
    trans.setRunConfiguration("key");
    JobMeta meta = new JobMeta();
    meta.addJobEntry(new JobEntryCopy(trans));
    JobMeta[] jobs = new JobMeta[] { meta };
    doReturn(jobs).when(spoon).getLoadedJobs();
    DefaultRunConfiguration config = new DefaultRunConfiguration();
    config.setName("Test");
    config.setServer("localhost");
    LogChannelInterface log = mock(LogChannelInterface.class);
    doReturn(log).when(spoon).getLog();
    PowerMockito.mockStatic(ExtensionPointHandler.class);
    PowerMockito.when(ExtensionPointHandler.class, "callExtensionPoint", any(), any(), any()).thenThrow(KettleException.class);
    delegate.updateLoadedJobs("key", config);
    verify(log, times(1)).logBasic(any());
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) JobEntryTrans(org.pentaho.di.job.entries.trans.JobEntryTrans) DefaultRunConfiguration(org.pentaho.di.engine.configuration.impl.pentaho.DefaultRunConfiguration) ExtensionPointHandler(org.pentaho.di.core.extension.ExtensionPointHandler) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 57 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class OpenMappingExtensionTest method setKettleLogFactoryWithMock.

private void setKettleLogFactoryWithMock() {
    LogChannelInterfaceFactory logChannelInterfaceFactory = mock(LogChannelInterfaceFactory.class);
    logChannelInterface = mock(LogChannelInterface.class);
    when(logChannelInterfaceFactory.create(any())).thenReturn(logChannelInterface);
    KettleLogStore.setLogChannelInterfaceFactory(logChannelInterfaceFactory);
}
Also used : LogChannelInterfaceFactory(org.pentaho.di.core.logging.LogChannelInterfaceFactory) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface)

Example 58 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface 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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 59 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class SniffStepServletTest method testSniffStepServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testSniffStepServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Trans mockTrans = mock(Trans.class);
    TransMeta mockTransMeta = mock(TransMeta.class);
    StepInterface mockStepInterface = mock(StepInterface.class);
    List<StepInterface> stepInterfaces = new ArrayList<StepInterface>();
    stepInterfaces.add(mockStepInterface);
    LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(SniffStepServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockTransformationMap.getTransformation(any(CarteObjectEntry.class))).thenReturn(mockTrans);
    when(mockTrans.getLogChannel()).thenReturn(mockChannelInterface);
    when(mockTrans.getLogChannelId()).thenReturn("test");
    when(mockTrans.getTransMeta()).thenReturn(mockTransMeta);
    when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
    when(mockTrans.findBaseSteps(ServletTestUtils.BAD_STRING_TO_TEST)).thenReturn(stepInterfaces);
    sniffStepServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StepInterface(org.pentaho.di.trans.step.StepInterface) StringWriter(java.io.StringWriter) TransMeta(org.pentaho.di.trans.TransMeta) ArrayList(java.util.ArrayList) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.pentaho.di.core.gui.Point) Trans(org.pentaho.di.trans.Trans) 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 60 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.

the class BlackBoxIT method runTransOrJob.

// This is a generic JUnit 4 test that takes no parameters
@Test
public void runTransOrJob() throws Exception {
    // Params are:
    // File transFile
    // List<File> expectedFiles
    LogChannelInterface log = new LogChannel("BlackBoxTest [" + transFile.toString() + "]");
    if (!transFile.exists()) {
        log.logError("Transformation does not exist: " + getPath(transFile));
        addFailure("Transformation does not exist: " + getPath(transFile));
        fail("Transformation does not exist: " + getPath(transFile));
    }
    if (expectedFiles.isEmpty()) {
        addFailure("No expected output files found: " + getPath(transFile));
        fail("No expected output files found: " + getPath(transFile));
    }
    Result result = runTrans(transFile.getAbsolutePath(), log);
    // 
    for (int i = 0; i < expectedFiles.size(); i++) {
        File expected = expectedFiles.get(i);
        if (expected.getAbsoluteFile().toString().contains(".expected")) {
            // create a path to the expected output
            String actualFile = expected.getAbsolutePath();
            // multiple files case
            actualFile = actualFile.replaceFirst(".expected_" + i + ".", ".actual_" + i + ".");
            // single file case
            actualFile = actualFile.replaceFirst(".expected.", ".actual.");
            File actual = new File(actualFile);
            if (result.getResult()) {
                fileCompare(expected, actual);
            }
        }
    }
    // 
    if (!result.getResult()) {
        String logStr = KettleLogStore.getAppender().getBuffer(result.getLogChannelId(), true).toString();
        if (expectedFiles.size() == 0) {
            // We haven't got a ".fail.txt" file, so this is a real failure
            fail("Error running " + getPath(transFile) + ":" + logStr);
        }
    }
}
Also used : LogChannel(org.pentaho.di.core.logging.LogChannel) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) File(java.io.File) Result(org.pentaho.di.core.Result) Test(org.junit.Test)

Aggregations

LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)85 Test (org.junit.Test)53 PrintWriter (java.io.PrintWriter)29 TransMeta (org.pentaho.di.trans.TransMeta)29 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 StringWriter (java.io.StringWriter)26 Point (org.pentaho.di.core.gui.Point)26 Trans (org.pentaho.di.trans.Trans)23 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)19 Job (org.pentaho.di.job.Job)17 JobMeta (org.pentaho.di.job.JobMeta)15 KettleException (org.pentaho.di.core.exception.KettleException)12 ArrayList (java.util.ArrayList)9 Matchers.anyString (org.mockito.Matchers.anyString)7 LogChannel (org.pentaho.di.core.logging.LogChannel)6 AbstractMeta (org.pentaho.di.base.AbstractMeta)5 Repository (org.pentaho.di.repository.Repository)5 RepositoryDirectoryInterface (org.pentaho.di.repository.RepositoryDirectoryInterface)5 ExtensionPointWrapper (org.pentaho.di.ui.core.events.dialog.extension.ExtensionPointWrapper)5