当前位置: 首页>>代码示例>>Java>>正文


Java MockResultSet.addColumn方法代码示例

本文整理汇总了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"));
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:22,代码来源:PatchTableTest.java

示例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());
}
 
开发者ID:yandex,项目名称:graphouse,代码行数:31,代码来源:MetricDataRowCallbackHandlerTest.java

示例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());
}
 
开发者ID:yandex,项目名称:graphouse,代码行数:29,代码来源:MetricDataRowCallbackHandlerTest.java

示例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++;
    }
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:33,代码来源:RedisClientTest.java

示例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++;
    }
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:38,代码来源:RedisClientTest.java

示例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);
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:32,代码来源:RedisClientTest.java

示例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);
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:33,代码来源:RedisClientTest.java

示例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));
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:28,代码来源:RedisClientTest.java

示例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++;
    }
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:29,代码来源:RedisClientTest.java

示例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++;
    }
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:34,代码来源:RedisClientTest.java

示例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++;
    }
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:34,代码来源:RedisClientTest.java

示例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++;
    }
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:33,代码来源:RedisClientTest.java

示例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++;
    }
}
 
开发者ID:powerreviews,项目名称:redshift-jdbc-caching-driver,代码行数:38,代码来源:RedisClientTest.java

示例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);
}
 
开发者ID:nortal,项目名称:petit,代码行数:10,代码来源:GeneratedKeysTest.java

示例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);
}
 
开发者ID:nortal,项目名称:petit,代码行数:10,代码来源:GeneratedKeysTest.java


注:本文中的com.mockrunner.mock.jdbc.MockResultSet.addColumn方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。