use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class GetTransStatusServletTest method testGetTransStatusServletEscapesHtmlWhenTransFound.
@Test
@PrepareForTest({ Encode.class })
public void testGetTransStatusServletEscapesHtmlWhenTransFound() 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);
PowerMockito.spy(Encode.class);
when(mockHttpServletRequest.getContextPath()).thenReturn(GetTransStatusServlet.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));
getTransStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("TITLE", out.toString())));
PowerMockito.verifyStatic(atLeastOnce());
Encode.forHtml(anyString());
}
use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class GetTransStatusServletTest method testGetTransStatus.
@Test
public void testGetTransStatus() throws ServletException, IOException {
KettleLogStore.init();
CarteStatusCache cacheMock = mock(CarteStatusCache.class);
getTransStatusServlet.cache = cacheMock;
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);
ServletOutputStream outMock = mock(ServletOutputStream.class);
String id = "123";
String logId = "logId";
String useXml = "Y";
when(mockHttpServletRequest.getContextPath()).thenReturn(GetTransStatusServlet.CONTEXT_PATH);
when(mockHttpServletRequest.getParameter("id")).thenReturn(id);
when(mockHttpServletRequest.getParameter("xml")).thenReturn(useXml);
when(mockHttpServletResponse.getOutputStream()).thenReturn(outMock);
when(mockTransformationMap.getTransformation(any(CarteObjectEntry.class))).thenReturn(mockTrans);
when(mockTrans.getLogChannel()).thenReturn(mockChannelInterface);
when(mockTrans.getTransMeta()).thenReturn(mockTransMeta);
when(mockTrans.getLogChannelId()).thenReturn(logId);
when(mockTrans.isFinishedOrStopped()).thenReturn(true);
when(mockTrans.getStatus()).thenReturn("Finished");
when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
getTransStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
when(cacheMock.get(logId, 0)).thenReturn(new byte[] { 0, 1, 2 });
getTransStatusServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
verify(cacheMock, times(2)).get(logId, 0);
verify(cacheMock, times(1)).put(eq(logId), anyString(), eq(0));
verify(mockTrans, times(1)).getLogChannel();
}
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));
}
use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class GetStatusServletTest method setupForJobDroppedFromMap.
private void setupForJobDroppedFromMap(HttpServletRequest mockHttpServletRequest, HttpServletResponse mockHttpServletResponse, StringWriter out) throws IOException {
KettleLogStore.init();
Trans mockTrans = mock(Trans.class);
TransMeta mockTransMeta = mock(TransMeta.class);
LogChannelInterface mockChannelInterface = mock(LogChannelInterface.class);
PrintWriter printWriter = new PrintWriter(out);
CarteObjectEntry carteObjectEntry1 = new CarteObjectEntry("name1", "testJobId1");
CarteObjectEntry carteObjectEntry2 = new CarteObjectEntry("name2", "testJobId2");
when(mockHttpServletRequest.getContextPath()).thenReturn(GetStatusServlet.CONTEXT_PATH);
when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
Job mockJob = mock(Job.class);
when(mockJobMap.getJobObjects()).thenReturn(Arrays.asList(carteObjectEntry1, carteObjectEntry2));
when(mockJobMap.getJob(carteObjectEntry1)).thenReturn(// Would have done this anyways but this line is to show it is required
null);
when(mockJobMap.getJob(carteObjectEntry2)).thenReturn(mockJob);
}
use of org.pentaho.di.core.logging.LogChannelInterface in project pentaho-kettle by pentaho.
the class RemoveTransServletTest method testRemoveTransServletEscapesHtmlWhenTransFound.
@Test
@PrepareForTest({ Encode.class })
public void testRemoveTransServletEscapesHtmlWhenTransFound() 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);
PowerMockito.spy(Encode.class);
when(mockHttpServletRequest.getContextPath()).thenReturn(RemoveTransServlet.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));
removeTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H3", out.toString())));
PowerMockito.verifyStatic(atLeastOnce());
Encode.forHtml(anyString());
}
Aggregations