Search in sources :

Example 6 with StandaloneApplicationContext

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

the class StandaloneSessionTest method testTempFileDeleter.

public void testTempFileDeleter() throws Exception {
    // get one with an id. //$NON-NLS-1$
    StandaloneSession session = new StandaloneSession("tempfiledeleter", UUIDUtil.getUUIDAsString());
    StandaloneTempFileDeleter deleter = new StandaloneTempFileDeleter();
    // $NON-NLS-1$ //$NON-NLS-2$
    StandaloneApplicationContext appContext = new StandaloneApplicationContext(getSolutionRoot(), "");
    // $NON-NLS-1$ //$NON-NLS-2$
    File file1 = appContext.createTempFile(session, "testTempFileDeleter", "txt", true);
    // File object was returned
    assertNotNull(file1);
    // File exists
    assertTrue(file1.exists());
    // Deleter wasn't bound to session, so no delete
    assertFalse(deleter.hasTempFile(file1.getName()));
    // Bind deleter to the session
    session.setAttribute(ITempFileDeleter.DELETER_SESSION_VARIABLE, deleter);
    // $NON-NLS-1$ //$NON-NLS-2$
    File file2 = appContext.createTempFile(session, "testTempFileDeleter", "txt", true);
    // File object was returned
    assertNotNull(file2);
    // File exists
    assertTrue(file2.exists());
    // Deleter is bound to session
    assertTrue(deleter.hasTempFile(file2.getName()));
    // File names should be unique
    assertFalse(file1.getName().equals(file2.getName()));
    deleter.doTempFileCleanup();
    // This file will be left over
    assertTrue(file1.exists());
    // The deleter should have removed this
    assertFalse(file2.exists());
    // After doTempFileCleanup() the list should be empty
    assertFalse(deleter.hasTempFile(file2.getName()));
    // The tearDown should blow away everything else...
    // Add known deleted file to the deleter
    deleter.trackTempFile(file2);
    // Validates cleanup doesn't choke on missing files
    deleter.doTempFileCleanup();
    // Test that IllegalArgumentException if passed a null
    try {
        deleter.trackTempFile(null);
        fail();
    } catch (IllegalArgumentException expected) {
    // ignored
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) StandaloneTempFileDeleter(org.pentaho.platform.engine.core.system.StandaloneTempFileDeleter) File(java.io.File)

Example 7 with StandaloneApplicationContext

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

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

the class SystemConfigIT method testSystemSettingsFromSpring.

@Test
public void testSystemSettingsFromSpring() throws Exception {
    PentahoSystem.clearObjectFactory();
    PentahoSystem.setApplicationContext(new StandaloneApplicationContext(TestResourceLocation.TEST_RESOURCES + "/SystemConfig", ""));
    FileSystemXmlApplicationContext context = new FileSystemXmlApplicationContext(TestResourceLocation.TEST_RESOURCES + "/SystemConfig/system/testPropertyPlaceholders-system-settings.spring.xml");
    context.refresh();
    assertNotNull(context.getBean("testPlaceHolder"));
    assertEquals("Hypersonic", context.getBean("testPlaceHolder"));
    assertNotNull(context.getBean("testPlaceHolder2"));
    assertEquals("A dog's tale", context.getBean("testPlaceHolder2"));
}
Also used : FileSystemXmlApplicationContext(org.springframework.context.support.FileSystemXmlApplicationContext) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) Test(org.junit.Test)

Example 9 with StandaloneApplicationContext

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

the class SystemConfigIT method testSystemSettingsConfiguration.

@Test
public void testSystemSettingsConfiguration() throws Exception {
    PentahoSystem.clearObjectFactory();
    PentahoSystem.setApplicationContext(new StandaloneApplicationContext(TestResourceLocation.TEST_RESOURCES + "/SystemConfig", ""));
    SystemSettingsConfiguration settings = new SystemSettingsConfiguration("system", new PathBasedSystemSettings());
    Properties props = settings.getProperties();
    assertNotNull(props);
    assertEquals("Hypersonic", props.get("sampledata-datasource.type"));
}
Also used : StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) Properties(java.util.Properties) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) Test(org.junit.Test)

Example 10 with StandaloneApplicationContext

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

the class RuntimeContextTest method before.

@Before
public void before() {
    mockedRuntimeRepository = mock(IRuntimeRepository.class);
    mockedSolutionEngine = mock(ISolutionEngine.class);
    mockedPentahoSystem = new MockUp<PentahoSystem>() {

        @Mock
        public <T> T get(Class<T> type, IPentahoSession session) {
            if (type == IRuntimeRepository.class) {
                return (T) mockedRuntimeRepository;
            } else if (type == ISolutionEngine.class) {
                return (T) mockedSolutionEngine;
            }
            throw new IllegalStateException("Unsupported type: " + type.getSimpleName());
        }

        @Mock
        public void setApplicationContext(final IApplicationContext applicationContext) {
        }

        @Mock
        public IApplicationContext getApplicationContext() {
            final String solutionPath = ".";
            final String applicationPath = "";
            return new StandaloneApplicationContext(solutionPath, applicationPath);
        }
    };
    runtimeCtx = new RuntimeContext("id", mockedSolutionEngine, "solutionName", makeRuntimeData(session), session, null, "processId", urlFactory, makeParameterProviders(session), new ArrayList<String>(), null);
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) Matchers.anyString(org.mockito.Matchers.anyString) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) PentahoSystem(org.pentaho.platform.engine.core.system.PentahoSystem) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Mock(mockit.Mock) IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Before(org.junit.Before)

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