Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Next »

This page will be a work in progress for now. The intent is to show how you can quickly embed a BI Platform in a JUnit test without extending any classes, such as BaseTest. The ability to startup a BI Platform in embedded mode gives you much more control in how your unit test will perform, not to mention it makes maintaining your unit test much easier since you have virtually no configuration files to maintain along with the test.

PentahoBoot and PentahoSystemBoot

TODO put a brief overview here of how to use these classes to configure and initialize an embedded Pentaho BI platform

Various example configurations (shown using JUnit)

Run a minimal action sequence

This configuration will setup everything necessary to run a very simplistic action sequence which accesses no data, but rather runs with hardcoded values provided within the action sequence itself.

A few things to note:

  • We are providing a relative dir to the MicroPlatform called "solutions". This folder must exist at the root of your project.
    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);
        }
      }
    
    }
    
  • No labels