Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

  • We are providing a relative dir to the MicroPlatform called "solutions". This folder must exist at the root of your project.
    Code Block
    public class EchoActionTest {
      
      private MicroPlatform booter;
    
      StandaloneSession session;
    
      @Before
      public void init() {
        booter = new MicroPlatform("solutions");
        booter.define(ISolutionEngine.class, SolutionEngine.class, Scope.GLOBAL);
        booter.define(ISolutionRepository.class, FileBasedSolutionRepository.class, Scope.GLOBAL);
        booter.define(IServiceManager.class, DefaultServiceManager.class, Scope.GLOBAL);
        booter.define(IPluginManager.class, DefaultPluginManager.class, Scope.GLOBAL);
        booter.define("systemStartupSession", StandaloneSession.class, Scope.GLOBAL);
    
        session = new StandaloneSession();
      }
      
      @Test
      public void testEchoActionExecute() throws PlatformInitializationException, FileNotFoundException {
        booter.define(IPluginProvider.class, TestPluginProvider.class);
        booter.addLifecycleListener(new PluginAdapter());
        booter.start();
        
        OutputStream outputStream = new FileOutputStream(new File("testEchoActionExecute.html"));
        ISolutionEngine engine = SolutionHelper.execute("testing EchoAction", "testuser", "bi-developers/EchoPlugin/echoAction.xaction", new HashMap(), outputStream);
        // TODO: add a convenience method in SolutionHelper to access the messages object
      }
      
      public static class TestPluginProvider implements IPluginProvider {
        public List<IPlatformPlugin> getPlugins(IPentahoSession session) throws PlatformPluginRegistrationException {
          PlatformPlugin p = new PlatformPlugin();
          //need to set source description - classloader needs it
          p.setId("test-echoAction-plugin");
          p.addBean(new PluginBeanDefinition("EchoAction", "org.pentaho.samples.EchoAction"));
          return Arrays.asList((IPlatformPlugin) p);
        }
      }
    
    }
    

Run a chartbeans actions sequence

A couple gotchas found when running chartbeans action sequences in embedded mode:

  • There was enough file-based config required that I decided just to reference a full sample solution as my solutions folder, even though lots of it is not required, e.g. Spring config.
  • In trying to run chartbeans samples I got chartbeans output which I belieive is valid, written to a file which I then load in FF, but flash is deciding to not render the chart. I tried changing the allowScriptAccess to be "always", but that still didn't help.
Code Block

/**
 * INSTRUCTIONS:
 * <ol>
 * <li> point SOLUTION_PATH to the bi-platform-sample-solution project (or other solutions folder)
 *    Note: not all system files in the solution are really needed.  In fact, you may remove any spring config files
 *    and expect everything to work just fine.
 * <li> comment out the PentahoUser.hbm.xml and PentahoRole.hbm.xml mapping file entries in <dialect>.hibernate.cfg.xml
 *    These are supplied by the user console and will not be used in this embedded appliction.
 * <li> set XACTION to the relative path to the xaction file you wish to run (relative to SOLUTION_PATH)
 * </ol>
 */
public class ActionSequenceRunnerTest {
  public static final String XACTION = "bi-developers/chartbeans/chartbeans_simple_bar.xaction";
  public static final String SOLUTION_PATH = "/home/aaron/workspaces/pentaho/bi-platform-sample-solution";
  
  private MicroPlatform booter;

  StandaloneSession session;

  @Before
  public void init() {
    booter = new MicroPlatform(SOLUTION_PATH);
    booter.define(ISolutionEngine.class, SolutionEngine.class, Scope.LOCAL);
    booter.define(ISolutionRepository.class, FileBasedSolutionRepository.class, Scope.GLOBAL);
    booter.define(IServiceManager.class, DefaultServiceManager.class, Scope.GLOBAL);
    booter.define(IPluginManager.class, DefaultPluginManager.class, Scope.GLOBAL);
    booter.define("systemStartupSession", StandaloneSession.class, Scope.GLOBAL);
    booter.define( "connection-XML", XQConnection.class, Scope.LOCAL );
    booter.define( "connection-SQL", SQLConnection.class, Scope.LOCAL );
    booter.define( "file", FileOutputHandler.class, Scope.LOCAL );
    
    booter.define(IChartBeansGenerator.class, DefaultChartBeansGenerator.class, Scope.GLOBAL);
    
    //db & repository stuff
    booter.define(IVersionHelper.class, VersionHelper.class, Scope.GLOBAL);
    booter.define(IDatasourceService.class, NonPooledDatasourceService.class, Scope.GLOBAL);
    booter.define(IDatasourceMgmtService.class, DatasourceMgmtService.class, Scope.LOCAL);
    booter.define(IDatasource.class, Datasource.class, Scope.LOCAL);
    booter.define(IPasswordService.class, Base64PasswordService.class, Scope.GLOBAL);
    
    booter.setSettingsProvider(new PathBasedSystemSettings());

    session = new StandaloneSession();
  }
  
  @Test
  public void executeActionSequence() throws PlatformInitializationException, FileNotFoundException {
    booter.start();
    
    OutputStream outputStream = new FileOutputStream(new File("actionSequenceOutput.html"));
    ISolutionEngine engine = SolutionHelper.execute("testing ChartBeans component", "testuser", XACTION, new HashMap(), outputStream);
  }
}