Search in sources :

Example 36 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class DefaultPluginManagerIT method test17_getPluginIdForType.

@Test
public void test17_getPluginIdForType() throws PlatformInitializationException, PluginBeanException {
    IPluginProvider provider = new IPluginProvider() {

        public List<IPlatformPlugin> getPlugins(IPentahoSession session) throws PlatformPluginRegistrationException {
            PlatformPlugin p = new PlatformPlugin(new DefaultListableBeanFactory());
            p.setId("testPlugin");
            ContentGeneratorInfo cg1 = new ContentGeneratorInfo();
            cg1.setDescription("test 9 plugin description");
            cg1.setId("oldworldCGid");
            cg1.setType("oldworldCGtype");
            cg1.setTitle("test");
            cg1.setClassname("org.pentaho.test.platform.plugin.pluginmgr.ContentGenerator1");
            // cg1.setFileInfoGeneratorClassname("org.pentaho.test.platform.plugin.pluginmgr.FileInfoGenerator");
            p.addContentGenerator(cg1);
            BeanDefinition beanDef = BeanDefinitionBuilder.rootBeanDefinition("org.pentaho.test.platform.plugin.pluginmgr.ContentGenerator1").setScope(BeanDefinition.SCOPE_PROTOTYPE).getBeanDefinition();
            p.getBeanFactory().registerBeanDefinition("springDefinedCGid", beanDef);
            p.getBeanFactory().registerAlias("springDefinedCGid", "springDefinedCGtype");
            return Arrays.asList((IPlatformPlugin) p);
        }
    };
    microPlatform.defineInstance(IPluginProvider.class, provider).start();
    pluginManager.reload();
    assertEquals("testPlugin", pluginManager.getPluginIdForType("oldworldCGtype"));
    assertEquals("testPlugin", pluginManager.getPluginIdForType("springDefinedCGtype"));
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) DefaultListableBeanFactory(org.springframework.beans.factory.support.DefaultListableBeanFactory) PlatformPlugin(org.pentaho.platform.plugin.services.pluginmgr.PlatformPlugin) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) ContentGeneratorInfo(org.pentaho.platform.engine.core.solution.ContentGeneratorInfo) IPluginProvider(org.pentaho.platform.api.engine.IPluginProvider) PluginBeanDefinition(org.pentaho.platform.api.engine.PluginBeanDefinition) BeanDefinition(org.springframework.beans.factory.config.BeanDefinition) IPlatformPlugin(org.pentaho.platform.api.engine.IPlatformPlugin) Test(org.junit.Test)

Example 37 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class PluginManagerNotConfiguredIT method testPluginAdapterViaSystemListenerAPI.

@SuppressWarnings("cast")
public void testPluginAdapterViaSystemListenerAPI() throws Exception {
    startTest();
    // $NON-NLS-1$
    IPentahoSession session = new StandaloneSession("test user");
    PluginAdapter mgr = new PluginAdapter();
    assertTrue(mgr instanceof IPentahoSystemListener);
    IPentahoSystemListener listener = (IPentahoSystemListener) mgr;
    assertFalse(listener.startup(session));
    // this does not do anything but it shouldn't error
    listener.shutdown();
    finishTest();
}
Also used : PluginAdapter(org.pentaho.platform.plugin.services.pluginmgr.PluginAdapter) IPentahoSystemListener(org.pentaho.platform.api.engine.IPentahoSystemListener) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 38 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class ConnectionIT method testMDX_VFS_zipped_Schema.

/**
 * This test currently fails, due to Mondrian not understanding the catalog URL. I'm guessing we're not using the
 * latest mondrian libs that support mondrian
 */
