MDXBaseComponent extends ComponentBase implements IDataComponent, IPreparedComponent { protected IPentahoConnection getConnection() { MdxConnectionAction connAction = (MdxConnectionAction) getActionDefinition(); String catalogName = connAction.getCatalog().getStringValue(); IMondrianCatalogService mondrianCatalogService = PentahoSystem.get( IMondrianCatalogService.class, "IMondrianCatalogService", PentahoSessionHolder.getSession() ); MondrianCatalog catalog = mondrianCatalogService.getCatalog( catalogName, PentahoSessionHolder.getSession() ); if ( catalog == null ) { return getConnectionOrig(); } Util.PropertyList connectProperties = Util.parseConnectString( catalog.getDataSourceInfo() ); Properties properties = new Properties(); Iterator<Pair<String, String>> iter = connectProperties.iterator(); while ( iter.hasNext() ) { Pair<String, String> pair = iter.next(); properties.put( pair.getKey(), pair.getValue() ); } properties.put( "Catalog", catalog.getDefinition() ); properties.put( "Provider", "mondrian" ); properties.put( "PoolNeeded", "false" ); properties.put( RolapConnectionProperties.Locale.name(), LocaleHelper.getLocale().toString() ); debug( "Mondrian Connection Properties: " + properties.toString() ); MDXConnection mdxConnection = (MDXConnection) PentahoConnectionFactory.getConnection( IPentahoConnection.MDX_DATASOURCE, properties, PentahoSessionHolder.getSession(), this ); if ( connAction != null ) { if ( ( connAction.getExtendedColumnNames() != ActionInputConstant.NULL_INPUT ) ) { mdxConnection.setUseExtendedColumnNames( connAction.getExtendedColumnNames().getBooleanValue() ); } } return mdxConnection; }  @Override abstract boolean validateSystemSettings(); @Override abstract Log getLogger(); IPentahoResultSet getResultSet(); @Override void done(); void dispose(); IPentahoConnection shareConnection(); IPentahoResultSet executePrepared( final Map preparedParams ); IPentahoConnection getDatasourceConnection(); @Override boolean init(); static final String FORMATTED_CELL_VALUES; }
@Test public void testGetConnection() throws Exception { doReturn( connAction ).when( mdxBaseComponent ).getActionDefinition(); when( connAction.getCatalog() ).thenReturn( catalog ); when( catalog.getStringValue() ).thenReturn( "my catalog" ); PentahoSystem.registerObject( mondrianCatalogService ); PentahoSystem.registerObject( mdxConnection ); PentahoSystem.registerPrimaryObjectFactory( objFactory ); PentahoSessionHolder.setSession( session ); when( objFactory.get( any( Class.class ), eq( "connection-MDX" ), any( IPentahoSession.class ) ) ).thenReturn( mdxConnection ); when( mondrianCatalogService.getCatalog( anyString(), any( IPentahoSession.class ) ) ).thenReturn( mondrianCatalog ); when( mondrianCatalog.getDataSourceInfo() ).thenReturn( "connection info" ); when( mondrianCatalog.getDefinition() ).thenReturn( "<catalog></catalog>" ); when( connAction.getExtendedColumnNames() ).thenReturn( ActionInputConstant.NULL_INPUT ); IPentahoConnection connection = mdxBaseComponent.getConnection(); assertNotNull( connection ); assertEquals( mdxConnection, connection ); }