Search in sources :

Example 86 with Point

use of org.pentaho.di.core.gui.Point 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 87 with Point

use of org.pentaho.di.core.gui.Point 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 88 with Point

use of org.pentaho.di.core.gui.Point 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)

Example 89 with Point

use of org.pentaho.di.core.gui.Point 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("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 90 with Point

use of org.pentaho.di.core.gui.Point 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));
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletOutputStream(javax.servlet.ServletOutputStream) TransMeta(org.pentaho.di.trans.TransMeta) 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) Trans(org.pentaho.di.trans.Trans) LogChannelInterface(org.pentaho.di.core.logging.LogChannelInterface) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Point (org.pentaho.di.core.gui.Point)141 KettleExtensionPoint (org.pentaho.di.core.extension.KettleExtensionPoint)72 Test (org.junit.Test)37 StepMeta (org.pentaho.di.trans.step.StepMeta)34 NotePadMeta (org.pentaho.di.core.NotePadMeta)29 KettleException (org.pentaho.di.core.exception.KettleException)28 JobEntryCopy (org.pentaho.di.job.entry.JobEntryCopy)28 PrintWriter (java.io.PrintWriter)26 HttpServletRequest (javax.servlet.http.HttpServletRequest)26 HttpServletResponse (javax.servlet.http.HttpServletResponse)26 LogChannelInterface (org.pentaho.di.core.logging.LogChannelInterface)26 TransMeta (org.pentaho.di.trans.TransMeta)25 StringWriter (java.io.StringWriter)24 AreaOwner (org.pentaho.di.core.gui.AreaOwner)22 Trans (org.pentaho.di.trans.Trans)18 JobMeta (org.pentaho.di.job.JobMeta)17 ArrayList (java.util.ArrayList)16 TransHopMeta (org.pentaho.di.trans.TransHopMeta)14 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)14 KettleRepositoryLostException (org.pentaho.di.repository.KettleRepositoryLostException)12