Search in sources :

Example 31 with LogChannelInterface

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

the class BaseStepTest method testBaseStepPutRowLocalSpecialPartitioning.

/**
 * This test checks that data from one non-partitioned step copies to 2 partitioned steps right.
 *
 * @throws KettleException
 * @see {@link <a href="http://jira.pentaho.com/browse/PDI-12211">http://jira.pentaho.com/browse/PDI-12211<a>}
 */
@Test
public void testBaseStepPutRowLocalSpecialPartitioning() throws KettleException {
    List<StepMeta> stepMetas = new ArrayList<StepMeta>();
    stepMetas.add(mockHelper.stepMeta);
    stepMetas.add(mockHelper.stepMeta);
    StepPartitioningMeta stepPartitioningMeta = spy(new StepPartitioningMeta());
    BasePartitioner partitioner = mock(BasePartitioner.class);
    when(mockHelper.logChannelInterfaceFactory.create(any(), any(LoggingObjectInterface.class))).thenAnswer(new Answer<LogChannelInterface>() {

        @Override
        public LogChannelInterface answer(InvocationOnMock invocation) throws Throwable {
            ((BaseStep) invocation.getArguments()[0]).getLogLevel();
            return mockHelper.logChannelInterface;
        }
    });
    when(mockHelper.trans.isRunning()).thenReturn(true);
    when(mockHelper.transMeta.findNextSteps(any(StepMeta.class))).thenReturn(stepMetas);
    when(mockHelper.stepMeta.getStepPartitioningMeta()).thenReturn(stepPartitioningMeta);
    when(stepPartitioningMeta.getPartitioner()).thenReturn(partitioner);
    when(partitioner.getNrPartitions()).thenReturn(2);
    Object object0 = "name0";
    ValueMetaInterface meta0 = new ValueMetaString(object0.toString());
    Object object1 = "name1";
    ValueMetaInterface meta2 = new ValueMetaString(object1.toString());
    RowMetaInterface rowMeta0 = new RowMeta();
    rowMeta0.addValueMeta(meta0);
    Object[] objects0 = { object0 };
    RowMetaInterface rowMeta1 = new RowMeta();
    rowMeta1.addValueMeta(meta2);
    Object[] objects1 = { object1 };
    when(stepPartitioningMeta.getPartition(rowMeta0, objects0)).thenReturn(0);
    when(stepPartitioningMeta.getPartition(rowMeta1, objects1)).thenReturn(1);
    BlockingRowSet[] rowSet = { new BlockingRowSet(2), new BlockingRowSet(2), new BlockingRowSet(2), new BlockingRowSet(2) };
    List<RowSet> outputRowSets = new ArrayList<RowSet>();
    outputRowSets.addAll(Arrays.asList(rowSet));
    BaseStep baseStep = new BaseStep(mockHelper.stepMeta, mockHelper.stepDataInterface, 0, mockHelper.transMeta, mockHelper.trans);
    baseStep.setStopped(false);
    baseStep.setRepartitioning(StepPartitioningMeta.PARTITIONING_METHOD_SPECIAL);
    baseStep.setOutputRowSets(outputRowSets);
    baseStep.putRow(rowMeta0, objects0);
    baseStep.putRow(rowMeta1, objects1);
    assertEquals(object0, baseStep.getOutputRowSets().get(0).getRow()[0]);
    assertEquals(object1, baseStep.getOutputRowSets().get(1).getRow()[0]);
    assertEquals(object0, baseStep.getOutputRowSets().get(2).getRow()[0]);
    assertEquals(object1, baseStep.getOutputRowSets().get(3).getRow()[0]);
}
Also used : ValueMetaString(org.pentaho.di.core.row.value.ValueMetaString) RowMeta(org.pentaho.di.core.row.RowMeta) ArrayList(java.util.ArrayList) QueueRowSet(org.pentaho.di.core.QueueRowSet) SingleRowRowSet(org.pentaho.di.core.SingleRowRowSet) RowSet(org.pentaho.di.core.RowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) BlockingRowSet(org.pentaho.di.core.BlockingRowSet) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) BasePartitioner(org.pentaho.di.trans.BasePartitioner) InvocationOnMock(org.mockito.invocation.InvocationOnMock) NonAccessibleFileObject(org.pentaho.di.core.fileinput.NonAccessibleFileObject) LoggingObjectInterface(org.pentaho.di.core.logging.LoggingObjectInterface) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 32 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface 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 33 with LogChannelInterface

