Search in sources :

Example 81 with StandaloneSession

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

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

the class OSGIObjectFactoryTest method setup.

@Before
public void setup() {
    session = new StandaloneSession();
    mockContext = Mockito.mock(BundleContext.class);
    mockBundle = Mockito.mock(Bundle.class);
    when(mockBundle.getState()).thenReturn(Bundle.ACTIVE);
    when(mockContext.getBundle()).thenReturn(mockBundle);
    factory = new OSGIObjectFactory(mockContext);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Bundle(org.osgi.framework.Bundle) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 83 with StandaloneSession

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

the class RuntimeObjectFactoryTest method testGetObjectReferences.

@Test
public void testGetObjectReferences() throws Exception {
    IPentahoSession session = new StandaloneSession("joe");
    RuntimeObjectFactory factory = new RuntimeObjectFactory();
    final SingletonPentahoObjectReference<String> something1 = new SingletonPentahoObjectReference<String>(String.class, "Something1", Collections.<String, Object>emptyMap(), 0);
    final SingletonPentahoObjectReference<String> something2 = new SingletonPentahoObjectReference<String>(String.class, "Something2", Collections.<String, Object>emptyMap(), 1);
    factory.registerReference(something1);
    factory.registerReference(something2);
    List<String> out = factory.getAll(String.class, PentahoSessionHolder.getSession());
    assertEquals(2, out.size());
    List<IPentahoObjectReference<String>> refs = factory.getObjectReferences(String.class, session);
    assertSame(something1, refs.get(1));
    assertSame(something2, refs.get(0));
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) SingletonPentahoObjectReference(org.pentaho.platform.engine.core.system.objfac.references.SingletonPentahoObjectReference) Test(org.junit.Test)

Example 84 with StandaloneSession

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

the class PrototypePentahoObjectReferenceTest method testReference.

@Test
public void testReference() throws Exception {
    PrototypePentahoObjectReference<UUID> sessionRef = new PrototypePentahoObjectReference.Builder<UUID>(UUID.class).creator(new IObjectCreator<UUID>() {

        @Override
        public UUID create(IPentahoSession session) {
            return UUID.randomUUID();
        }
    }).build();
    IPentahoSession s1 = new StandaloneSession("joe");
    IPentahoSession s2 = new StandaloneSession("admin");
    PentahoSessionHolder.setSession(s1);
    UUID s1Uuid = sessionRef.getObject();
    PentahoSessionHolder.setSession(s2);
    UUID s2Uuid = sessionRef.getObject();
    assertNotSame(s1Uuid, s2Uuid);
    PentahoSessionHolder.setSession(s1);
    UUID s1UuidAgain = sessionRef.getObject();
    assertNotSame(s1Uuid, s1UuidAgain);
}
Also used : IObjectCreator(org.pentaho.platform.api.engine.IObjectCreator) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) UUID(java.util.UUID) Test(org.junit.Test)

Example 85 with StandaloneSession

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

the class SessionBoundPentahoObjectReferenceTest method testReference.

@Test
public void testReference() throws Exception {
    SessionBoundPentahoObjectReference<UUID> sessionRef = new SessionBoundPentahoObjectReference.Builder<UUID>(UUID.class).creator(new IObjectCreator<UUID>() {

        @Override
        public UUID create(IPentahoSession session) {
            return UUID.randomUUID();
        }
    }).build();
    IPentahoSession s1 = new StandaloneSession("joe");
    IPentahoSession s2 = new StandaloneSession("admin");
    PentahoSessionHolder.setSession(s1);
    UUID s1Uuid = sessionRef.getObject();
    PentahoSessionHolder.setSession(s2);
    UUID s2Uuid = sessionRef.getObject();
    assertNotSame(s1Uuid, s2Uuid);
    PentahoSessionHolder.setSession(s1);
    UUID s1UuidAgain = sessionRef.getObject();
    assertSame(s1Uuid, s1UuidAgain);
}
Also used : IObjectCreator(org.pentaho.platform.api.engine.IObjectCreator) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)218 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)74 ArrayList (java.util.ArrayList)46 Authentication (org.springframework.security.core.Authentication)39 Test (org.junit.Test)38 OutputStream (java.io.OutputStream)34 UsernamePasswordAuthenticationToken (org.springframework.security.authentication.UsernamePasswordAuthenticationToken)30 GrantedAuthority (org.springframework.security.core.GrantedAuthority)30 User (org.springframework.security.core.userdetails.User)30 SimpleGrantedAuthority (org.springframework.security.core.authority.SimpleGrantedAuthority)29 UserDetails (org.springframework.security.core.userdetails.UserDetails)29 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)24 File (java.io.File)21 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)21 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)21 IPentahoUser (org.pentaho.platform.api.engine.security.userroledao.IPentahoUser)20 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)20 HashMap (java.util.HashMap)16 Before (org.junit.Before)16