Search in sources :

Example 16 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class StartPipelineServletTest method testStartPipelineServletEscapesHtmlWhenPipelineFound.

@Test
@PrepareForTest({ Encode.class })
public void testStartPipelineServletEscapesHtmlWhenPipelineFound() throws ServletException, IOException {
    HopLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    Pipeline mockPipeline = mock(Pipeline.class);
    PipelineMeta mockPipelineMeta = mock(PipelineMeta.class);
    ILogChannel mockChannelInterface = mock(ILogChannel.class);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StartPipelineServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockPipelineMap.getPipeline(any(HopServerObjectEntry.class))).thenReturn(mockPipeline);
    when(mockPipeline.getLogChannel()).thenReturn(mockChannelInterface);
    when(mockPipeline.getLogChannelId()).thenReturn("test");
    when(mockPipeline.getPipelineMeta()).thenReturn(mockPipelineMeta);
    when(mockPipelineMeta.getMaximum()).thenReturn(new Point(10, 10));
    startPipelineServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(Encode.class);
    Encode.forHtml(anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) ILogChannel(org.apache.hop.core.logging.ILogChannel) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.apache.hop.core.gui.Point) Pipeline(org.apache.hop.pipeline.Pipeline) PipelineMeta(org.apache.hop.pipeline.PipelineMeta) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 17 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class StartWorkflowServletTest method testStartWorkflowServletEscapesHtmlWhenPipelineFound.

@Test
@PrepareForTest({ Encode.class })
public void testStartWorkflowServletEscapesHtmlWhenPipelineFound() throws ServletException, IOException {
    HopLogStore.init();
    HttpServletRequest mockHttpServletRequest = mock(HttpServletRequest.class);
    HttpServletResponse mockHttpServletResponse = mock(HttpServletResponse.class);
    IWorkflowEngine<WorkflowMeta> mockWorkflow = mock(Workflow.class);
    WorkflowMeta mockWorkflowMeta = mock(WorkflowMeta.class);
    ILogChannel mockLogChannelInterface = mock(ILogChannel.class);
    mockWorkflowMeta.setName(ServletTestUtils.BAD_STRING_TO_TEST);
    StringWriter out = new StringWriter();
    PrintWriter printWriter = new PrintWriter(out);
    PowerMockito.spy(Encode.class);
    when(mockHttpServletRequest.getContextPath()).thenReturn(StartWorkflowServlet.CONTEXT_PATH);
    when(mockHttpServletRequest.getParameter(anyString())).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    when(mockHttpServletResponse.getWriter()).thenReturn(printWriter);
    when(mockWorkflowMap.getWorkflow(any(HopServerObjectEntry.class))).thenReturn(mockWorkflow);
    when(mockWorkflow.getLogChannelId()).thenReturn(ServletTestUtils.BAD_STRING_TO_TEST);
    when(mockWorkflow.getLogChannel()).thenReturn(mockLogChannelInterface);
    when(mockWorkflow.getWorkflowMeta()).thenReturn(mockWorkflowMeta);
    when(mockWorkflowMeta.getMaximum()).thenReturn(new Point(10, 10));
    startJobServlet.doGet(mockHttpServletRequest, mockHttpServletResponse);
    assertFalse(ServletTestUtils.hasBadText(ServletTestUtils.getInsideOfTag("H1", out.toString())));
    PowerMockito.verifyStatic(Encode.class);
    Encode.forHtml(anyString());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) StringWriter(java.io.StringWriter) ILogChannel(org.apache.hop.core.logging.ILogChannel) HttpServletResponse(javax.servlet.http.HttpServletResponse) Point(org.apache.hop.core.gui.Point) WorkflowMeta(org.apache.hop.workflow.WorkflowMeta) PrintWriter(java.io.PrintWriter) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 18 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class HopPipelineMetaToBeamPipelineConverter method createPipeline.

public Pipeline createPipeline() throws Exception {
    try {
        ILogChannel log = LogChannel.GENERAL;
        // Create a new Pipeline
        // 
        RunnerType runnerType = pipelineRunConfiguration.getRunnerType();
        Class<? extends PipelineRunner<?>> runnerClass = getPipelineRunnerClass(runnerType);
        PipelineOptions pipelineOptions = pipelineRunConfiguration.getPipelineOptions();
        // The generic options
        // 
        pipelineOptions.setUserAgent(variables.resolve(pipelineRunConfiguration.getUserAgent()));
        pipelineOptions.setTempLocation(variables.resolve(pipelineRunConfiguration.getTempLocation()));
        pipelineOptions.setJobName(sanitizeJobName(pipelineMeta.getName()));
        pipelineOptions.setRunner(runnerClass);
        Pipeline pipeline = Pipeline.create(pipelineOptions);
        pipeline.getCoderRegistry().registerCoderForClass(HopRow.class, new HopRowCoder());
        log.logBasic("Created Apache Beam pipeline with name '" + pipelineOptions.getJobName() + "'");
        // Keep track of which transform outputs which Collection
        // 
        Map<String, PCollection<HopRow>> transformCollectionMap = new HashMap<>();
        // Handle io
        // 
        handleBeamInputTransforms(log, transformCollectionMap, pipeline);
        // Transform all the other transforms...
        // 
        handleGenericTransform(transformCollectionMap, pipeline);
        // Output handling
        // 
        handleBeamOutputTransforms(log, transformCollectionMap, pipeline);
        return pipeline;
    } catch (Throwable e) {
        throw new Exception("Error converting Hop pipeline to Beam", e);
    }
}
Also used : PCollection(org.apache.beam.sdk.values.PCollection) ILogChannel(org.apache.hop.core.logging.ILogChannel) PipelineOptions(org.apache.beam.sdk.options.PipelineOptions) HopRowCoder(org.apache.hop.beam.core.coder.HopRowCoder) RunnerType(org.apache.hop.beam.metadata.RunnerType) HopException(org.apache.hop.core.exception.HopException) IOException(java.io.IOException) Pipeline(org.apache.beam.sdk.Pipeline)

