This is an automated email from the ASF dual-hosted git repository.
nreich pushed a commit to branch feature/GEODE-3781
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/feature/GEODE-3781 by this
push:
new defb7e1 Refactor JDBCManager and its tests
defb7e1 is described below
commit defb7e194026e1ced365af20100fdfb979bad133
Author: Nick Reich <[email protected]>
AuthorDate: Mon Nov 13 09:32:53 2017 -0800
Refactor JDBCManager and its tests
---
.../connectors/jdbc/internal/JDBCManager.java | 22 +-
.../jdbc/internal/JDBCManagerUnitTest.java | 615 +++++----------------
2 files changed, 164 insertions(+), 473 deletions(-)
diff --git
a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java
index be82e22..7f16ad3 100644
---
a/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java
+++
b/geode-connectors/src/main/java/org/apache/geode/connectors/jdbc/internal/JDBCManager.java
@@ -50,23 +50,27 @@ public class JDBCManager {
}
Connection getConnection(JDBCConnectionConfiguration config) {
- Connection result = connectionMap.get(config.getName());
+ Connection connection = connectionMap.get(config.getName());
try {
- if (result != null && !result.isClosed()) {
- return result;
+ if (connection != null && !connection.isClosed()) {
+ return connection;
}
} catch (SQLException ignore) {
// If isClosed throws fall through and connect again
}
- // TODO: make thread safe by synchronizing on map of connections
+ return getNewConnection(config);
+ }
+
+ private synchronized Connection getNewConnection(JDBCConnectionConfiguration
config) {
+ Connection connection;
try {
- result = getSQLConnection(config);
+ connection = getSQLConnection(config);
} catch (SQLException e) {
// TODO: consider a different exception
throw new IllegalStateException("Could not connect to " +
config.getUrl(), e);
}
- connectionMap.put(config.getName(), result);
- return result;
+ connectionMap.put(config.getName(), connection);
+ return connection;
}
// package protected for testing purposes only
@@ -74,7 +78,6 @@ public class JDBCManager {
return DriverManager.getConnection(config.getUrl(), config.getUser(),
config.getPassword());
}
- // TODO write unit tests
List<ColumnValue> getColumnToValueList(JDBCConnectionConfiguration config,
JDBCRegionMapping regionMapping, Object key, PdxInstance value,
Operation operation) {
String keyColumnName = getKeyColumnName(config,
regionMapping.getTableName());
@@ -112,9 +115,9 @@ public class JDBCManager {
private String computeKeyColumnName(JDBCConnectionConfiguration
connectionConfig,
String tableName) {
// TODO: check config for key column
- Connection connection = getConnection(connectionConfig);
String key;
try {
+ Connection connection = getConnection(connectionConfig);
DatabaseMetaData metaData = connection.getMetaData();
ResultSet tables = metaData.getTables(null, null, "%", null);
String realTableName = null;
@@ -151,6 +154,7 @@ public class JDBCManager {
throw new IllegalStateException("NYI: handleSQLException", e);
}
+ //TODO: debug code to be removed
private void printResultSet(ResultSet resultSets) {
System.out.println("Printing ResultSet:");
try {
diff --git
a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java
index f9a81e1..73e78b0 100644
---
a/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java
+++
b/geode-connectors/src/test/java/org/apache/geode/connectors/jdbc/internal/JDBCManagerUnitTest.java
@@ -15,6 +15,8 @@
package org.apache.geode.connectors.jdbc.internal;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -22,27 +24,53 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Arrays;
+import java.util.List;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+import org.apache.geode.cache.Operation;
+import org.apache.geode.pdx.PdxInstance;
import org.apache.geode.test.junit.categories.UnitTest;
@Category(UnitTest.class)
public class JDBCManagerUnitTest {
-
private static final String REGION_NAME = "testRegion";
+ private static final String TABLE_NAME = "testTable";
private static final String CONFIG_NAME = "configName";
+ private static final String KEY_COLUMN = "keyColumn";
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
private JDBCConfigurationService configService;
private JDBCManager manager;
+ private Connection connection;
+ private JDBCConnectionConfiguration connectionConfig;
+ private JDBCRegionMapping mapping;
+ private Object key = new Object();
+ private PdxInstance value = mock(PdxInstance.class);
@Before
- public void setup() {
+ public void setup() throws Exception {
configService = mock(JDBCConfigurationService.class);
- manager = new JDBCManager(configService);
+ manager = spy(new JDBCManager(configService));
+ connection = mock(Connection.class);
+
+ connectionConfig =
+ getTestConnectionConfig("name", "url", null, null);
+ doReturn(connection).when(manager).getSQLConnection(connectionConfig);
+
+ mapping = mock(JDBCRegionMapping.class);
+ when(mapping.getTableName()).thenReturn(TABLE_NAME);
}
@Test
@@ -59,83 +87,151 @@ public class JDBCManagerUnitTest {
@Test
public void retrievesANewConnection() throws Exception {
- JDBCManager spyManager = spy(manager);
- Connection connection = mock(Connection.class);
- JDBCConnectionConfiguration connectionConfig =
- getTestConnectionConfig("name", "url", null, null);
- doReturn(connection).when(spyManager).getSQLConnection(connectionConfig);
- Connection returnedConnection = spyManager.getConnection(connectionConfig);
+ Connection returnedConnection = manager.getConnection(connectionConfig);
assertThat(returnedConnection).isNotNull().isSameAs(connection);
}
@Test
public void retrievesSameConnectionForSameConnectionConfig() throws
Exception {
- JDBCManager spyManager = spy(manager);
- Connection connection = mock(Connection.class);
- JDBCConnectionConfiguration connectionConfig =
- getTestConnectionConfig("name", "url", null, null);
- doReturn(connection).when(spyManager).getSQLConnection(connectionConfig);
- Connection returnedConnection = spyManager.getConnection(connectionConfig);
- Connection secondReturnedConnection =
spyManager.getConnection(connectionConfig);
+ Connection returnedConnection = manager.getConnection(connectionConfig);
+ Connection secondReturnedConnection =
manager.getConnection(connectionConfig);
assertThat(returnedConnection).isNotNull().isSameAs(connection);
assertThat(secondReturnedConnection).isNotNull().isSameAs(connection);
}
@Test
public void retrievesDifferentConnectionForEachConfig() throws Exception {
- JDBCManager spyManager = spy(manager);
- Connection connection = mock(Connection.class);
Connection secondConnection = mock(Connection.class);
- JDBCConnectionConfiguration connectionConfig =
- getTestConnectionConfig("name", "url", null, null);
JDBCConnectionConfiguration secondConnectionConfig =
getTestConnectionConfig("newName", "url", null, null);
+
doReturn(secondConnection).when(manager).getSQLConnection(secondConnectionConfig);
- doReturn(connection).when(spyManager).getSQLConnection(connectionConfig);
-
doReturn(secondConnection).when(spyManager).getSQLConnection(secondConnectionConfig);
- Connection returnedConnection = spyManager.getConnection(connectionConfig);
- Connection secondReturnedConnection =
spyManager.getConnection(secondConnectionConfig);
+ Connection returnedConnection = manager.getConnection(connectionConfig);
+ Connection secondReturnedConnection =
manager.getConnection(secondConnectionConfig);
assertThat(returnedConnection).isNotNull().isSameAs(connection);
assertThat(secondReturnedConnection).isNotNull().isSameAs(secondConnection);
assertThat(returnedConnection).isNotSameAs(secondReturnedConnection);
}
@Test
- public void retrivesANewConnectionIfCachedOneIsClosed() throws Exception {
- JDBCManager spyManager = spy(manager);
- Connection connection = mock(Connection.class);
+ public void retrievesANewConnectionIfCachedOneIsClosed() throws Exception {
+ manager.getConnection(connectionConfig);
when(connection.isClosed()).thenReturn(true);
- Connection secondConnection = mock(Connection.class);
- JDBCConnectionConfiguration connectionConfig =
- getTestConnectionConfig("name", "url", null, null);
- doReturn(connection).when(spyManager).getSQLConnection(connectionConfig);
- spyManager.getConnection(connectionConfig);
-
doReturn(secondConnection).when(spyManager).getSQLConnection(connectionConfig);
- Connection secondReturnedConnection =
spyManager.getConnection(connectionConfig);
+ Connection secondConnection = mock(Connection.class);
+
doReturn(secondConnection).when(manager).getSQLConnection(connectionConfig);
+ Connection secondReturnedConnection =
manager.getConnection(connectionConfig);
assertThat(secondReturnedConnection).isSameAs(secondConnection);
}
@Test
public void closesAllConnections() throws Exception {
- JDBCManager spyManager = spy(manager);
- Connection connection = mock(Connection.class);
Connection secondConnection = mock(Connection.class);
- JDBCConnectionConfiguration connectionConfig =
- getTestConnectionConfig("name", "url", null, null);
JDBCConnectionConfiguration secondConnectionConfig =
getTestConnectionConfig("newName", "url", null, null);
- doReturn(connection).when(spyManager).getSQLConnection(connectionConfig);
-
doReturn(secondConnection).when(spyManager).getSQLConnection(secondConnectionConfig);
- spyManager.getConnection(connectionConfig);
- spyManager.getConnection(secondConnectionConfig);
+
doReturn(secondConnection).when(manager).getSQLConnection(secondConnectionConfig);
+ manager.getConnection(connectionConfig);
+ manager.getConnection(secondConnectionConfig);
- spyManager.close();
+ manager.close();
verify(connection).close();
verify(secondConnection).close();
}
+ @Test
+ public void returnsCorrectColumnForDestroy() throws Exception {
+ ResultSet primaryKeys = getPrimaryKeysMetadData();
+ when(primaryKeys.next()).thenReturn(true).thenReturn(false);
+
+ List<ColumnValue> columnValueList =
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.DESTROY);
+ assertThat(columnValueList).hasSize(1);
+ assertThat(columnValueList.get(0).getColumnName()).isEqualTo(KEY_COLUMN);
+ }
+
+ @Test
+ public void returnsCorrectColumnForGet() throws Exception {
+ ResultSet primaryKeys = getPrimaryKeysMetadData();
+ when(primaryKeys.next()).thenReturn(true).thenReturn(false);
+
+ List<ColumnValue> columnValueList =
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.GET);
+ assertThat(columnValueList).hasSize(1);
+ assertThat(columnValueList.get(0).getColumnName()).isEqualTo(KEY_COLUMN);
+ }
+
+ @Test
+ public void throwsExceptionIfTableHasCompositePrimaryKey() throws Exception {
+ ResultSet primaryKeys = getPrimaryKeysMetadData();
+ when(primaryKeys.next()).thenReturn(true);
+
+ thrown.expect(IllegalStateException.class);
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.GET);
+ }
+
+ @Test
+ public void throwsExceptionWhenTwoTablesHasCaseInsensitiveSameName() throws
Exception {
+ DatabaseMetaData metadata = mock(DatabaseMetaData.class);
+ when(connection.getMetaData()).thenReturn(metadata);
+ ResultSet resultSet = mock(ResultSet.class);
+ when(resultSet.next()).thenReturn(true).thenReturn(true).thenReturn(false);
+ when(resultSet.getString("TABLE_NAME")).thenReturn(TABLE_NAME);
+
when(resultSet.getString("TABLE_NAME")).thenReturn(TABLE_NAME.toUpperCase());
+ when(metadata.getTables(any(), any(), any(), any())).thenReturn(resultSet);
+
+ thrown.expect(IllegalStateException.class);
+ thrown.expectMessage("Duplicate tables that match region name");
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.GET);
+ }
+
+ @Test
+ public void throwsExceptionWhenDesiredTableNotFound() throws Exception {
+ DatabaseMetaData metadata = mock(DatabaseMetaData.class);
+ when(connection.getMetaData()).thenReturn(metadata);
+ ResultSet resultSet = mock(ResultSet.class);
+ when(resultSet.next()).thenReturn(true).thenReturn(false);
+ when(resultSet.getString("TABLE_NAME")).thenReturn("otherTable");
+ when(metadata.getTables(any(), any(), any(), any())).thenReturn(resultSet);
+
+ thrown.expect(IllegalStateException.class);
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.GET);
+ }
+
+ @Test
+ public void throwsExceptionWhenNoPrimaryKeyInTable() throws Exception {
+ ResultSet primaryKeys = getPrimaryKeysMetadData();
+ when(primaryKeys.next()).thenReturn(false);
+
+ thrown.expect(IllegalStateException.class);
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.GET);
+ }
+
+ @Test
+ public void throwsExceptionWhenFailsToGetTableMetadata() throws Exception {
+ when(connection.getMetaData()).thenThrow(SQLException.class);
+
+ thrown.expect(IllegalStateException.class);
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.GET);
+ }
+
+ @Test
+ public void returnsCorrectColumnsForUpsertOperations() throws Exception {
+ ResultSet primaryKeys = getPrimaryKeysMetadData();
+ when(primaryKeys.next()).thenReturn(true).thenReturn(false);
+
+ String nonKeyColumn = "otherColumn";
+ when(mapping.getColumnNameForField(KEY_COLUMN)).thenReturn(KEY_COLUMN);
+ when(mapping.getColumnNameForField(nonKeyColumn)).thenReturn(nonKeyColumn);
+ when(value.getFieldNames()).thenReturn(Arrays.asList(KEY_COLUMN,
nonKeyColumn));
+
+ List<ColumnValue> columnValueList =
+ manager.getColumnToValueList(connectionConfig, mapping, key, value,
Operation.UPDATE);
+ assertThat(columnValueList).hasSize(2);
+ assertThat(columnValueList.get(0).getColumnName()).isEqualTo(nonKeyColumn);
+ assertThat(columnValueList.get(1).getColumnName()).isEqualTo(KEY_COLUMN);
+ }
+
private JDBCConnectionConfiguration getTestConnectionConfig(String name,
String url, String user,
String password) {
JDBCConnectionConfiguration config = new JDBCConnectionConfiguration();
@@ -146,425 +242,16 @@ public class JDBCManagerUnitTest {
return config;
}
-
- /*
- * private JDBCManager mgr; private String regionName = "jdbcRegion"; private
- * JDBCConfigurationService configService; private Connection connection;
private
- * PreparedStatement preparedStatement; private PreparedStatement
preparedStatement2;
- *
- * private static final String ID_COLUMN_NAME = "ID"; private static final
String NAME_COLUMN_NAME
- * = "name"; private static final String AGE_COLUMN_NAME = "age";
- */
-
- /*
- * public class TestableUpsertJDBCManager extends JDBCManager {
- *
- * final int upsertReturn;
- *
- * TestableUpsertJDBCManager(JDBCConfigurationService config) {
super(config); upsertReturn = 1; }
- *
- * TestableUpsertJDBCManager(JDBCConfigurationService config, int
upsertReturn) { super(config);
- * this.upsertReturn = upsertReturn; }
- *
- * @Override protected Connection createConnection(String url, String user,
String password)
- * throws SQLException { ResultSet rsKeys = mock(ResultSet.class);
- * when(rsKeys.next()).thenReturn(true, false);
- * when(rsKeys.getString("COLUMN_NAME")).thenReturn(ID_COLUMN_NAME);
- *
- * ResultSet rs = mock(ResultSet.class); when(rs.next()).thenReturn(true,
false);
- * when(rs.getString("TABLE_NAME")).thenReturn(regionName.toUpperCase());
- *
- * DatabaseMetaData metaData = mock(DatabaseMetaData.class);
when(metaData.getPrimaryKeys(null,
- * null, regionName.toUpperCase())).thenReturn(rsKeys);
when(metaData.getTables(any(), any(),
- * any(), any())).thenReturn(rs);
- *
- * preparedStatement = mock(PreparedStatement.class); preparedStatement2 =
- * mock(PreparedStatement.class);
when(preparedStatement.getUpdateCount()).thenReturn(0);
- * when(preparedStatement2.getUpdateCount()).thenReturn(this.upsertReturn);
- *
- * connection = mock(Connection.class);
when(connection.getMetaData()).thenReturn(metaData);
- * when(connection.prepareStatement(any())).thenReturn(preparedStatement,
preparedStatement2);
- *
- * return connection; } }
- */
-
- /*
- * public class TestableJDBCManagerWithResultSets extends JDBCManager {
- *
- * private ResultSet tableResults; private ResultSet primaryKeyResults;
private ResultSet
- * queryResultSet; private String tableName;
- *
- * TestableJDBCManagerWithResultSets(String tableName,
JDBCConfigurationService config, ResultSet
- * tableResults, ResultSet primaryKeyResults, ResultSet queryResultSet) {
super(config);
- * this.tableResults = tableResults; this.primaryKeyResults =
primaryKeyResults;
- * this.queryResultSet = queryResultSet; this.tableName = tableName; }
- *
- * @Override protected Connection createConnection(String url, String user,
String password)
- * throws SQLException { if (primaryKeyResults == null) { primaryKeyResults =
- * mock(ResultSet.class); when(primaryKeyResults.next()).thenReturn(true,
false);
- *
when(primaryKeyResults.getString("COLUMN_NAME")).thenReturn(ID_COLUMN_NAME); }
- *
- * if (tableResults == null) { tableResults = mock(ResultSet.class);
- * when(tableResults.next()).thenReturn(true, false);
- *
when(tableResults.getString("TABLE_NAME")).thenReturn(this.tableName.toUpperCase());
}
- *
- * DatabaseMetaData metaData = mock(DatabaseMetaData.class);
when(metaData.getPrimaryKeys(null,
- * null, this.tableName.toUpperCase())) .thenReturn(primaryKeyResults);
- * when(metaData.getTables(any(), any(), any(),
any())).thenReturn(tableResults);
- *
- * preparedStatement = mock(PreparedStatement.class);
- * when(preparedStatement.getUpdateCount()).thenReturn(1);
- *
- *
- * if (this.queryResultSet == null) { queryResultSet =
mock(ResultSet.class); ResultSetMetaData
- * rsmd = mock(ResultSetMetaData.class);
when(rsmd.getColumnCount()).thenReturn(3);
- * when(rsmd.getColumnName(anyInt())).thenReturn("ID", "NAME", "AGE");
- * when(queryResultSet.getMetaData()).thenReturn(rsmd);
- * when(queryResultSet.next()).thenReturn(true, false);
- * when(queryResultSet.getObject(anyInt())).thenReturn("1", "Emp1", 21); }
- *
- * when(preparedStatement.executeQuery()).thenReturn(queryResultSet);
- *
- * connection = mock(Connection.class);
when(connection.getMetaData()).thenReturn(metaData);
- * when(connection.prepareStatement(any())).thenReturn(preparedStatement);
- *
- * return connection; } }
- */
-
- /*
- * @Before public void setUp() throws Exception { configService =
- * mock(JDBCConfigurationService.class); }
- *
- * @After public void tearDown() throws Exception {}
- *
- * private void createManager(String... args) throws SQLException {
- * createManagerWithTableName(regionName, args); }
- *
- * private void createManagerWithTableName(String tableName, String... args)
throws SQLException {
- * ResultSet rsKeys = mock(ResultSet.class);
when(rsKeys.next()).thenReturn(true, false);
- * when(rsKeys.getString("COLUMN_NAME")).thenReturn(ID_COLUMN_NAME);
- *
- * ResultSet rs = mock(ResultSet.class); when(rs.next()).thenReturn(true,
false);
- * when(rs.getString("TABLE_NAME")).thenReturn(tableName.toUpperCase());
- *
- * this.mgr = new JDBCManager(tableName, createConfiguration(args), rs,
rsKeys, null); }
- *
- * private void createDefaultManager() throws SQLException {
createManager(); }
- *
- * private void createUpsertManager() { this.mgr = new
- * TestableUpsertJDBCManager(createConfiguration()); }
- *
- * private void createUpsertManager(int upsertReturn) { this.mgr = new
- * TestableUpsertJDBCManager(createConfiguration(), upsertReturn); }
- *
- * private void createManager(ResultSet tableNames, ResultSet primaryKeys,
ResultSet
- * queryResultSet, String... args) { this.mgr = new
TestableJDBCManagerWithResultSets(regionName,
- * createConfiguration(args), tableNames, primaryKeys, queryResultSet); }
- *
- * private JDBCConfigurationService createConfiguration(String... args) {
Properties props = new
- * Properties(); props.setProperty("url", "fakeURL"); String[] argsArray =
args; if (argsArray !=
- * null) { assert argsArray.length % 2 == 0; for (int i = 0; i <
argsArray.length; i += 2) {
- * props.setProperty(argsArray[i], argsArray[i + 1]); } }
JDBCConfigurationService service = new
- * JDBCConfigurationService(); JDBCConnectionConfiguration connectionConfig =
- * service.addOrUpdateConnectionConfig(conne); return service; }
- *
- * @Test public void verifySimpleCreateCallsExecute() throws SQLException {
- * createDefaultManager(); GemFireCacheImpl cache = Fakes.cache(); Region
region =
- * Fakes.region(regionName, cache); PdxInstanceImpl pdx1 =
mockPdxInstance("Emp1", 21);
- * this.mgr.write(region, Operation.CREATE, "1", pdx1);
verify(this.preparedStatement).execute();
- * ArgumentCaptor<String> sqlCaptor = ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
- * assertThat(sqlCaptor.getValue()).isEqualTo("INSERT INTO " + regionName +
"(" + NAME_COLUMN_NAME
- * + ", " + AGE_COLUMN_NAME + ", " + ID_COLUMN_NAME + ") VALUES (?,?,?)");
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(3)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1"); }
- *
- * @Test public void verifySimpleCreateWithIdField() throws SQLException {
createDefaultManager();
- * GemFireCacheImpl cache = Fakes.cache(); Region region =
Fakes.region(regionName, cache);
- * PdxInstanceImpl pdx1 = mockPdxInstance("Emp1", 21, true);
this.mgr.write(region,
- * Operation.CREATE, "1", pdx1); verify(this.preparedStatement).execute();
ArgumentCaptor<String>
- * sqlCaptor = ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
- * assertThat(sqlCaptor.getValue()).isEqualTo("INSERT INTO " + regionName +
"(" + NAME_COLUMN_NAME
- * + ", " + AGE_COLUMN_NAME + ", " + ID_COLUMN_NAME + ") VALUES (?,?,?)");
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(3)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1"); }
- *
- * @Test public void verifySimpleUpdateCallsExecute() throws SQLException {
- * createDefaultManager(); GemFireCacheImpl cache = Fakes.cache(); Region
region =
- * Fakes.region(regionName, cache); PdxInstanceImpl pdx1 =
mockPdxInstance("Emp1", 21);
- * this.mgr.write(region, Operation.UPDATE, "1", pdx1);
verify(this.preparedStatement).execute();
- * ArgumentCaptor<String> sqlCaptor = ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
- * assertThat(sqlCaptor.getValue()).isEqualTo("UPDATE " + regionName + " SET
" + NAME_COLUMN_NAME
- * + " = ?, " + AGE_COLUMN_NAME + " = ? WHERE " + ID_COLUMN_NAME + " = ?");
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(3)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1"); }
- *
- * @Test public void verifySimpleDestroyCallsExecute() throws SQLException {
- * createDefaultManager(); GemFireCacheImpl cache = Fakes.cache(); Region
region =
- * Fakes.region(regionName, cache); this.mgr.write(region,
Operation.DESTROY, "1", null);
- * verify(this.preparedStatement).execute(); ArgumentCaptor<String>
sqlCaptor =
- * ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
assertThat(sqlCaptor.getValue())
- * .isEqualTo("DELETE FROM " + regionName + " WHERE " + ID_COLUMN_NAME + " =
?");
- * ArgumentCaptor<Object> objectCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(this.preparedStatement, times(1)).setObject(anyInt(),
objectCaptor.capture());
- * List<Object> allObjects = objectCaptor.getAllValues();
- * assertThat(allObjects.get(0)).isEqualTo("1"); }
- *
- * @Test public void verifyTwoCreatesReuseSameStatement() throws
SQLException {
- * createDefaultManager(); GemFireCacheImpl cache = Fakes.cache(); Region
region =
- * Fakes.region(regionName, cache); PdxInstanceImpl pdx1 =
mockPdxInstance("Emp1", 21);
- * PdxInstanceImpl pdx2 = mockPdxInstance("Emp2", 55);
this.mgr.write(region, Operation.CREATE,
- * "1", pdx1); this.mgr.write(region, Operation.CREATE, "2", pdx2);
verify(this.preparedStatement,
- * times(2)).execute(); verify(this.connection).prepareStatement(any());
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(6)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1");
- * assertThat(allObjects.get(3)).isEqualTo("Emp2");
assertThat(allObjects.get(4)).isEqualTo(55);
- * assertThat(allObjects.get(5)).isEqualTo("2"); }
- *
- * private PdxInstanceImpl mockPdxInstance(String name, int age) { return
mockPdxInstance(name,
- * age, false); }
- *
- * private PdxInstanceImpl mockPdxInstance(String name, int age, boolean
addId) { PdxInstanceImpl
- * pdxInstance = mock(PdxInstanceImpl.class); if (addId) {
when(pdxInstance.getFieldNames())
- * .thenReturn(Arrays.asList(NAME_COLUMN_NAME, AGE_COLUMN_NAME,
ID_COLUMN_NAME));
- * when(pdxInstance.getField(ID_COLUMN_NAME)).thenReturn("bogusId"); } else {
- * when(pdxInstance.getFieldNames())
.thenReturn(Arrays.asList(NAME_COLUMN_NAME,
- * AGE_COLUMN_NAME)); }
when(pdxInstance.getField(NAME_COLUMN_NAME)).thenReturn(name);
- * when(pdxInstance.getField(AGE_COLUMN_NAME)).thenReturn(age); PdxType
pdxType =
- * mock(PdxType.class); when(pdxType.getTypeId()).thenReturn(1);
- * when(pdxInstance.getPdxType()).thenReturn(pdxType); return pdxInstance; }
- *
- * @Test public void verifySimpleInvalidateIsUnsupported() throws
SQLException {
- * createDefaultManager(); GemFireCacheImpl cache = Fakes.cache(); Region
region =
- * Fakes.region(regionName, cache); PdxInstanceImpl pdx1 =
mockPdxInstance("Emp1", 21);
- * catchException(this.mgr).write(region, Operation.INVALIDATE, "1", pdx1);
assertThat((Exception)
- * caughtException()).isInstanceOf(IllegalStateException.class);
- * assertThat(caughtException().getMessage()).isEqualTo("unsupported
operation INVALIDATE"); }
- *
- * @Test public void verifyNoTableForRegion() throws SQLException {
createDefaultManager();
- * GemFireCacheImpl cache = Fakes.cache(); Region region =
Fakes.region("badRegion", cache);
- * catchException(this.mgr).write(region, Operation.DESTROY, "1", null);
assertThat((Exception)
- * caughtException()).isInstanceOf(IllegalStateException.class);
- * assertThat(caughtException().getMessage())
- * .isEqualTo("no table was found that matches badRegion"); }
- *
- * @Test public void callClose() throws SQLException {
createDefaultManager(); this.mgr.close(); }
- *
- * @Test public void callCloseWithConnection() throws SQLException {
createDefaultManager();
- * this.mgr.getConnection(null, null); this.mgr.close(); }
- *
- * @Test public void verifyInsertUpdate() throws SQLException {
createUpsertManager();
- * GemFireCacheImpl cache = Fakes.cache(); Region region =
Fakes.region(regionName, cache);
- * PdxInstanceImpl pdx1 = mockPdxInstance("Emp1", 21);
this.mgr.write(region, Operation.CREATE,
- * "1", pdx1); verify(this.preparedStatement).execute();
- * verify(this.preparedStatement2).execute(); ArgumentCaptor<String>
sqlCaptor =
- * ArgumentCaptor.forClass(String.class); verify(this.connection,
- * times(2)).prepareStatement(sqlCaptor.capture()); List<String> allArgs =
- * sqlCaptor.getAllValues(); assertThat(allArgs.get(0)).isEqualTo("INSERT
INTO " + regionName +
- * "(" + NAME_COLUMN_NAME + ", " + AGE_COLUMN_NAME + ", " + ID_COLUMN_NAME +
") VALUES (?,?,?)");
- * assertThat(allArgs.get(1)).isEqualTo("UPDATE " + regionName + " SET " +
NAME_COLUMN_NAME +
- * " = ?, " + AGE_COLUMN_NAME + " = ? WHERE " + ID_COLUMN_NAME + " = ?");
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(3)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1");
- * verify(this.preparedStatement2, times(3)).setObject(anyInt(),
objectCaptor.capture());
- * allObjects = objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1"); }
- *
- * @Test public void verifyUpdateInsert() throws SQLException {
createUpsertManager();
- * GemFireCacheImpl cache = Fakes.cache(); Region region =
Fakes.region(regionName, cache);
- * PdxInstanceImpl pdx1 = mockPdxInstance("Emp1", 21);
this.mgr.write(region, Operation.UPDATE,
- * "1", pdx1); verify(this.preparedStatement).execute();
- * verify(this.preparedStatement2).execute(); ArgumentCaptor<String>
sqlCaptor =
- * ArgumentCaptor.forClass(String.class); verify(this.connection,
- * times(2)).prepareStatement(sqlCaptor.capture()); List<String> allArgs =
- * sqlCaptor.getAllValues(); assertThat(allArgs.get(0)).isEqualTo("UPDATE "
+ regionName + " SET "
- * + NAME_COLUMN_NAME + " = ?, " + AGE_COLUMN_NAME + " = ? WHERE " +
ID_COLUMN_NAME + " = ?");
- * assertThat(allArgs.get(1)).isEqualTo("INSERT INTO " + regionName + "(" +
NAME_COLUMN_NAME +
- * ", " + AGE_COLUMN_NAME + ", " + ID_COLUMN_NAME + ") VALUES (?,?,?)");
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(3)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1");
- * verify(this.preparedStatement2, times(3)).setObject(anyInt(),
objectCaptor.capture());
- * allObjects = objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1"); }
- *
- * @Test public void verifyInsertUpdateThatUpdatesNothing() throws
SQLException {
- * createUpsertManager(0); GemFireCacheImpl cache = Fakes.cache(); Region
region =
- * Fakes.region(regionName, cache); PdxInstanceImpl pdx1 =
mockPdxInstance("Emp1", 21);
- * catchException(this.mgr).write(region, Operation.CREATE, "1", pdx1);
assertThat((Exception)
- * caughtException()).isInstanceOf(IllegalStateException.class);
- * assertThat(caughtException().getMessage()).isEqualTo("Unexpected
updateCount 0");
- * verify(this.preparedStatement).execute();
verify(this.preparedStatement2).execute();
- * ArgumentCaptor<String> sqlCaptor = ArgumentCaptor.forClass(String.class);
- * verify(this.connection, times(2)).prepareStatement(sqlCaptor.capture());
List<String> allArgs =
- * sqlCaptor.getAllValues(); assertThat(allArgs.get(0)).isEqualTo("INSERT
INTO " + regionName +
- * "(" + NAME_COLUMN_NAME + ", " + AGE_COLUMN_NAME + ", " + ID_COLUMN_NAME +
") VALUES (?,?,?)");
- * assertThat(allArgs.get(1)).isEqualTo("UPDATE " + regionName + " SET " +
NAME_COLUMN_NAME +
- * " = ?, " + AGE_COLUMN_NAME + " = ? WHERE " + ID_COLUMN_NAME + " = ?");
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(3)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1");
- * verify(this.preparedStatement2, times(3)).setObject(anyInt(),
objectCaptor.capture());
- * allObjects = objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1"); }
- *
- * @Test public void twoTablesOfSameName() throws SQLException { ResultSet
primaryKeys = null;
- * ResultSet tables = mock(ResultSet.class);
when(tables.next()).thenReturn(true, true, false);
- * when(tables.getString("TABLE_NAME")).thenReturn(regionName.toUpperCase());
- * createManager(tables, primaryKeys, null);
- * catchException(this.mgr).computeKeyColumnName(regionName);
assertThat((Exception)
- * caughtException()).isInstanceOf(IllegalStateException.class);
- * assertThat(caughtException().getMessage()).isEqualTo("Duplicate tables
that match region name"
- * ); }
- *
- * @Test public void noPrimaryKeyOnTable() throws SQLException { ResultSet
tables = null;
- * ResultSet primaryKeys = mock(ResultSet.class);
when(primaryKeys.next()).thenReturn(false);
- * createManager(tables, primaryKeys, null);
- * catchException(this.mgr).computeKeyColumnName(regionName);
assertThat((Exception)
- * caughtException()).isInstanceOf(IllegalStateException.class);
- * assertThat(caughtException().getMessage()) .isEqualTo("The table " +
regionName +
- * " does not have a primary key column."); }
- *
- * @Test public void twoPrimaryKeysOnTable() throws SQLException { ResultSet
tables = null;
- * ResultSet primaryKeys = mock(ResultSet.class);
when(primaryKeys.next()).thenReturn(true, true,
- * false); createManager(tables, primaryKeys, null);
- * catchException(this.mgr).computeKeyColumnName(regionName);
assertThat((Exception)
- * caughtException()).isInstanceOf(IllegalStateException.class);
- * assertThat(caughtException().getMessage()) .isEqualTo("The table " +
regionName +
- * " has more than one primary key column."); }
- *
- * @Test public void verifyReadThatMissesReturnsNull() throws SQLException {
ResultSet
- * queryResults = mock(ResultSet.class);
when(queryResults.next()).thenReturn(false);
- * createManager(null, null, queryResults); GemFireCacheImpl cache =
Fakes.cache(); Region region
- * = Fakes.region(regionName, cache); assertThat(this.mgr.read(region,
"2")).isNull(); }
- *
- * @Test public void verifyReadWithMultipleResultsFails() throws
SQLException { ResultSet
- * queryResults = mock(ResultSet.class);
when(queryResults.next()).thenReturn(true, true, false);
- * ResultSetMetaData rsmd = mock(ResultSetMetaData.class);
- * when(rsmd.getColumnCount()).thenReturn(3);
when(rsmd.getColumnName(anyInt())).thenReturn("ID",
- * "NAME", "AGE"); when(queryResults.getMetaData()).thenReturn(rsmd);
createManager(null, null,
- * queryResults); GemFireCacheImpl cache = Fakes.cache(); PdxInstanceFactory
factory =
- * mock(PdxInstanceFactory.class); PdxInstance pi = mock(PdxInstance.class);
- * when(factory.create()).thenReturn(pi);
when(cache.createPdxInstanceFactory("no class",
- * false)).thenReturn(factory); Region region = Fakes.region(regionName,
cache);
- * catchException(this.mgr).read(region, "1"); assertThat((Exception)
- * caughtException()).isInstanceOf(IllegalStateException.class);
- * assertThat(caughtException().getMessage())
- * .isEqualTo("Multiple rows returned for key 1 on table " + regionName); }
- *
- * @Test public void verifyReadThatHitsReturnsValue() throws SQLException {
- * createDefaultManager(); GemFireCacheImpl cache = Fakes.cache();
PdxInstanceFactory factory =
- * mock(PdxInstanceFactory.class); PdxInstance pi = mock(PdxInstance.class);
- * when(factory.create()).thenReturn(pi);
when(cache.createPdxInstanceFactory("no class",
- * false)).thenReturn(factory);
- *
- * Region region = Fakes.region(regionName, cache); Object key = "1";
PdxInstance value =
- * this.mgr.read(region, key); ArgumentCaptor<String> sqlCaptor =
- * ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
assertThat(sqlCaptor.getValue())
- * .isEqualTo("SELECT * FROM " + regionName + " WHERE " + ID_COLUMN_NAME + "
= ?");
- * ArgumentCaptor<Object> objectCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(this.preparedStatement, times(1)).setObject(anyInt(),
objectCaptor.capture());
- * List<Object> allObjects = objectCaptor.getAllValues();
- * assertThat(allObjects.get(0)).isEqualTo("1");
assertThat(value).isSameAs(pi);
- * ArgumentCaptor<String> fieldNameCaptor =
ArgumentCaptor.forClass(String.class);
- * ArgumentCaptor<Object> fieldValueCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(factory, times(2)).writeField(fieldNameCaptor.capture(),
fieldValueCaptor.capture(),
- * any());
assertThat(fieldNameCaptor.getAllValues()).isEqualTo(Arrays.asList("name",
"age"));
- *
assertThat(fieldValueCaptor.getAllValues()).isEqualTo(Arrays.asList("Emp1",
21)); }
- *
- * @Test public void verifyReadWithValueClassName() throws SQLException {
- * createManager("valueClassName-" + regionName, "myValueClass");
GemFireCacheImpl cache =
- * Fakes.cache(); PdxInstanceFactory factory =
mock(PdxInstanceFactory.class); PdxInstance pi =
- * mock(PdxInstance.class); when(factory.create()).thenReturn(pi);
- * when(cache.createPdxInstanceFactory("myValueClass")).thenReturn(factory);
- *
- * Region region = Fakes.region(regionName, cache); Object key = "1";
PdxInstance value =
- * this.mgr.read(region, key); ArgumentCaptor<String> sqlCaptor =
- * ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
assertThat(sqlCaptor.getValue())
- * .isEqualTo("SELECT * FROM " + regionName + " WHERE " + ID_COLUMN_NAME + "
= ?");
- * ArgumentCaptor<Object> objectCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(this.preparedStatement, times(1)).setObject(anyInt(),
objectCaptor.capture());
- * List<Object> allObjects = objectCaptor.getAllValues();
- * assertThat(allObjects.get(0)).isEqualTo("1");
assertThat(value).isSameAs(pi);
- * ArgumentCaptor<String> fieldNameCaptor =
ArgumentCaptor.forClass(String.class);
- * ArgumentCaptor<Object> fieldValueCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(factory, times(2)).writeField(fieldNameCaptor.capture(),
fieldValueCaptor.capture(),
- * any());
assertThat(fieldNameCaptor.getAllValues()).isEqualTo(Arrays.asList("name",
"age"));
- *
assertThat(fieldValueCaptor.getAllValues()).isEqualTo(Arrays.asList("Emp1",
21)); }
- *
- * @Test public void verifyReadWithKeyPartOfValue() throws SQLException {
- * createManager("isKeyPartOfValue-" + regionName, "true"); GemFireCacheImpl
cache =
- * Fakes.cache(); PdxInstanceFactory factory =
mock(PdxInstanceFactory.class); PdxInstance pi =
- * mock(PdxInstance.class); when(factory.create()).thenReturn(pi);
- * when(cache.createPdxInstanceFactory("no class",
false)).thenReturn(factory);
- *
- * Region region = Fakes.region(regionName, cache); Object key = "1";
PdxInstance value =
- * this.mgr.read(region, key); ArgumentCaptor<String> sqlCaptor =
- * ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
assertThat(sqlCaptor.getValue())
- * .isEqualTo("SELECT * FROM " + regionName + " WHERE " + ID_COLUMN_NAME + "
= ?");
- * ArgumentCaptor<Object> objectCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(this.preparedStatement, times(1)).setObject(anyInt(),
objectCaptor.capture());
- * List<Object> allObjects = objectCaptor.getAllValues();
- * assertThat(allObjects.get(0)).isEqualTo("1");
assertThat(value).isSameAs(pi);
- * ArgumentCaptor<String> fieldNameCaptor =
ArgumentCaptor.forClass(String.class);
- * ArgumentCaptor<Object> fieldValueCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(factory, times(3)).writeField(fieldNameCaptor.capture(),
fieldValueCaptor.capture(),
- * any());
assertThat(fieldNameCaptor.getAllValues()).isEqualTo(Arrays.asList("id", "name",
- * "age"));
assertThat(fieldValueCaptor.getAllValues()).isEqualTo(Arrays.asList("1",
"Emp1", 21));
- * }
- *
- * @Test public void verifyRegionToTable() throws SQLException { String
tableName = "mySqlTable";
- * createManagerWithTableName(tableName, "regionToTable-" + regionName,
tableName);
- * GemFireCacheImpl cache = Fakes.cache(); PdxInstanceFactory factory =
- * mock(PdxInstanceFactory.class); PdxInstance pi = mock(PdxInstance.class);
- * when(factory.create()).thenReturn(pi);
when(cache.createPdxInstanceFactory("no class",
- * false)).thenReturn(factory);
- *
- * Region region = Fakes.region(regionName, cache); Object key = "1";
PdxInstance value =
- * this.mgr.read(region, key); ArgumentCaptor<String> sqlCaptor =
- * ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
assertThat(sqlCaptor.getValue())
- * .isEqualTo("SELECT * FROM " + tableName + " WHERE " + ID_COLUMN_NAME + "
= ?");
- * ArgumentCaptor<Object> objectCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(this.preparedStatement, times(1)).setObject(anyInt(),
objectCaptor.capture());
- * List<Object> allObjects = objectCaptor.getAllValues();
- * assertThat(allObjects.get(0)).isEqualTo("1");
assertThat(value).isSameAs(pi);
- * ArgumentCaptor<String> fieldNameCaptor =
ArgumentCaptor.forClass(String.class);
- * ArgumentCaptor<Object> fieldValueCaptor =
ArgumentCaptor.forClass(Object.class);
- * verify(factory, times(2)).writeField(fieldNameCaptor.capture(),
fieldValueCaptor.capture(),
- * any());
assertThat(fieldNameCaptor.getAllValues()).isEqualTo(Arrays.asList("name",
"age"));
- *
assertThat(fieldValueCaptor.getAllValues()).isEqualTo(Arrays.asList("Emp1",
21)); }
- *
- * @Test public void verifyFieldToColumn() throws SQLException {
createManager("fieldToColumn",
- * "name:columnName, " + regionName + ":age:columnAge"); GemFireCacheImpl
cache = Fakes.cache();
- * Region region = Fakes.region(regionName, cache); PdxInstanceImpl pdx1 =
mockPdxInstance("Emp1",
- * 21); this.mgr.write(region, Operation.CREATE, "1", pdx1);
- * verify(this.preparedStatement).execute(); ArgumentCaptor<String>
sqlCaptor =
- * ArgumentCaptor.forClass(String.class);
- * verify(this.connection).prepareStatement(sqlCaptor.capture());
- * assertThat(sqlCaptor.getValue()).isEqualTo("INSERT INTO " + regionName +
"(" + "columnName" +
- * ", " + "columnAge" + ", " + ID_COLUMN_NAME + ") VALUES (?,?,?)");
ArgumentCaptor<Object>
- * objectCaptor = ArgumentCaptor.forClass(Object.class);
verify(this.preparedStatement,
- * times(3)).setObject(anyInt(), objectCaptor.capture()); List<Object>
allObjects =
- * objectCaptor.getAllValues();
assertThat(allObjects.get(0)).isEqualTo("Emp1");
- * assertThat(allObjects.get(1)).isEqualTo(21);
assertThat(allObjects.get(2)).isEqualTo("1"); }
- */
+ private ResultSet getPrimaryKeysMetadData() throws SQLException {
+ DatabaseMetaData metadata = mock(DatabaseMetaData.class);
+ when(connection.getMetaData()).thenReturn(metadata);
+ ResultSet resultSet = mock(ResultSet.class);
+ when(resultSet.next()).thenReturn(true).thenReturn(false);
+ when(resultSet.getString("TABLE_NAME")).thenReturn(TABLE_NAME);
+ when(metadata.getTables(any(), any(), any(), any())).thenReturn(resultSet);
+ ResultSet primaryKeys = mock(ResultSet.class);
+ when(metadata.getPrimaryKeys(any(), any(),
anyString())).thenReturn(primaryKeys);
+ when(primaryKeys.getString("COLUMN_NAME")).thenReturn(KEY_COLUMN);
+ return primaryKeys;
+ }
}
--
To stop receiving notification emails like this one, please contact
['"[email protected]" <[email protected]>'].