Search in sources :

Example 11 with StandaloneApplicationContext

use of org.pentaho.platform.engine.core.system.StandaloneApplicationContext 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 12 with StandaloneApplicationContext

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

the class RepositoryFactoryTest method setup.

@BeforeClass
public static void setup() throws Exception {
    PentahoSystem.init(new StandaloneApplicationContext("", ""));
    KettleEnvironment.init();
}
Also used : StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) BeforeClass(org.junit.BeforeClass)

Example 13 with StandaloneApplicationContext

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

the class KarafBootTest method testClearDataCacheSetting.

@Test
public void testClearDataCacheSetting() throws Exception {
    // clear Karaf's property to avoid tests' interdependency
    System.clearProperty("karaf.data");
    PentahoSystem.init(new StandaloneApplicationContext(TestResourceLocation.TEST_RESOURCES + "/karafBootTest", "."));
    // set property
    KarafBoot karafBoot = new KarafBoot();
    File root = Files.createTempDirectory(Paths.get("."), "root").toFile();
    File caches = new File(root, "caches");
    caches.mkdir();
    for (int i = 0; i < 5; i++) {
        File clientTypeFolder = new File(caches, "client" + i);
        clientTypeFolder.mkdir();
        for (int y = 0; y < 3; y++) {
            new File(clientTypeFolder, "data-" + y).mkdir();
        }
    }
    FileUtils.copyDirectory(new File(TestResourceLocation.TEST_RESOURCES + "/karafBootTest/system/karaf/etc"), new File(root, "etc"));
    FileOutputStream fileOutputStream = null;
    FileInputStream fileInputStream = null;
    try {
        Properties config = new Properties();
        File configFile = new File(root + "/etc/custom.properties");
        fileInputStream = new FileInputStream(configFile);
        config.load(fileInputStream);
        fileInputStream.close();
        config.setProperty("org.pentaho.clean.karaf.cache", "true");
        fileOutputStream = new FileOutputStream(configFile);
        config.store(fileOutputStream, "setting stage");
        karafBoot.cleanCachesIfFlagSet(root.getPath());
        // Check that all data directories are gone
        for (int i = 0; i < 5; i++) {
            File clientTypeFolder = new File(caches, "client" + i);
            File[] files = clientTypeFolder.listFiles();
            assertEquals(0, files.length);
        }
        fileInputStream = new FileInputStream(configFile);
        config.load(fileInputStream);
        assertEquals("false", config.getProperty("org.pentaho.clean.karaf.cache"));
    } finally {
        if (fileOutputStream != null) {
            fileOutputStream.close();
        }
        if (fileInputStream != null) {
            fileInputStream.close();
        }
    }
    if (root.exists()) {
        FileUtils.deleteDirectory(root);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) Properties(java.util.Properties) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 14 with StandaloneApplicationContext

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

Example 15 with StandaloneApplicationContext

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

the class ContentOutputComponentIT method setUp.

public void setUp() {
    super.setUp();
    // $NON-NLS-1$
    StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(getSolutionPath(), "");
    PentahoSystem.init(applicationContext, getRequiredListeners());
}
Also used : StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext)

Aggregations

StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)23 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)8 IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)7 PathBasedSystemSettings (org.pentaho.platform.engine.core.system.PathBasedSystemSettings)7 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)5 File (java.io.File)4 ApplicationContext (org.springframework.context.ApplicationContext)4 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)4 Properties (java.util.Properties)3 Before (org.junit.Before)3 Test (org.junit.Test)3 IApplicationContext (org.pentaho.platform.api.engine.IApplicationContext)3 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)3 ArrayList (java.util.ArrayList)2 Mock (mockit.Mock)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)2 IRuntimeRepository (org.pentaho.platform.api.repository.IRuntimeRepository)2 PentahoSystem (org.pentaho.platform.engine.core.system.PentahoSystem)2 FileInputStream (java.io.FileInputStream)1