@SuppressWarnings("deprecation")
public void testMDX_VFS_zipped_Schema() {
    startTest();
    // StandaloneSession session = new StandaloneSession(Messages.getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$
    // SolutionRepositoryVfs.setSolutionRepository( PentahoSystem.getSolutionRepository( session ) );
    IPentahoSession session = new StandaloneSession("Admin");
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = this.getOutputStream("ConnectionTest.testSQLConnection", ".csv");
    File file = // $NON-NLS-1$
    new File(PentahoSystem.getApplicationContext().getSolutionPath("test/datasources/SampleDataSchema.zip"));
    // $NON-NLS-1$ //$NON-NLS-2$
    String catalog = "zip:" + file.toURI().toString() + "!/SampleData.mondrian.xml";
    // $NON-NLS-1$
    catalog = "solution:/test/datasources/SampleData.mondrian.xml;vfs=true";
    IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + catalog, "mondrian", "sa", "", session, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    null);
    String query = // $NON-NLS-1$
    "select {[Measures].[Actual], [Measures].[Budget]} on rows, {[Region].[All Regions]} ON columns from [Quadrant Analysis] WHERE ([Positions].[All Positions])";
    try {
        IPentahoResultSet results = connection.executeQuery(query);
        Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
        for (int row = columnHeaders.length - 1; row >= 0; row--) {
            for (int col = 0; col < columnHeaders[row].length; col++) {
                // $NON-NLS-1$
                outputStream.write((columnHeaders[row][col] + "\t").getBytes());
            }
            outputStream.write('\n');
        }
        Object[][] rowHeaders = results.getMetaData().getRowHeaders();
        int rowIdx = 0;
        Object[] row = results.next();
        while (row != null) {
            for (int colIdx = rowHeaders[rowIdx].length - 1; colIdx >= 0; colIdx--) {
                // $NON-NLS-1$
                outputStream.write((rowHeaders[rowIdx][colIdx].toString() + "\t").getBytes());
            }
            for (int colIdx = 0; colIdx < row.length; colIdx++) {
                // $NON-NLS-1$
                outputStream.write((row[colIdx] + "\t").getBytes());
            }
            outputStream.write('\n');
            row = results.next();
            rowIdx++;
        }
        results.close();
    } catch (Exception e) {
        e.printStackTrace();
    }
    connection.close();
    finishTest();
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OutputStream(java.io.OutputStream) File(java.io.File)

Example 39 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class ConnectionIT method testSQLConnectionWithAllInfo.

public void testSQLConnectionWithAllInfo() {
    startTest();
    IPentahoSession session = new StandaloneSession("Admin");
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = this.getOutputStream("ConnectionTest.testConnectionWithPropertyName", ".csv");
    File file = // $NON-NLS-1$
    new File(PentahoSystem.getApplicationContext().getSolutionPath("test/datasources/SampleData.mondrian.xml"));
    IPentahoConnection connection = PentahoConnectionFactory.getConnection(IPentahoConnection.MDX_DATASOURCE, "jdbc:hsqldb:hsql://localhost:9001/sampledata; Catalog=" + file.toURI().toString(), "mondrian", "sa", "", session, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    this);
    try {
        // $NON-NLS-1$
        IPentahoResultSet results = connection.executeQuery("select * from DEPARTMENT_MANAGERS");
        Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
        for (int row = 0; row < columnHeaders.length; row++) {
            for (int col = 0; col < columnHeaders[0].length; col++) {
                outputStream.write(columnHeaders[row][col].toString().getBytes());
                // $NON-NLS-1$
                outputStream.write(",".getBytes());
            }
            // $NON-NLS-1$
            outputStream.write("\n".getBytes());
        }
        Object[] row = results.next();
        while (row != null) {
            for (int i = 0; i < row.length; i++) {
                outputStream.write(row[i].toString().getBytes());
                // $NON-NLS-1$
                outputStream.write(",".getBytes());
            }
            // $NON-NLS-1$
            outputStream.write("\n".getBytes());
            row = results.next();
        }
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    connection.close();
    finishTest();
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) OutputStream(java.io.OutputStream) File(java.io.File)

Example 40 with IPentahoSession

use of org.pentaho.platform.api.engine.IPentahoSession in project pentaho-platform by pentaho.

the class FilterDefinitionIT method getSession.

private IPentahoSession getSession() {
    IPentahoResultSet rs = getFakeResultSet();
    // $NON-NLS-1$
    IPentahoSession session = new StandaloneSession("REPOSTEST.JUNIT_TEST_SESSION");
    // $NON-NLS-1$
    session.setAttribute("customerNamesList", rs);
    return session;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Aggregations

IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)231 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)76 Test (org.junit.Test)70 Matchers.anyString (org.mockito.Matchers.anyString)40 ArrayList (java.util.ArrayList)32 ITenant (org.pentaho.platform.api.mt.ITenant)22 IOException (java.io.IOException)20 StandaloneObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneObjectFactory)18 File (java.io.File)17 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)16 Before (org.junit.Before)14 OutputStream (java.io.OutputStream)13 HashMap (java.util.HashMap)13 InputStream (java.io.InputStream)12 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)12 ModelInfo (org.pentaho.platform.dataaccess.datasource.wizard.models.ModelInfo)12 Domain (org.pentaho.metadata.model.Domain)11 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)11 List (java.util.List)10 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)10