本文整理汇总了Java中com.mockrunner.mock.jdbc.MockResultSet.addColumn方法的典型用法代码示例。如果您正苦于以下问题:Java MockResultSet.addColumn方法的具体用法?Java MockResultSet.addColumn怎么用?Java MockResultSet.addColumn使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mockrunner.mock.jdbc.MockResultSet
的用法示例。
在下文中一共展示了MockResultSet.addColumn方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testPatchRetrievesSetWithPatchesApplied
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
public void testPatchRetrievesSetWithPatchesApplied () throws SQLException, MigrationException {
handler = conn.getPreparedStatementResultSetHandler();
MockDatabaseMetaData mdmd = (MockDatabaseMetaData) conn.getMetaData();
MockResultSet mrs = handler.createResultSet();
mrs.addRow(new String[]{"", "", "", "system_name"});
mrs.addRow(new String[]{"", "", "", "patch_level"});
mdmd.setPrimaryKeys(mrs);
MockResultSet rs = handler.createResultSet();
rs.addColumn("patch_level", new Object[]{1, 2});
handler.prepareGlobalResultSet(rs);
Set<Integer> expected = new HashSet<Integer>();
expected.add(1);
expected.add(2);
assertEquals(expected, table.getPatchesApplied());
commonVerifications();
verifyPreparedStatementPresent(table.getSql("patches.all"));
}
示例2: testHandler
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testHandler() throws Exception {
MockResultSet resultSet = new MockResultSet("data");
resultSet.addColumn("metric", new String[]{"name1", "name1", "name2", "name2"});
resultSet.addColumn("ts", new Integer[]{100, 160, 160, 220});
resultSet.addColumn("value", new Double[]{33.33, 42.0, 32.0, 77.7});
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(stringWriter);
jsonWriter.beginObject();
MetricDataService.MetricDataRowCallbackHandler handler = new MetricDataService.MetricDataRowCallbackHandler(
jsonWriter, 100, 280, 60
);
while (resultSet.next()) {
handler.processRow(resultSet);
}
handler.finish();
jsonWriter.endObject();
JsonObject expected = new JsonObject();
expected.add("name1", createMetric(100, 280, 60, 33.33, 42.0, Double.NaN));
expected.add("name2", createMetric(100, 280, 60, Double.NaN, 32.0, 77.7));
Assert.assertEquals(expected.toString(), stringWriter.toString());
}
示例3: testChNan
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testChNan() throws Exception {
MockResultSet resultSet = new MockResultSet("data");
resultSet.addColumn("metric", new String[]{"name1", "name1", "name1"});
resultSet.addColumn("ts", new Integer[]{0, 1, 2});
resultSet.addColumn("value", new Double[]{0.0, Double.NaN, 2.0});
StringWriter stringWriter = new StringWriter();
JsonWriter jsonWriter = new JsonWriter(stringWriter);
jsonWriter.beginObject();
MetricDataService.MetricDataRowCallbackHandler handler = new MetricDataService.MetricDataRowCallbackHandler(
jsonWriter, 0, 3, 1
);
while (resultSet.next()) {
handler.processRow(resultSet);
}
handler.finish();
jsonWriter.endObject();
JsonObject expected = new JsonObject();
expected.add("name1", createMetric(0, 3, 1, 0.0, Double.NaN, 2.0));
Assert.assertEquals(expected.toString(), stringWriter.toString());
}
示例4: testExecuteNonCachedQueryStatement
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteNonCachedQueryStatement() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost";
String sql = "select * from test";
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(null);
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1, 2});
resultSetMock.addColumn("columnB", new String[]{"record1", "record2"});
Statement statementMock = mock(Statement.class);
when(statementMock.executeQuery(sql)).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery(sql);
verify(jedisClientMock).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
int rowNumber = 1;
while(result.next()) {
assertEquals(rowNumber, result.getInt(1));
assertEquals("record" + rowNumber, result.getString(2));
rowNumber++;
}
}
示例5: testExecuteCachedQueryStatement
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteCachedQueryStatement() throws SQLException, IOException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost";
String sql = "select * from test";
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1, 2});
resultSetMock.addColumn("columnB", new String[]{"record1", "record2"});
CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.populate(resultSetMock);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(cachedRowSet);
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(bos.toByteArray());
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
Statement statementMock = mock(Statement.class);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock, never()).executeQuery(anyString());
verify(jedisClientMock, never()).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
int rowNumber = 1;
while(result.next()) {
assertEquals(rowNumber, result.getInt(1));
assertEquals("record" + rowNumber, result.getString(2));
rowNumber++;
}
}
示例6: testExecuteNonCachedQueryStatementSizeLimit
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteNonCachedQueryStatementSizeLimit() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost&redisObjectMaxSizeKB=10";
String sql = "select * from test";
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(null);
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
Integer[] columnA = new Integer[100];
String[] columnB = new String[100];
for(int i = 0; i < 100; i++) {
columnA[i] = i + 1;
columnB[i] = "record" + (i + 1);
}
resultSetMock.addColumn("columnA", columnA);
resultSetMock.addColumn("columnB", columnB);
Statement statementMock = mock(Statement.class);
when(statementMock.executeQuery(sql)).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery(sql);
verify(jedisClientMock, never()).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
}
示例7: testExecuteNonCachedQueryWithExpiration
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteNonCachedQueryWithExpiration() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost&redisExpiration=60";
String sql = "select * from test";
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(null);
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
Integer[] columnA = new Integer[100];
String[] columnB = new String[100];
for(int i = 0; i < 100; i++) {
columnA[i] = i + 1;
columnB[i] = "record" + (i + 1);
}
resultSetMock.addColumn("columnA", columnA);
resultSetMock.addColumn("columnB", columnB);
Statement statementMock = mock(Statement.class);
when(statementMock.executeQuery(sql)).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery(sql);
verify(jedisClientMock).set(any(byte[].class), any(byte[].class));
verify(jedisClientMock).expire(sql.getBytes(), 60);
assertNotNull(result);
}
示例8: testExecuteValidationQuery
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteValidationQuery() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost&poolValidationQuery=SELECT%201";
String sql = "select 1";
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(null);
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1});
Statement statementMock = mock(Statement.class);
when(statementMock.executeQuery(sql)).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery(sql);
verify(jedisClientMock, never()).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
result.next();
assertEquals(1, result.getInt(1));
}
示例9: testExecuteNoRedisConnection
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteNoRedisConnection() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost";
String sql = "select * from test";
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(null);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1, 2});
resultSetMock.addColumn("columnB", new String[]{"record1", "record2"});
Statement statementMock = mock(Statement.class);
when(statementMock.executeQuery(sql)).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery(sql);
assertNotNull(result);
int rowNumber = 1;
while(result.next()) {
assertEquals(rowNumber, result.getInt(1));
assertEquals("record" + rowNumber, result.getString(2));
rowNumber++;
}
}
示例10: testExecuteRedisGetConnectionIssue
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteRedisGetConnectionIssue() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost";
String sql = "select * from test";
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenThrow(new JedisConnectionException(""));
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1, 2});
resultSetMock.addColumn("columnB", new String[]{"record1", "record2"});
Statement statementMock = mock(Statement.class);
when(statementMock.executeQuery(sql)).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery(sql);
verify(jedisClientMock).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
int rowNumber = 1;
while(result.next()) {
assertEquals(rowNumber, result.getInt(1));
assertEquals("record" + rowNumber, result.getString(2));
rowNumber++;
}
}
示例11: testExecuteRedisSetConnectionIssue
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteRedisSetConnectionIssue() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost";
String sql = "select * from test";
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(null);
when(jedisClientMock.set(any(byte[].class), any(byte[].class))).thenThrow(new JedisConnectionException(""));
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1, 2});
resultSetMock.addColumn("columnB", new String[]{"record1", "record2"});
Statement statementMock = mock(Statement.class);
when(statementMock.executeQuery(sql)).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery(sql);
verify(jedisClientMock).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
int rowNumber = 1;
while(result.next()) {
assertEquals(rowNumber, result.getInt(1));
assertEquals("record" + rowNumber, result.getString(2));
rowNumber++;
}
}
示例12: testExecuteNonCachedPreparedStatement
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteNonCachedPreparedStatement() throws SQLException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost";
String sql = "select * from test";
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(null);
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1, 2});
resultSetMock.addColumn("columnB", new String[]{"record1", "record2"});
PreparedStatement statementMock = mock(PreparedStatement.class);
when(statementMock.executeQuery()).thenReturn(resultSetMock);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock).executeQuery();
verify(jedisClientMock).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
int rowNumber = 1;
while(result.next()) {
assertEquals(rowNumber, result.getInt(1));
assertEquals("record" + rowNumber, result.getString(2));
rowNumber++;
}
}
示例13: testExecuteCachedPreparedStatement
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
@Test
public void testExecuteCachedPreparedStatement() throws SQLException, IOException {
String jdbcUrl = "jdbc:redshiftcached://redshiftHost:redshiftPort/redshiftDb?redisUrl=redisHost";
String sql = "select * from test";
MockResultSet resultSetMock = new MockResultSet("myMockRS");
resultSetMock.addColumn("columnA", new Integer[]{1, 2});
resultSetMock.addColumn("columnB", new String[]{"record1", "record2"});
CachedRowSet cachedRowSet = new CachedRowSetImpl();
cachedRowSet.populate(resultSetMock);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
ObjectOutput out = new ObjectOutputStream(bos);
out.writeObject(cachedRowSet);
Jedis jedisClientMock = mock(Jedis.class);
when(jedisClientMock.get(sql.getBytes())).thenReturn(bos.toByteArray());
JedisFactory jedisFactoryMock = mock(JedisFactory.class);
when(jedisFactoryMock.createJedisClient(anyString(), anyInt())).thenReturn(jedisClientMock);
PreparedStatement statementMock = mock(PreparedStatement.class);
RedisClient redisClient = new RedisClient(jdbcUrl, null, jedisFactoryMock);
ResultSet result = redisClient.executeQuery(statementMock, sql);
verify(statementMock, never()).executeQuery(anyString());
verify(jedisClientMock, never()).set(any(byte[].class), any(byte[].class));
assertNotNull(result);
int rowNumber = 1;
while(result.next()) {
assertEquals(rowNumber, result.getInt(1));
assertEquals("record" + rowNumber, result.getString(2));
rowNumber++;
}
}
示例14: prepareResultsetReturningLong
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
private void prepareResultsetReturningLong() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
PreparedStatementResultSetHandler statementHandler = connection.getPreparedStatementResultSetHandler();
MockResultSet keysResult = statementHandler.createResultSet();
keysResult.addColumn("id");
keysResult.addRow(new Object[] {Long.valueOf(11L)});
statementHandler.prepareGeneratedKeys("insert", keysResult);
}
示例15: prepareResultsetReturningBigDecimal
import com.mockrunner.mock.jdbc.MockResultSet; //导入方法依赖的package包/类
private void prepareResultsetReturningBigDecimal() {
MockConnection connection = getJDBCMockObjectFactory().getMockConnection();
PreparedStatementResultSetHandler statementHandler = connection.getPreparedStatementResultSetHandler();
MockResultSet keysResult = statementHandler.createResultSet();
keysResult.addColumn("id");
keysResult.addRow(new Object[] {BigDecimal.valueOf(11L)});
statementHandler.prepareGeneratedKeys("insert", keysResult);
}