use of org.pentaho.di.www.cache.CarteStatusCache 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.www.cache.CarteStatusCache 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(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.getLogChannel(), times(1));
}
Aggregations