Package org.pentaho.platform.api.engine

Examples of org.pentaho.platform.api.engine.IRuntimeContext


    if ( xactionResultsOutputStream instanceof RepositoryFileOutputStream ) {
      outputHandler = new RepositoryFileOutputHandler( ( (RepositoryFileOutputStream) xactionResultsOutputStream ) );
    } else {
      outputHandler = new SimpleOutputHandler( xactionResultsOutputStream, false );
    }
    IRuntimeContext rt = null;
    try {
      ISolutionEngine solutionEngine = PentahoSystem.get( ISolutionEngine.class, null );
      solutionEngine.setCreateFeedbackParameterCallback( null );
      solutionEngine.setLoggingLevel( ILogger.DEBUG );
      solutionEngine.setForcePrompt( false );

      ArrayList messages = new ArrayList();

      HashMap<String, Object> parameterProviders = new HashMap<String, Object>();
      parameterProviders.put( IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider( xActionInputParams ) );
      parameterProviders.put( IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(
          PentahoSessionHolder.getSession() ) );
      String xactionPath = null;
      if ( xactionDefInputStream instanceof RepositoryFileInputStream ) {
        xactionPath = ( (RepositoryFileInputStream) xactionDefInputStream ).getFile().getPath();
      }
      rt =
          solutionEngine.execute( xactionPath, this.getClass().getName(), false, true, null, true, parameterProviders,
            outputHandler, null, null, messages );

      if ( !outputHandler.contentDone() ) {
        if ( ( rt != null ) && ( rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS ) ) {
          boolean isFlushed = false;
          boolean isEmpty;
          if ( xactionResultsOutputStream instanceof RepositoryFileOutputStream ) {
            RepositoryFileOutputStream repositoryFileOutputStream =
                (RepositoryFileOutputStream) xactionResultsOutputStream;
            isFlushed = repositoryFileOutputStream.isFlushed();
            isEmpty = repositoryFileOutputStream.size() > 0 ? false : true;
            String extension = RepositoryFilenameUtils.getExtension( repositoryFileOutputStream.getFilePath() );
            String mimeTypeFromExtension = MimeHelper.getMimeTypeFromExtension( "." + extension );
            if ( mimeTypeFromExtension == null ) {
              // unknown type, treat it not as an extension but part of the name
              extension = "";
            }
            if ( extension.isEmpty()
                && xactionResultsOutputStream.toString().isEmpty() ) {
              repositoryFileOutputStream.setFilePath( repositoryFileOutputStream.getFilePath() + ".html" );
            }
          } else {
            isEmpty = xactionResultsOutputStream.toString().isEmpty();
          }

          if ( !isFlushed ) {
            if ( isEmpty ) {
              StringBuffer buffer = new StringBuffer();
              PentahoSystem.get( IMessageFormatter.class, null ).formatSuccessMessage( "text/html", rt, buffer, false ); //$NON-NLS-1$
              xactionResultsOutputStream.write( buffer.toString().getBytes( LocaleHelper.getSystemEncoding() ) );
            }
            xactionResultsOutputStream.close();
          }
        } else {
          // we need an error message...
          StringBuffer buffer = new StringBuffer();
          PentahoSystem.get( IMessageFormatter.class, null ).formatFailureMessage( "text/html", rt, buffer, messages ); //$NON-NLS-1$
          xactionResultsOutputStream.write( buffer.toString().getBytes( LocaleHelper.getSystemEncoding() ) );
          xactionResultsOutputStream.close();
        }
      }
    } finally {
      if ( rt != null ) {
        rt.dispose();
      }
    }
  }
