Search in sources :

Example 16 with StandaloneSpringPentahoObjectFactory

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

the class AggregateObjectFactoryTest method testRegisteredButNotPublishingAnythingApplicationContext.

/**
 * 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 testRegisteredButNotPublishingAnythingApplicationContext() throws Exception {
    PublishedBeanRegistry.reset();
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    ConfigurableApplicationContext context = new FileSystemXmlApplicationContext("src/test/resources/solution/system/registeredButNotPublishing.spring.xml");
    // this was causing an exception.
    factory.init(null, context);
    AggregateObjectFactory aggFactory = (AggregateObjectFactory) PentahoSystem.getObjectFactory();
    aggFactory.registerObjectFactory(factory);
    assertEquals(0, PublishedBeanRegistry.getRegisteredFactories().size());
}
Also used : ConfigurableApplicationContext(org.springframework.context.ConfigurableApplicationContext) FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory) Test(org.junit.Test)

Example 17 with StandaloneSpringPentahoObjectFactory

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

the class MimeTypeListFactoryIT method testGetMimeTypeList.

@Test
public void testGetMimeTypeList() throws Exception {
    MicroPlatform microPlatform = new MicroPlatform();
    StandaloneSpringPentahoObjectFactory objectFactory = new StandaloneSpringPentahoObjectFactory();
    objectFactory.init(TestResourceLocation.TEST_RESOURCES + "/MimeTypeFactoryTest/MimeTypeFactoryTest.spring.xml", null);
    PentahoSystem.registerObjectFactory(objectFactory);
    MimeTypeListFactory factory = new MimeTypeListFactory(TestResourceLocation.TEST_RESOURCES + "/MimeTypeFactoryTest/ImportHandlerMimeTypeDefinitions.xml");
    List<IMimeType> list1 = factory.createMimeTypeList("org.pentaho.platform.plugin.services.importer.RepositoryFileImportFileHandler");
    assertNotNull(list1);
    list1 = factory.createMimeTypeList("this.one.is.not.present");
    assertNotNull(list1);
    assertEquals(0, list1.size());
    list1 = factory.createMimeTypeList("org.pentaho.platform.plugin.services.importer.SolutionImportHandler");
    assertNotNull(list1);
    assertTrue(list1.size() > 0);
    list1 = factory.createMimeTypeList("com.pentaho.repository.importexport.PDIImportFileHandler");
    assertNotNull(list1);
    assert (list1.contains(new MimeType("application/vnd.pentaho.job", "ktr")));
}
Also used : IMimeType(org.pentaho.platform.api.mimetype.IMimeType) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) MimeType(org.pentaho.platform.core.mimetype.MimeType) IMimeType(org.pentaho.platform.api.mimetype.IMimeType) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) Test(org.junit.Test)

Example 18 with StandaloneSpringPentahoObjectFactory

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

the class BaseTest method setUp.

@Override
public void setUp() {
    // used by test repository impl such as FileSystemRepositoryFileDao
    System.setProperty("solution.root.dir", getSolutionPath());
    messages = TestManager.getMessagesList();
    if (messages == null) {
        messages = new ArrayList<String>();
    }
    if (initOk) {
        return;
    }
    PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
    if (PentahoSystem.getApplicationContext() == null) {
        // $NON-NLS-1$
        StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(getSolutionPath(), "");
        // set the base url assuming there is a running server on port 8080
        applicationContext.setFullyQualifiedServerURL(getFullyQualifiedServerURL());
        // $NON-NLS-1$ //$NON-NLS-2$
        String inContainer = System.getProperty("incontainer", "false");
        if (inContainer.equalsIgnoreCase("false")) {
            // $NON-NLS-1$
            // Setup simple-jndi for datasources
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("org.osjava.sj.root", getSolutionPath() + "/system/simple-jndi");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("org.osjava.sj.delimiter", "/");
        }
        ApplicationContext springApplicationContext = getSpringApplicationContext();
        IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
        pentahoObjectFactory.init(null, springApplicationContext);
        PentahoSystem.registerObjectFactory(pentahoObjectFactory);
        // force Spring to inject PentahoSystem, there has got to be a better way than this, perhaps an alternate way
        // of
        // initting spring's app context
        // $NON-NLS-1$
        springApplicationContext.getBean("pentahoSystemProxy");
        // Initialize SecurityHelper with a mock for testing
        SecurityHelper.setMockInstance(new MockSecurityHelper());
        initOk = PentahoSystem.init(applicationContext);
    } else {
        initOk = true;
    }
    // $NON-NLS-1$
    assertTrue(Messages.getInstance().getString("BaseTest.ERROR_0001_FAILED_INITIALIZATION"), initOk);
}
Also used : MockSecurityHelper(org.pentaho.test.platform.engine.security.MockSecurityHelper) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 19 with StandaloneSpringPentahoObjectFactory

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

the class DataSourcePublishIT method setUpClass.

@BeforeClass
public static void setUpClass() throws Exception {
    // folder cannot be deleted at teardown shutdown hooks have not yet necessarily completed
    // parent folder must match jcrRepository.homeDir bean property in repository-test-override.spring.xml
    FileUtils.deleteDirectory(new File("/tmp/repository-future/jackrabbit-test-TRUNK"));
    PentahoSessionHolder.setStrategyName(PentahoSessionHolder.MODE_GLOBAL);
    // register repository spring context for correct work of <pen:list>
    final StandaloneSpringPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
    GenericApplicationContext appCtx = new GenericApplicationContext();
    XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx);
    xmlReader.loadBeanDefinitions("classpath:/repository.spring.xml");
    xmlReader.loadBeanDefinitions("classpath:/solutionACL/system/repository-test-override.spring.xml");
    xmlReader.loadBeanDefinitions("classpath:/solutionACL/system/importExport.xml");
    xmlReader.loadBeanDefinitions("classpath:/solutionACL/system/pentahoObjects.spring.xml");
    xmlReader.loadBeanDefinitions("classpath:/jackrabbit-test-repo.xml");
    pentahoObjectFactory.init(null, appCtx);
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
    FileUtils.deleteDirectory(new File("/tmp/data-access/jackrabbit-test-TRUNK"));
}
Also used : GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) XmlBeanDefinitionReader(org.springframework.beans.factory.xml.XmlBeanDefinitionReader) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) BeforeClass(org.junit.BeforeClass)

Example 20 with StandaloneSpringPentahoObjectFactory

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

the class SystemResourceIT method setUp.

@Before
public void setUp() throws Exception {
    mp = new MicroPlatform();
    mp.defineInstance(IAuthorizationPolicy.class, new TestAuthorizationPolicy());
    mp.start();
    ISystemConfig systemConfig = new SystemConfig();
    IConfiguration securityConfig = mock(IConfiguration.class);
    Properties props = new Properties();
    props.setProperty("provider", "jackrabbit");
    when(securityConfig.getProperties()).thenReturn(props);
    when(securityConfig.getId()).thenReturn("security");
    systemConfig.registerConfiguration(securityConfig);
    systemResource = new SystemResource(systemConfig);
    // $NON-NLS-1$
    StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(getSolutionPath(), "");
    ApplicationContext springApplicationContext = getSpringApplicationContext();
    IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
    pentahoObjectFactory.init(null, springApplicationContext);
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
    // force Spring to populate PentahoSystem
    boolean initOk = PentahoSystem.init(applicationContext);
/*
     * StandaloneSession session = new StandaloneSession();
     * 
     * StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory( );
     * 
     * File f = new File(TestResourceLocation.TEST_RESOURCES + "/solution/system/pentahoObjects.spring.xml"); FileSystemResource fsr = new
     * FileSystemResource(f); GenericApplicationContext appCtx = new GenericApplicationContext();
     * XmlBeanDefinitionReader xmlReader = new XmlBeanDefinitionReader(appCtx); xmlReader.loadBeanDefinitions(fsr);
     * 
     * factory.init(TestResourceLocation.TEST_RESOURCES + "/solution/system/pentahoObjects.spring.xml", appCtx );
     */
}
Also used : ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) SystemConfig(org.pentaho.platform.config.SystemConfig) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) MicroPlatform(org.pentaho.test.platform.engine.core.MicroPlatform) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) FileSystemResource(org.springframework.core.io.FileSystemResource) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Properties(java.util.Properties) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory) Before(org.junit.Before)

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