Search in sources :

Example 6 with IPentahoConnection

use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method testGetConnectionOrig.

@Test
public void testGetConnectionOrig() throws Exception {
    doReturn(connAction).when(mdxBaseComponent).getActionDefinition();
    when(connAction.getMdxConnectionString()).thenReturn(connectionStringAction);
    when(connectionStringAction.getStringValue()).thenReturn("mdx:localhost:8080");
    when(connAction.getConnectionProps()).thenReturn(actionInput);
    when(actionInput.getValue()).thenReturn(new Properties());
    when(connAction.getConnection()).thenReturn(jdbcAction);
    when(jdbcAction.getStringValue()).thenReturn("psql://localhost:5432");
    when(connAction.getJndi()).thenReturn(jndiAction);
    when(jndiAction.getStringValue()).thenReturn("jndi string");
    when(connAction.getLocation()).thenReturn(locationAction);
    when(locationAction.getStringValue()).thenReturn("location string");
    when(connAction.getRole()).thenReturn(roleAction);
    when(roleAction.getStringValue()).thenReturn("role string");
    when(connAction.getCatalog()).thenReturn(catalog);
    // when( catalog.getStringValue() ).thenReturn( "<catalog></catalog>" );
    when(catalog.getStringValue()).thenReturn(null);
    when(connAction.getCatalogResource()).thenReturn(catalogResource);
    when(catalogResource.getName()).thenReturn("catalog name");
    when(connAction.getUserId()).thenReturn(userAction);
    when(connAction.getPassword()).thenReturn(userAction);
    when(userAction.getStringValue()).thenReturn("user/pass");
    PentahoSystem.registerObject(mdxConnection);
    PentahoSystem.registerPrimaryObjectFactory(objFactory);
    PentahoSessionHolder.setSession(session);
    when(objFactory.get(any(Class.class), anyString(), any(IPentahoSession.class))).thenReturn(mdxConnection);
    mdxBaseComponent.setRuntimeContext(runtimeContext);
    when(runtimeContext.getResourceDefintion("catalog name")).thenReturn(catalogActionSeqRes);
    when(catalogActionSeqRes.getSourceType()).thenReturn(IActionSequenceResource.URL_RESOURCE);
    when(catalogActionSeqRes.getAddress()).thenReturn("sampledata");
    when(connAction.getExtendedColumnNames()).thenReturn(ActionInputConstant.NULL_INPUT);
    IPentahoConnection connectionOrig = mdxBaseComponent.getConnectionOrig();
    assertNotNull(connectionOrig);
    assertEquals(mdxConnection, connectionOrig);
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Properties(java.util.Properties) Test(org.junit.Test)

Example 7 with IPentahoConnection

use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method testGetDatasourceConnection_waitForTimeout.

@Test
public void testGetDatasourceConnection_waitForTimeout() throws Exception {
    // first try
    doThrow(new RuntimeException()).doThrow(// second try
    new RuntimeException()).doThrow(// third try
    new RuntimeException()).doReturn(conn).when(mdxBaseComponent).getConnection();
    doNothing().when(mdxBaseComponent).waitFor(anyInt());
    IPentahoConnection datasourceConnection = mdxBaseComponent.getDatasourceConnection();
    assertEquals(conn, datasourceConnection);
    verify(conn).clearWarnings();
    verify(mdxBaseComponent).waitFor(200);
    verify(mdxBaseComponent).waitFor(500);
    verify(mdxBaseComponent).waitFor(2000);
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) Test(org.junit.Test)

Example 8 with IPentahoConnection

use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method testGetConnectionOrig_nullConnectionProps_noConnString2.

@Test
public void testGetConnectionOrig_nullConnectionProps_noConnString2() throws Exception {
    doReturn(connAction).when(mdxBaseComponent).getActionDefinition();
    when(connAction.getMdxConnectionString()).thenReturn(connectionStringAction);
    when(connectionStringAction.getStringValue()).thenReturn(null);
    when(connAction.getConnectionProps()).thenReturn(actionInput);
    when(actionInput.getValue()).thenReturn(null);
    when(connAction.getConnection()).thenReturn(jdbcAction);
    when(jdbcAction.getStringValue()).thenReturn("psql://localhost:5432");
    when(connAction.getJndi()).thenReturn(jndiAction);
    when(jndiAction.getStringValue()).thenReturn("jndi string");
    when(connAction.getLocation()).thenReturn(locationAction);
    when(locationAction.getStringValue()).thenReturn("location string");
    when(connAction.getRole()).thenReturn(roleAction);
    when(roleAction.getStringValue()).thenReturn("role string");
    when(connAction.getCatalog()).thenReturn(catalog);
    // when( catalog.getStringValue() ).thenReturn( "<catalog></catalog>" );
    when(catalog.getStringValue()).thenReturn(null);
    when(connAction.getCatalogResource()).thenReturn(catalogResource);
    when(catalogResource.getName()).thenReturn("catalog name");
    when(connAction.getUserId()).thenReturn(userAction);
    when(connAction.getPassword()).thenReturn(userAction);
    when(userAction.getStringValue()).thenReturn("user/pass");
    PentahoSystem.registerObject(mdxConnection);
    PentahoSystem.registerPrimaryObjectFactory(objFactory);
    PentahoSessionHolder.setSession(session);
    when(objFactory.get(any(Class.class), anyString(), any(IPentahoSession.class))).thenReturn(mdxConnection);
    mdxBaseComponent.setRuntimeContext(runtimeContext);
    when(runtimeContext.getResourceDefintion("catalog name")).thenReturn(catalogActionSeqRes);
    when(catalogActionSeqRes.getSourceType()).thenReturn(IActionSequenceResource.URL_RESOURCE);
    final String urlFileExists = (new File(TestResourceLocation.TEST_RESOURCES + "/MDXBaseComponentTest/SampleData.mondrian.xml")).toURL().toString();
    when(catalogActionSeqRes.getAddress()).thenReturn(urlFileExists);
    when(connAction.getExtendedColumnNames()).thenReturn(ActionInputConstant.NULL_INPUT);
    IPentahoConnection connectionOrig = mdxBaseComponent.getConnectionOrig();
    assertNotNull(connectionOrig);
    assertEquals(mdxConnection, connectionOrig);
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Matchers.anyString(org.mockito.Matchers.anyString) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Test(org.junit.Test)

Example 9 with IPentahoConnection

use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method testGetConnectionOrig_nullConnectionProps_noConnString.

@Test
public void testGetConnectionOrig_nullConnectionProps_noConnString() throws Exception {
    doReturn(connAction).when(mdxBaseComponent).getActionDefinition();
    when(connAction.getMdxConnectionString()).thenReturn(connectionStringAction);
    when(connectionStringAction.getStringValue()).thenReturn(null);
    when(connAction.getConnectionProps()).thenReturn(actionInput);
    when(actionInput.getValue()).thenReturn(null);
    when(connAction.getConnection()).thenReturn(jdbcAction);
    when(jdbcAction.getStringValue()).thenReturn("psql://localhost:5432");
    when(connAction.getJndi()).thenReturn(jndiAction);
    when(jndiAction.getStringValue()).thenReturn("jndi string");
    when(connAction.getLocation()).thenReturn(locationAction);
    when(locationAction.getStringValue()).thenReturn("location string");
    when(connAction.getRole()).thenReturn(roleAction);
    when(roleAction.getStringValue()).thenReturn("role string");
    when(connAction.getCatalog()).thenReturn(catalog);
    // when( catalog.getStringValue() ).thenReturn( "<catalog></catalog>" );
    when(catalog.getStringValue()).thenReturn(null);
    when(connAction.getCatalogResource()).thenReturn(catalogResource);
    when(catalogResource.getName()).thenReturn("catalog name");
    when(connAction.getUserId()).thenReturn(userAction);
    when(connAction.getPassword()).thenReturn(userAction);
    when(userAction.getStringValue()).thenReturn("user/pass");
    PentahoSystem.registerObject(mdxConnection);
    PentahoSystem.registerPrimaryObjectFactory(objFactory);
    PentahoSessionHolder.setSession(session);
    when(objFactory.get(any(Class.class), anyString(), any(IPentahoSession.class))).thenReturn(mdxConnection);
    mdxBaseComponent.setRuntimeContext(runtimeContext);
    when(runtimeContext.getResourceDefintion("catalog name")).thenReturn(catalogActionSeqRes);
    when(catalogActionSeqRes.getSourceType()).thenReturn(IActionSequenceResource.URL_RESOURCE);
    when(catalogActionSeqRes.getAddress()).thenReturn("sampledata");
    when(connAction.getExtendedColumnNames()).thenReturn(ActionInputConstant.NULL_INPUT);
    IPentahoConnection connectionOrig = mdxBaseComponent.getConnectionOrig();
    assertNotNull(connectionOrig);
    assertEquals(mdxConnection, connectionOrig);
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Test(org.junit.Test)

Example 10 with IPentahoConnection

use of org.pentaho.commons.connection.IPentahoConnection in project pentaho-platform by pentaho.

the class MDXBaseComponentTest method testGetConnectionOrig_null.

@Test
public void testGetConnectionOrig_null() throws Exception {
    IPentahoConnection connectionOrig = mdxBaseComponent.getConnectionOrig();
    assertNull(connectionOrig);
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) Test(org.junit.Test)

Aggregations

IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)29 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)11 Test (org.junit.Test)9 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)9 Properties (java.util.Properties)6 OutputStream (java.io.OutputStream)5 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)5 File (java.io.File)4 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)3 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)3 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)3 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)2 AbstractRelationalDbAction (org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)2 MdxConnectionAction (org.pentaho.actionsequence.dom.actions.MdxConnectionAction)2 SqlConnectionAction (org.pentaho.actionsequence.dom.actions.SqlConnectionAction)2 DatabaseDialectException (org.pentaho.database.DatabaseDialectException)2 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)2 FileInputStream (java.io.FileInputStream)1 Format (java.text.Format)1 ArrayList (java.util.ArrayList)1