View Full Code Here


  public void testSuccessPaths() {
    startTest();
    String testName = CO_TEST_NAME + "string_" + System.currentTimeMillis(); //$NON-NLS-1$
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    IRuntimeContext context =
        run( "/test/platform/ContentOutputTest.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$

    IActionParameter rtn = context.getOutputParameter( "content" ); //$NON-NLS-1$
    assertNotNull( rtn );
    InputStream is = this.getInputStreamFromOutput( testName, CO_TEST_EXTN );
    assertNotNull( is ); // Did the test execute properly...
    String lookingFor = "This is sample output from the content-output component."; //$NON-NLS-1$
    String wasRead = FileHelper.getStringFromInputStream( is );
    assertTrue( wasRead.startsWith( lookingFor ) );

    // Test different path - Byte Array Output Stream
    lookingFor = "This is as sample bytearray output stream"; //$NON-NLS-1$
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      baos.write( lookingFor.getBytes() );
    } catch ( Exception ex ) {
      fail();
    }
    testName = CO_TEST_NAME + "ByteArrayOutputStream_" + System.currentTimeMillis(); //$NON-NLS-1$
    parameterProvider.setParameter( "CONTENTOUTPUT", baos ); //$NON-NLS-1$
    context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() );
    is = this.getInputStreamFromOutput( testName, CO_TEST_EXTN );
    assertNotNull( is ); // Did the test execute properly...
    wasRead = FileHelper.getStringFromInputStream( is );
    FileHelper.getStringFromFile( new File( PentahoSystem.getApplicationContext().getSolutionPath(
        "test/datasource/books.xml" ) ) ); //$NON-NLS-1$
    try {
      FileHelper.getBytesFromFile( new File( PentahoSystem.getApplicationContext().getSolutionPath(
          "test/datasource/books.xml" ) ) ); //$NON-NLS-1$
    } catch ( IOException io ) {
      // do nothing
    }
    File f = null;
    FileHelper.getStringFromFile( f );
    assertTrue( wasRead.startsWith( lookingFor ) );

    // Test different path - InputStream
    testName = CO_TEST_NAME + "ByteArrayInputStream_" + System.currentTimeMillis(); //$NON-NLS-1$
    lookingFor = "This is as a simple bytearray input stream"; //$NON-NLS-1$
    ByteArrayInputStream bais = new ByteArrayInputStream( lookingFor.getBytes() );
    parameterProvider.setParameter( "CONTENTOUTPUT", bais ); //$NON-NLS-1$
    context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() );
    is = this.getInputStreamFromOutput( testName, CO_TEST_EXTN );
    assertNotNull( is ); // Did the test execute properly...
    String newText = FileHelper.getStringFromInputStream( is );
    System.out.println( "Read Text from the input stream" + newText ); //$NON-NLS-1$
    String newTextFromIS = FileHelper.getStringFromInputStream( is );
