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]);
}
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());
}
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));
}
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();
}
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));
}
Aggregations