Search in sources :

Example 1 with Logger

use of nl.topicus.jdbc.Logger in project spanner-jdbc by olavloite.

the class CloudSpannerTestObjects method createConnection.

public static CloudSpannerConnection createConnection() throws SQLException {
    CloudSpannerConnection connection = Mockito.mock(CloudSpannerConnection.class);
    Mockito.doCallRealMethod().when(connection).setAutoCommit(Mockito.anyBoolean());
    Mockito.when(connection.getAutoCommit()).thenCallRealMethod();
    connection.setAutoCommit(false);
    Mockito.doCallRealMethod().when(connection).setBatchReadOnly(Mockito.anyBoolean());
    Mockito.when(connection.isBatchReadOnly()).thenCallRealMethod();
    Mockito.doCallRealMethod().when(connection).setReadOnly(Mockito.anyBoolean());
    Mockito.when(connection.isReadOnly()).thenCallRealMethod();
    Mockito.when(connection.isAllowExtendedMode()).thenAnswer(new Returns(true));
    Mockito.when(connection.createArrayOf(Mockito.anyString(), Mockito.any())).thenCallRealMethod();
    CloudSpannerDatabaseMetaData metadata = createMetaData();
    Mockito.when(connection.getMetaData()).thenReturn(metadata);
    CloudSpannerTransaction transaction = Mockito.mock(CloudSpannerTransaction.class);
    Mockito.when(transaction.executeQuery(Mockito.any())).thenReturn(Mockito.mock(com.google.cloud.spanner.ResultSet.class));
    Mockito.when(transaction.partitionQuery(Mockito.any(), Mockito.any())).thenReturn(Arrays.asList(mock(Partition.class), mock(Partition.class), mock(Partition.class)));
    Mockito.when(connection.getTransaction()).thenReturn(transaction);
    TableKeyMetaData tableFoo = Mockito.mock(TableKeyMetaData.class);
    Mockito.when(tableFoo.getKeyColumns()).thenAnswer(new Returns(Arrays.asList("ID")));
    Mockito.when(connection.getTable(Mockito.matches(Pattern.compile("FOO", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)))).thenAnswer(new Returns(tableFoo));
    TableKeyMetaData tableBar = Mockito.mock(TableKeyMetaData.class);
    Mockito.when(tableBar.getKeyColumns()).thenAnswer(new Returns(Arrays.asList("ID1", "ID2")));
    Mockito.when(connection.getTable(Mockito.matches(Pattern.compile("BAR", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE)))).thenAnswer(new Returns(tableBar));
    Mockito.when(connection.getLogger()).thenAnswer(new Returns(new Logger()));
    mockXAMethods(connection);
    return connection;
}
Also used : TableKeyMetaData(nl.topicus.jdbc.MetaDataStore.TableKeyMetaData) Returns(org.mockito.internal.stubbing.answers.Returns) CloudSpannerDatabaseMetaData(nl.topicus.jdbc.CloudSpannerDatabaseMetaData) CloudSpannerResultSet(nl.topicus.jdbc.resultset.CloudSpannerResultSet) ResultSet(java.sql.ResultSet) CloudSpannerConnection(nl.topicus.jdbc.CloudSpannerConnection) CloudSpannerTransaction(nl.topicus.jdbc.transaction.CloudSpannerTransaction) Logger(nl.topicus.jdbc.Logger)

Example 2 with Logger

use of nl.topicus.jdbc.Logger in project spanner-jdbc by olavloite.

the class TransactionThreadTest method createTestSubject.

private TestSubject createTestSubject() {
    MockTransactionRunner runner = new MockTransactionRunner();
    DatabaseClient dbClient = mock(DatabaseClient.class);
    when(dbClient.readWriteTransaction()).then(new Returns(runner));
    return new TestSubject(new TransactionThread(dbClient, new Logger()), runner.mock);
}
Also used : Returns(org.mockito.internal.stubbing.answers.Returns) DatabaseClient(com.google.cloud.spanner.DatabaseClient) Logger(nl.topicus.jdbc.Logger)

Aggregations

Logger (nl.topicus.jdbc.Logger)2 Returns (org.mockito.internal.stubbing.answers.Returns)2 DatabaseClient (com.google.cloud.spanner.DatabaseClient)1 ResultSet (java.sql.ResultSet)1 CloudSpannerConnection (nl.topicus.jdbc.CloudSpannerConnection)1 CloudSpannerDatabaseMetaData (nl.topicus.jdbc.CloudSpannerDatabaseMetaData)1 TableKeyMetaData (nl.topicus.jdbc.MetaDataStore.TableKeyMetaData)1 CloudSpannerResultSet (nl.topicus.jdbc.resultset.CloudSpannerResultSet)1 CloudSpannerTransaction (nl.topicus.jdbc.transaction.CloudSpannerTransaction)1