use of org.pentaho.di.core.logging.LogChannelInterface 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 34 with LogChannelInterface

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

the class GetSlavesServletTest method testUpdateActivityStatusInDoGet.

@Test
@SuppressWarnings("ResultOfMethodCallIgnored")
public void testUpdateActivityStatusInDoGet() throws Exception {
    LogChannelInterface log = mock(LogChannelInterface.class);
    ServletOutputStream outputStream = mock(ServletOutputStream.class);
    SlaveServerDetection activeServerDetection = mock(SlaveServerDetection.class);
    SlaveServerDetection inactiveServerDetection = mock(SlaveServerDetection.class);
    SlaveServer activeSlaveServer = mock(SlaveServer.class);
    SlaveServer inactiveSlaveServer = mock(SlaveServer.class);
    servlet.log = log;
    List<SlaveServerDetection> detections = new ArrayList<>();
    detections.add(activeServerDetection);
    detections.add(inactiveServerDetection);
    doReturn(false).when(log).isDebug();
    doReturn(outputStream).when(response).getOutputStream();
    doReturn(detections).when(servlet).getDetections();
    doReturn(activeSlaveServer).when(activeServerDetection).getSlaveServer();
    doReturn(inactiveSlaveServer).when(inactiveServerDetection).getSlaveServer();
    doThrow(new Exception()).when(inactiveSlaveServer).getStatus();
    doCallRealMethod().when(servlet).doGet(request, response);
    servlet.doGet(request, response);
    verify(activeSlaveServer).getStatus();
    verify(activeServerDetection, never()).setActive(false);
    verify(activeServerDetection, never()).setLastInactiveDate(anyObject());
    verify(activeServerDetection).getXML();
    verify(inactiveSlaveServer).getStatus();
    verify(inactiveServerDetection).setActive(false);
    verify(inactiveServerDetection).setLastInactiveDate(anyObject());
    verify(inactiveServerDetection).getXML();
}
Also used : ServletOutputStream(javax.servlet.ServletOutputStream) ArrayList(java.util.ArrayList) SlaveServer(org.pentaho.di.cluster.SlaveServer) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) Test(org.junit.Test)

Example 35 with LogChannelInterface

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

the class GetStatusServletTest method testGetStatusServletEscapesHtmlWhenTransFound.

@Test
public void testGetStatusServletEscapesHtmlWhenTransFound() 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);
    LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    when(mockHttpServletRequest.getContextPath()).thenReturn(GetStatusServlet.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.getTransMeta()).thenReturn(mockTransMeta);
    when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
    getStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(out.toString().contains(ServletTestUtils.BAD_STRING_TO_TEST));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) TransMeta(org.pentaho.di.trans.TransMeta) 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) Test(org.junit.Test)

Aggregations

LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)65 Test (org.junit.Test)42 HttpServletRequest (javax.servlet.http.HttpServletRequest)27 HttpServletResponse (javax.servlet.http.HttpServletResponse)27 PrintWriter (java.io.PrintWriter)26 Point (org.pentaho.di.core.gui.Point)26 StringWriter (java.io.StringWriter)25 TransMeta (org.pentaho.di.trans.TransMeta)24 Trans (org.pentaho.di.trans.Trans)20 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 KettleException (org.pentaho.di.core.exception.KettleException)12 JobMeta (org.pentaho.di.job.JobMeta)12 Job (org.pentaho.di.job.Job)11 ArrayList (java.util.ArrayList)8 LogChannel (org.pentaho.di.core.logging.LogChannel)6 Matchers.anyString (org.mockito.Matchers.anyString)5 Before (org.junit.Before)4 StepInterface (org.pentaho.di.trans.step.StepInterface)4 ServletOutputStream (javax.servlet.ServletOutputStream)3 LoggingObjectInterface (org.pentaho.di.core.logging.LoggingObjectInterface)3