View Full Code Here

    String neverWritten = "This data cannot be written"; //$NON-NLS-1$
    String testName = CO_TEST_NAME + "BAD_OUTPUTSTREAM_" + System.currentTimeMillis(); //$NON-NLS-1$
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    parameterProvider.setParameter( "CONTENTOUTPUT", neverWritten );
    //$NON-NLS-1$
    IRuntimeContext context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus() ); //$NON-NLS-1$

    // Another test with a bad output stream...
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    try {
      baos.write( neverWritten.getBytes() );
    }
    catch (Exception ex) { fail(); }
    parameterProvider.setParameter( "CONTENTOUTPUT", baos ); //$NON-NLS-1$
    context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus() );

    // Final test with a bad output stream...
    parameterProvider.setParameter( "CONTENTOUTPUT", new ByteArrayInputStream( neverWritten.getBytes() ) ); //$NON-NLS-1$
    context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus() );

    // Tests with bad action sequences
    context = run( "/test/platform/ContentOutputTest_error1.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, context.getStatus() );

    parameterProvider = new SimpleParameterProvider(); // Empty Parameter Provider
    context = run( "/test/platform/ContentOutputTest_error2.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, context.getStatus() );

    // Test with an invalid input parameter
    parameterProvider.setParameter("CONTENTOUTPUT", neverWritten.getBytes()); //$NON-NLS-1$
    context = run( "/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus() );

    finishTest();
  }
View Full Code Here

    startTest();

    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    parameterProvider.setParameter( "customer", "Acme" ); //$NON-NLS-1$ //$NON-NLS-2$

    IRuntimeContext context = run( "/test/rules/script_rule1.xaction", parameterProvider ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$

    assertNotNull(
        Messages.getInstance().getString( "RulesTest.ERROR_0001_NULL_RESULT" ), context.getOutputParameter( "rule-result" ) ); //$NON-NLS-1$ //$NON-NLS-2$
    assertEquals(
        Messages.getInstance().getString( "RulesTest.ERROR_0002_WRONG_RESULT" ), "Central", context.getOutputParameter( "rule-result" ).getStringValue() ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    info( Messages.getInstance().getString(
        "RulesTest.DEBUG_0003_SCRIPT_RULE_SUCCESS", context.getOutputParameter( "rule-result" ).getStringValue() ) ); //$NON-NLS-1$ //$NON-NLS-2$
    finishTest();
  }
View Full Code Here

  }

  public void testScriptRuleError1() {
    startTest();
    info( Messages.getInstance().getString( "RulesTest.USER_ERRORS_EXPECTED_SCRIPT_NOT_DEFINED" ) ); //$NON-NLS-1$
    IRuntimeContext context = run( "/test/rules/script_rule_error1.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, context.getStatus() ); //$NON-NLS-1$

    assertNotNull(
        Messages.getInstance().getString( "RulesTest.ERROR_0004_NULL_OUTPUT_OBJECT" ), context.getOutputParameter( "rule-result" ) ); //$NON-NLS-1$//$NON-NLS-2$
    assertEquals(
        Messages.getInstance().getString( "RulesTest.ERROR_0005_RESULT_WHEN_NULL_EXPECTED" ), null, context.getOutputParameter( "rule-result" ).getStringValue() ); //$NON-NLS-1$//$NON-NLS-2$
    finishTest();
  }
View Full Code Here

  }

  public void testScriptRuleError2() {
    startTest();
    info( Messages.getInstance().getString( "RulesTest.USER_ERRORS_EXPECTED_OUTPUT_NOT_DEFINED" ) ); //$NON-NLS-1$
    IRuntimeContext context = run( "/test/rules/script_rule_error2.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL, context.getStatus() ); //$NON-NLS-1$

    assertEquals(
        Messages.getInstance().getString( "RulesTest.ERROR_0006_RESULT_WHEN_ERROR_EXPECTED" ), false, context.getOutputNames().contains( "rule-result" ) ); //$NON-NLS-1$//$NON-NLS-2$
    finishTest();
  }
View Full Code Here

  }

  public void testScriptRuleError3() {
    startTest();
    info( Messages.getInstance().getString( "RulesTest.USER_ERRORS_EXPECTED_SCRIPT_INVALID" ) ); //$NON-NLS-1$
    IRuntimeContext context = run( "/test/rules/script_rule_error3.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus() ); //$NON-NLS-1$

    assertEquals(
        Messages.getInstance().getString( "RulesTest.ERROR_0005_RESULT_WHEN_NULL_EXPECTED" ), null, context.getOutputParameter( "rule-result" ).getStringValue() ); //$NON-NLS-1$//$NON-NLS-2$
    finishTest();
  }
View Full Code Here

  public void testScriptRuleError4() {
    startTest();

    info( "This should generate errors because the input to the script has a minus sign in the input name." ); //$NON-NLS-1$
    IRuntimeContext context = run( "/test/rules/script_rule_error4.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_FAILURE, context.getStatus() ); //$NON-NLS-1$
    assertEquals(
        Messages.getInstance().getString( "RulesTest.ERROR_0005_RESULT_WHEN_NULL_EXPECTED" ), null, context.getOutputParameter( "rule-result" ).getStringValue() ); //$NON-NLS-1$//$NON-NLS-2$
    finishTest();
  }
View Full Code Here

  }

  public void testScriptCompoundResult() {
    startTest();
    info( Messages.getInstance().getString( "RulesTest.USER_ERRORS_EXPECTED_SCRIPT_INVALID" ) ); //$NON-NLS-1$
    IRuntimeContext context = run( "/test/rules/script_rule3.xaction" ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$

    assertNotNull( context.getOutputParameter( "fruit" ) ); //$NON-NLS-1$
    assertNotNull( context.getOutputParameter( "veg" ) ); //$NON-NLS-1$
    assertEquals( "bad", "apples", context.getOutputParameter( "fruit" ).getStringValue() ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    assertEquals( "bad", "carrots", context.getOutputParameter( "veg" ).getStringValue() ); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
    finishTest();
  }
View Full Code Here

    ISolutionEngine solutionEngine = PentahoSystem.get( ISolutionEngine.class, session );
    solutionEngine.setLoggingLevel( getLoggingLevel() );
    solutionEngine.init( session );
    solutionEngine.setForcePrompt( true );
    IRuntimeContext context =
        run( solutionEngine,
            "/test/reporting/jfreereport-reports-test-param.xaction", null, false, parameterProvider, outputHandler ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(
        Messages.getInstance().getString( "BaseTest.USER_RUNNING_ACTION_SEQUENCE" ), IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus() ); //$NON-NLS-1$

    finishTest();
  }
View Full Code Here

TOP

Related Classes of org.pentaho.platform.api.engine.IRuntimeContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.