Example 19 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class ExtensionPointHandlerTest method callExtensionPointTest.

@Test
public void callExtensionPointTest() throws Exception {
    IPluginMock pluginInterface = mock(IPluginMock.class);
    when(pluginInterface.getName()).thenReturn(TEST_NAME);
    when(pluginInterface.getMainType()).thenReturn((Class) IExtensionPoint.class);
    when(pluginInterface.getIds()).thenReturn(new String[] { "testID" });
    IExtensionPoint extensionPoint = mock(IExtensionPoint.class);
    when(pluginInterface.loadClass(IExtensionPoint.class)).thenReturn(extensionPoint);
    PluginRegistry.addPluginType(ExtensionPointPluginType.getInstance());
    PluginRegistry.getInstance().registerPlugin(ExtensionPointPluginType.class, pluginInterface);
    final ILogChannel log = mock(ILogChannel.class);
    ExtensionPointHandler.callExtensionPoint(log, null, "noPoint", null);
    verify(extensionPoint, never()).callExtensionPoint(any(ILogChannel.class), any(), any());
    ExtensionPointHandler.callExtensionPoint(log, null, TEST_NAME, null);
    verify(extensionPoint, times(1)).callExtensionPoint(eq(log), any(), isNull());
}
Also used : ILogChannel(org.apache.hop.core.logging.ILogChannel) Test(org.junit.Test)

Example 20 with ILogChannel

use of org.apache.hop.core.logging.ILogChannel in project hop by apache.

the class ExtensionPointIntegrationTest method test.

@Test
public void test() throws Exception {
    // check that all extension points are added to the map
    assertEquals(HopExtensionPoint.values().length, ExtensionPointMap.getInstance().getNumberOfRows());
    // check that all extension points are executed
    final ILogChannel log = mock(ILogChannel.class);
    for (HopExtensionPoint ep : HopExtensionPoint.values()) {
        final IExtensionPoint currentEP = ExtensionPointMap.getInstance().getTableValue(ep.id, "id" + ep.id);
        assertFalse(currentEP.getClass().getField(EXECUTED_FIELD_NAME).getBoolean(currentEP));
        ExtensionPointHandler.callExtensionPoint(log, null, ep.id, null);
        assertTrue(currentEP.getClass().getField(EXECUTED_FIELD_NAME).getBoolean(currentEP));
    }
    // check modification of extension point
    final HopExtensionPoint jobAfterOpen = HopExtensionPoint.WorkflowAfterOpen;
    final IExtensionPoint int1 = ExtensionPointMap.getInstance().getTableValue(jobAfterOpen.id, "id" + jobAfterOpen.id);
    ExtensionPointPluginType.getInstance().registerCustom(createClassRuntime(jobAfterOpen, "Edited"), "custom", "id" + jobAfterOpen.id, jobAfterOpen.id, "no description", null);
    assertNotSame(int1, ExtensionPointMap.getInstance().getTableValue(jobAfterOpen.id, "id" + jobAfterOpen.id));
    assertEquals(HopExtensionPoint.values().length, ExtensionPointMap.getInstance().getNumberOfRows());
    // check removal of extension point
    PluginRegistry.getInstance().removePlugin(ExtensionPointPluginType.class, PluginRegistry.getInstance().getPlugin(ExtensionPointPluginType.class, "id" + jobAfterOpen.id));
    assertTrue(ExtensionPointMap.getInstance().getTableValue(jobAfterOpen.id, "id" + jobAfterOpen.id) == null);
    assertEquals(HopExtensionPoint.values().length - 1, ExtensionPointMap.getInstance().getNumberOfRows());
}
Also used : ILogChannel(org.apache.hop.core.logging.ILogChannel) Test(org.junit.Test)

Aggregations

ILogChannel (org.apache.hop.core.logging.ILogChannel)47 HopException (org.apache.hop.core.exception.HopException)20 Test (org.junit.Test)19 Point (org.apache.hop.core.gui.Point)15 PipelineMeta (org.apache.hop.pipeline.PipelineMeta)14 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HttpServletResponse (javax.servlet.http.HttpServletResponse)13 PrintWriter (java.io.PrintWriter)12 StringWriter (java.io.StringWriter)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 WorkflowMeta (org.apache.hop.workflow.WorkflowMeta)10 IVariables (org.apache.hop.core.variables.IVariables)9 Pipeline (org.apache.hop.pipeline.Pipeline)9 ExtensionPoint (org.apache.hop.core.extension.ExtensionPoint)8 IExtensionPoint (org.apache.hop.core.extension.IExtensionPoint)7 SimpleDateFormat (java.text.SimpleDateFormat)6 Result (org.apache.hop.core.Result)6 NeoConnection (org.apache.hop.neo4j.shared.NeoConnection)6 Transaction (org.neo4j.driver.Transaction)6 Date (java.util.Date)4