Search in sources :

Example 1 with SessionStartupAction

use of org.pentaho.platform.engine.core.system.SessionStartupAction in project pentaho-platform by pentaho.

the class GlobalListPublisherTest method test1.

public void test1() throws ObjectFactoryException {
    StandaloneSession session = new StandaloneSession("test");
    StandaloneApplicationContext appContext = new StandaloneApplicationContext("src/test/resources/solution", "");
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.GlobalListPublisherTest.spring.xml", null);
    PentahoSystem.init(appContext);
    PentahoSystem.registerObjectFactory(factory);
    PentahoSystem.setSystemSettingsService(factory.get(ISystemSettings.class, "systemSettingsService", session));
    List<ISessionStartupAction> actions = new ArrayList<ISessionStartupAction>();
    SessionStartupAction startupAction1 = new SessionStartupAction();
    startupAction1.setSessionType(PentahoSystem.SCOPE_GLOBAL);
    startupAction1.setActionPath("testsolution/testpath/test.xaction");
    startupAction1.setActionOutputScope(PentahoSystem.SCOPE_GLOBAL);
    actions.add(startupAction1);
    TestRuntimeContext context = new TestRuntimeContext();
    context.status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
    TestSolutionEngine engine = PentahoSystem.get(TestSolutionEngine.class, "ISolutionEngine", session);
    engine.testRuntime = context;
    Map<String, IActionParameter> outputs = new HashMap<String, IActionParameter>();
    TestActionParameter param = new TestActionParameter();
    param.setValue("testvalue");
    outputs.put("testoutput", param);
    context.outputParameters = outputs;
    engine.executeCount = 0;
    GlobalListsPublisher globals = new GlobalListsPublisher();
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS"), globals.getName());
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_DESCRIPTION"), globals.getDescription());
    assertTrue(!globals.getName().startsWith("!"));
    assertTrue(!globals.getDescription().startsWith("!"));
    assertNotNull(globals.getLogger());
    String resultMsg = globals.publish(session);
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"), resultMsg);
    assertEquals(0, engine.executeCount);
    PentahoSystem.setSessionStartupActions(actions);
    IParameterProvider globalParams = PentahoSystem.getGlobalParameters();
    resultMsg = globals.publish(session);
    assertEquals(1, engine.executeCount);
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"), resultMsg);
    // check that we made it all the way to executing the startup action
    assertEquals(session, engine.initSession);
    assertEquals(startupAction1.getActionPath(), engine.actionPath);
    assertEquals("testvalue", globalParams.getParameter("testoutput"));
    param.setValue("testvalue2");
    resultMsg = globals.publish(session);
    assertEquals(Messages.getInstance().getString("GlobalListsPublisher.USER_SYSTEM_SETTINGS_UPDATED"), resultMsg);
    assertEquals(2, engine.executeCount);
    assertNotNull(globalParams);
    assertEquals("testvalue2", globalParams.getParameter("testoutput"));
    assertEquals(2, engine.executeCount);
}
Also used : ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) SessionStartupAction(org.pentaho.platform.engine.core.system.SessionStartupAction) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) GlobalListsPublisher(org.pentaho.platform.engine.core.system.GlobalListsPublisher) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Aggregations

ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)1 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)1 ISessionStartupAction (org.pentaho.platform.api.engine.ISessionStartupAction)1 ISystemSettings (org.pentaho.platform.api.engine.ISystemSettings)1 GlobalListsPublisher (org.pentaho.platform.engine.core.system.GlobalListsPublisher)1 SessionStartupAction (org.pentaho.platform.engine.core.system.SessionStartupAction)1 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)1