Search in sources :

Example 11 with StandaloneSpringPentahoObjectFactory

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

the class StandaloneSpringPentahoObjectFactoryTest method testInitFromObject.

public void testInitFromObject() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    File f = new File("src/test/resources/solution/system/pentahoObjects.spring.xml");
    FileSystemResource fsr = new FileSystemResource(f);
    GenericApplicationContext appCtx = new GenericApplicationContext();
    appCtx.refresh();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
    xmlReader.loadBeanDefinitions(fsr);
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", appCtx);
    GoodObject obj = factory.get(GoodObject.class, session);
    assertNotNull(obj);
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) FileSystemResource(org.springframework.core.io.FileSystemResource) File(java.io.File) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 12 with StandaloneSpringPentahoObjectFactory

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

the class StandaloneSpringPentahoObjectFactoryTest method testReferenceList.

public void testReferenceList() throws Exception {
    PentahoSystem.shutdown();
    StandaloneSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    MimeListenerCollection collection = PentahoSystem.get(MimeListenerCollection.class, session);
    assertNotNull(collection);
    assertEquals(5, collection.getListeners().size());
    // Highest priorty first?
    assertEquals("Higher Priority MimeTypeListener", collection.getListeners().get(0).name);
    // Queried list has only one match
    assertEquals(1, collection.getQueriedList().size());
    // queried list returned correct impl #3
    assertEquals("Test Attr3", collection.getQueriedList().get(0).name);
    // Check the bean that was injected is the highest priority one available.
    assertEquals("Higher Priority MimeTypeListener", collection.getHighestListener().name);
    // Check that the bean injected is based on the query for #2
    assertEquals("Test Attr2", collection.getQueriedBean().name);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 13 with StandaloneSpringPentahoObjectFactory

use of org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory 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)

Example 14 with StandaloneSpringPentahoObjectFactory

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

the class AggregateObjectFactoryTest method testCombined.

@Test
public void testCombined() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/solution/system/pentahoObjects.spring.xml");
    factory.init(null, context);
    StandaloneSpringPentahoObjectFactory factory2 = new StandaloneSpringPentahoObjectFactory();
    factory2.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    StandaloneObjectFactory factory3 = new StandaloneObjectFactory();
    factory3.init(null, null);
    factory3.defineObject("MimeTypeListener", MimeTypeListener.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    AggregateObjectFactory aggFactory = (AggregateObjectFactory) PentahoSystem.getObjectFactory();
    aggFactory.registerObjectFactory(factory3);
    List<MimeTypeListener> mimes = aggFactory.getAll(MimeTypeListener.class, session);
    assertEquals(6, mimes.size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory) Test(org.junit.Test)

Example 15 with StandaloneSpringPentahoObjectFactory

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

the class AggregateObjectFactoryTest method testRegistration.

/**
 * Two Spring PentahoObjectFactories with the same underlying applicationContext should not be registered twice. This
 * case tests that the AggregateObjectFactory's set implementation is working properly.
 *
 * @throws Exception
 */
@Test
public void testRegistration() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/solution/system/pentahoObjects.spring.xml");
    factory.init(null, context);
    StandaloneSpringPentahoObjectFactory factory2 = new StandaloneSpringPentahoObjectFactory();
    factory2.init(null, context);
    AggregateObjectFactory aggFactory = (AggregateObjectFactory) PentahoSystem.getObjectFactory();
    aggFactory.registerObjectFactory(factory);
    aggFactory.registerObjectFactory(factory2);
    List<MimeTypeListener> mimes = aggFactory.getAll(MimeTypeListener.class, session);
    assertEquals(5, mimes.size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IMimeTypeListener(org.pentaho.platform.api.engine.IMimeTypeListener) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory) Test(org.junit.Test)

Aggregations

StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)35 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)21 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)10 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)9 Test (org.junit.Test)8 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)8 PathBasedSystemSettings (org.pentaho.platform.engine.core.system.PathBasedSystemSettings)7 File (java.io.File)5 IMimeTypeListener (org.pentaho.platform.api.engine.IMimeTypeListener)5 AggregateObjectFactory (org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory)5 HashMap (java.util.HashMap)3 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)3 XmlBeanDefinitionReader (org.springframework.beans.factory.xml.XmlBeanDefinitionReader)3 ApplicationContext (org.springframework.context.ApplicationContext)3 ConfigurableApplicationContext (org.springframework.context.ConfigurableApplicationContext)3 FileSystemXmlApplicationContext (org.springframework.context.support.FileSystemXmlApplicationContext)3 BeforeClass (org.junit.BeforeClass)2 IPentahoObjectRegistration (org.pentaho.platform.api.engine.IPentahoObjectRegistration)2 IPlatformPlugin (org.pentaho.platform.api.engine.IPlatformPlugin)2 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)2