Search in sources :

Example 51 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class StopJobServletTest method testStopJobServletEscapesHtmlWhenTransFound.

@Test
@PrepareForTest({ Encode.class })
public void testStopJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException {
    KettleLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Job mockJob = mock(Job.class);
    JobMeta mockJobMeta = mock(JobMeta.class);
    LogChannelInterface mockLogChannelInterface = mock(LogChannelInterface.class);
    mockJob.setName(ServletTestUtils.BAD_STRING_TO_TEST);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StopJobServlet.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);
    when(mockJob.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    when(mockJob.getLogChannel()).thenReturn(mockLogChannelInterface);
    when(mockJob.getJobMeta()).thenReturn(mockJobMeta);
    when(mockJobMeta.getMaximum()).thenReturn(new Point(10, 10));
    stopJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    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) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 52 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class StopTransServletIT method testStopTransServletEscapesHtmlWhenTransFound.

@Test
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);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StopTransServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING);
    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())));
}
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 53 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class JobInformation method loadValues.

private JobInformationValues loadValues(ReportSubjectLocation location) throws KettleException {
    // Load the job
    // 
    JobMeta jobMeta = loadJob(location);
    Point min = jobMeta.getMinimum();
    Point area = jobMeta.getMaximum();
    area.x += 30;
    area.y += 30;
    int iconsize = 32;
    ScrollBarInterface bar = new ScrollBarInterface() {

        public void setThumb(int thumb) {
        }

        public int getSelection() {
            return 0;
        }
    };
    // Paint the transformation...
    // 
    GCInterface gc = new SwingGC(null, area, iconsize, 50, 20);
    List<AreaOwner> areaOwners = new ArrayList<AreaOwner>();
    JobPainter painter = new JobPainter(gc, jobMeta, area, bar, bar, null, null, null, areaOwners, new ArrayList<JobEntryCopy>(), iconsize, 1, 0, 0, true, "FreeSans", 10);
    painter.setMagnification(0.25f);
    painter.drawJob();
    BufferedImage bufferedImage = (BufferedImage) gc.getImage();
    int newWidth = bufferedImage.getWidth() - min.x;
    int newHeigth = bufferedImage.getHeight() - min.y;
    BufferedImage image = new BufferedImage(newWidth, newHeigth, bufferedImage.getType());
    image.getGraphics().drawImage(bufferedImage, 0, 0, newWidth, newHeigth, min.x, min.y, min.x + newWidth, min.y + newHeigth, null);
    JobInformationValues values = new JobInformationValues();
    values.jobMeta = jobMeta;
    values.image = image;
    values.areaOwners = areaOwners;
    return values;
}
Also used : JobMeta(org.pentaho.di.job.JobMeta) JobPainter(org.pentaho.di.job.JobPainter) ArrayList(java.util.ArrayList) Point(org.pentaho.di.core.gui.Point) SwingGC(org.pentaho.di.core.gui.SwingGC) Point(org.pentaho.di.core.gui.Point) ScrollBarInterface(org.pentaho.di.core.gui.ScrollBarInterface) BufferedImage(java.awt.image.BufferedImage) GCInterface(org.pentaho.di.core.gui.GCInterface) JobEntryCopy(org.pentaho.di.job.entry.JobEntryCopy) AreaOwner(org.pentaho.di.core.gui.AreaOwner)

Example 54 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class TransformationInformation method drawImage.

