Search in sources :

Example 76 with StandaloneSession

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

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

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

the class PentahoSessionHolderTest method testStandaloneSessionLifecycle.

@Test
public void testStandaloneSessionLifecycle() {
    PentahoSessionHolder.removeSession();
    assertNull("session should be null at first", PentahoSessionHolder.getSession());
    StandaloneSession session = new StandaloneSession();
    PentahoSessionHolder.setSession(session);
    assertSame("StandaloneSession was not set as the thread-bound session", session, PentahoSessionHolder.getSession());
    PentahoSessionHolder.removeSession();
    assertNull("session should be null after a remove", PentahoSessionHolder.getSession());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) Test(org.junit.Test)

Example 79 with StandaloneSession

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

the class SimpleOutputHandlerTest method test3.

public void test3() throws Exception {
    StandaloneSession session = new StandaloneSession();
    OutputStream out = new MockExceptionOutputStream();
    SimpleOutputHandler handler = new SimpleOutputHandler(out, false);
    assertFalse(handler.allowFeedback());
    handler.setSession(session);
    assertEquals(session, handler.getSession());
    IContentItem content2 = handler.getOutputContentItem(IOutputHandler.RESPONSE, IOutputHandler.CONTENT, null, null);
    assertEquals(out, content2.getOutputStream(null));
    assertNull(handler.getFeedbackContentItem());
    try {
        handler.setOutput(IOutputHandler.CONTENT, "test data");
        fail("Exception not detected.");
    } catch (Exception ex) {
    // Test passed.
    }
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IContentItem(org.pentaho.platform.api.repository.IContentItem) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler)

Example 80 with StandaloneSession

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

the class AuditHelperTest method setUp.

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
    session = new StandaloneSession(SESSION_NAME);
    factory = new StandaloneObjectFactory();
    PentahoSystem.registerObjectFactory(factory);
    factory.defineObject(IAuditEntry.class.getSimpleName(), TestAuditEntry.class.getName(), StandaloneObjectFactory.Scope.GLOBAL);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory) IAuditEntry(org.pentaho.platform.api.engine.IAuditEntry) Before(org.junit.Before)

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