Search in sources :

Example 66 with LogChannelInterface

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

the class StartExecutionTransServletTest method testStartExecutionTransServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testStartExecutionTransServletEscapesHtmlWhenTransFound() 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(StartExecutionTransServlet.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.isReadyToStart()).thenReturn(true);
    when(mockTrans.getLogChannelId()).thenReturn("test");
    when(mockTrans.getTransMeta()).thenReturn(mockTransMeta);
    when(mockTransMeta.getMaximum()).thenReturn(new Point(10, 10));
    startExecutionTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 67 with LogChannelInterface

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

the class StartTransServletTest method testStartTransServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testStartTransServletEscapesHtmlWhenTransFound() 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(StartTransServlet.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));
    startTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 68 with LogChannelInterface

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

the class StopTransServletTest method testStopTransServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testStopTransServletEscapesHtmlWhenTransFound() 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(StopTransServlet.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));
    stopTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 69 with LogChannelInterface

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

the class PauseTransServletTest method testPauseTransServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testPauseTransServletEscapesHtmlWhenTransFound() 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(PauseTransServlet.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));
    pauseTransServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(atLeastOnce());
    Encode.forHtml(anyString());
}
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) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 70 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)

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