public void drawImage(final Graphics2D g2d, final Rectangle2D rectangle2d, ReportSubjectLocation location, boolean pixelateImages) throws KettleException {
    // Load the transformation
    // 
    TransMeta transMeta = loadTransformation(location);
    Point min = transMeta.getMinimum();
    Point area = transMeta.getMaximum();
    area.x -= min.x;
    area.y -= min.y;
    int iconsize = 32;
    ScrollBarInterface bar = new ScrollBarInterface() {

        public void setThumb(int thumb) {
        }

        public int getSelection() {
            return 0;
        }
    };
    // Paint the transformation...
    // 
    Rectangle rect = new java.awt.Rectangle(0, 0, area.x, area.y);
    double magnificationX = rectangle2d.getWidth() / rect.getWidth();
    double magnificationY = rectangle2d.getHeight() / rect.getHeight();
    float magnification = (float) Math.min(1, Math.min(magnificationX, magnificationY));
    SwingGC gc = new SwingGC(g2d, rect, iconsize, 0, 0);
    gc.setDrawingPixelatedImages(pixelateImages);
    TransPainter painter = new TransPainter(gc, transMeta, area, bar, bar, null, null, null, new ArrayList<AreaOwner>(), new ArrayList<StepMeta>(), iconsize, 1, 0, 0, true, "FreeSans", 10);
    painter.setMagnification(magnification);
    painter.setTranslationX((-min.x) * magnification);
    painter.setTranslationY((-min.y) * magnification);
    painter.buildTransformationImage();
}
Also used : TransMeta(org.pentaho.di.trans.TransMeta) Rectangle(java.awt.Rectangle) Point(org.pentaho.di.core.gui.Point) SwingGC(org.pentaho.di.core.gui.SwingGC) StepMeta(org.pentaho.di.trans.step.StepMeta) Point(org.pentaho.di.core.gui.Point) ScrollBarInterface(org.pentaho.di.core.gui.ScrollBarInterface) AreaOwner(org.pentaho.di.core.gui.AreaOwner) TransPainter(org.pentaho.di.trans.TransPainter)

Example 55 with Point

use of org.pentaho.di.core.gui.Point in project pentaho-kettle by pentaho.

the class AbstractMetaTest method testAddRemoveViewUndo.

@Test
public void testAddRemoveViewUndo() throws Exception {
    // addUndo() right now will fail with an NPE
    assertEquals(0, meta.getUndoSize());
    meta.clearUndo();
    assertEquals(0, meta.getUndoSize());
    assertEquals(0, meta.getMaxUndo());
    meta.setMaxUndo(3);
    assertEquals(3, meta.getMaxUndo());
    // viewThisUndo() and viewPreviousUndo() have the same logic
    assertNull(meta.viewThisUndo());
    assertNull(meta.viewPreviousUndo());
    assertNull(meta.viewNextUndo());
    assertNull(meta.previousUndo());
    assertNull(meta.nextUndo());
    StepMeta fromMeta = mock(StepMeta.class);
    StepMeta toMeta = mock(StepMeta.class);
    Object[] from = new Object[] { fromMeta };
    Object[] to = new Object[] { toMeta };
    int[] pos = new int[0];
    Point[] prev = new Point[0];
    Point[] curr = new Point[0];
    meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_NEW, false);
    assertNotNull(meta.viewThisUndo());
    assertNotNull(meta.viewPreviousUndo());
    assertNull(meta.viewNextUndo());
    meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_CHANGE, false);
    assertNotNull(meta.viewThisUndo());
    assertNotNull(meta.viewPreviousUndo());
    assertNull(meta.viewNextUndo());
    TransAction action = meta.previousUndo();
    assertNotNull(action);
    assertEquals(AbstractMeta.TYPE_UNDO_CHANGE, action.getType());
    assertNotNull(meta.viewThisUndo());
    assertNotNull(meta.viewPreviousUndo());
    assertNotNull(meta.viewNextUndo());
    meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_DELETE, false);
    meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_POSITION, false);
    assertNotNull(meta.previousUndo());
    assertNotNull(meta.nextUndo());
    meta.setMaxUndo(1);
    assertEquals(1, meta.getUndoSize());
    meta.addUndo(from, to, pos, prev, curr, AbstractMeta.TYPE_UNDO_NEW, false);
}
Also used : TransAction(org.pentaho.di.core.undo.TransAction) Matchers.anyObject(org.mockito.Matchers.anyObject) Point(org.pentaho.di.core.gui.Point) StepMeta(org.pentaho.di.trans.step.StepMeta) 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