Search in sources :

Example 71 with StandaloneSession

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

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

the class StandaloneSpringPentahoObjectFactoryTest method testPriority.

public void testPriority() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    MimeTypeListener obj = PentahoSystem.get(MimeTypeListener.class, session);
    assertEquals("Higher Priority MimeTypeListener", obj.name);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 73 with StandaloneSession

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

the class StandaloneSpringPentahoObjectFactoryTest method testFallbackPenBean.

/**
 * Test <pen:bean> fallback behavior when no object is published matching the request. It should fall-back to
 * PentahoSystem.get() behavior where beans matching the simple-name of the queried class are returned.
 *
 * @throws Exception
 */
public void testFallbackPenBean() throws Exception {
    PentahoSystem.shutdown();
    ISystemConfig config = mock(ISystemConfig.class);
    when(config.getProperty("system.dampening-timeout")).thenReturn("3000");
    PentahoSystem.registerObject(config);
    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);
    // fallback
    SimpleObjectHolder integerHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder", session);
    // to
    // simpleName
    assertNotNull(integerHolder);
    assertEquals(123, (int) integerHolder.getVal());
    // fallback
    SimpleObjectHolder stringHolder = PentahoSystem.get(SimpleObjectHolder.class, "SimpleStringHolder", session);
    // to
    // simpleName
    assertNotNull(stringHolder);
    assertEquals("testing_fallback_by_interface", stringHolder.getVal().toString());
    // checks
    SimpleObjectHolder integerHolder2 = PentahoSystem.get(SimpleObjectHolder.class, "SimpleIntegerHolder2", session);
    // ID
    assertNotNull(integerHolder2);
    assertEquals(456, (int) integerHolder2.getVal());
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 74 with StandaloneSession

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

the class StandaloneSpringPentahoObjectFactoryTest method testReferences.

public void testReferences() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    IPentahoObjectReference reference = PentahoSystem.getObjectReference(MimeTypeListener.class, session);
    assertEquals("30", reference.getAttributes().get("priority"));
    assertEquals(((MimeTypeListener) reference.getObject()).name, "Higher Priority MimeTypeListener");
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 75 with StandaloneSession

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

the class StandaloneSpringPentahoObjectFactoryTest method testGetByProperty.

public void testGetByProperty() throws Exception {
    StandaloneSession session = new StandaloneSession();
    StandaloneSpringPentahoObjectFactory factory = new StandaloneSpringPentahoObjectFactory();
    factory.init("src/test/resources/solution/system/pentahoObjects.spring.xml", null);
    PentahoSystem.registerObjectFactory(factory);
    MimeTypeListener obj = PentahoSystem.get(MimeTypeListener.class, session, Collections.singletonMap("someKey", "1"));
    assertEquals("Test Attr1", obj.name);
    obj = PentahoSystem.get(MimeTypeListener.class, session, Collections.singletonMap("someKey", "2"));
    assertEquals("Test Attr2", obj.name);
    // Multiple Attributes
    HashMap<String, String> map = new HashMap<String, String>();
    map.put("someKey", "3");
    map.put("foo", "bar");
    obj = PentahoSystem.get(MimeTypeListener.class, session, map);
    assertEquals("Test Attr3", obj.name);
    // Not found, will default to
    map = new HashMap<String, String>();
    map.put("someKey", "3");
    map.put("foo", "bang");
    obj = PentahoSystem.get(MimeTypeListener.class, session, map);
    assertEquals(null, obj);
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

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