Java源码示例:com.mockrunner.mock.jdbc.MockResultSet

示例1
/**
 * Constructs a mock Column metadata {@link ResultSet} describing fake columns of the tables.
 */
private static ResultSet createColumnMetadataResultSet(String... tableNames) {
  MockResultSet mockResultSet = initResultSet(COLUMN_METADATA_LABELS);

  for (int i = 0; i < tableNames.length; i++) {
    Object[] row = new Object[COLUMN_METADATA_LABELS.length];
    Arrays.fill(row, "");
    row[2] = tableNames[i];
    row[3] = "column";
    row[4] = Types.VARCHAR;
    row[5] = "string(255)";
    row[6] = 255;
    row[7] = 0;
    row[8] = 0;
    mockResultSet.addRow(row);
  }

  return mockResultSet;
}
 
示例2
@Test
public void testEmpty() throws Exception {
    MockResultSet resultSet = new MockResultSet("data");

    StringWriter stringWriter = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(stringWriter);
    jsonWriter.beginObject();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(0, 3, 1), Collections.emptySet()
    );

    while (resultSet.next()) {
        handler.processRow(resultSet);
    }
    handler.finish();
    jsonWriter.endObject();

    Assert.assertEquals("{}", stringWriter.toString());

}
 
示例3
/**
 * Validates that the system recognizes an existing patches table.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testVerifyPatchesTable() throws Exception
{
    // Test-specific setup
    handler = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = handler.createResultSet();
    
    MockDatabaseMetaData mdmd = (MockDatabaseMetaData) conn.getMetaData();
    MockResultSet mrs = handler.createResultSet();
    mrs.addRow(new String[]{"", "", "", "system_name"});
    mrs.addRow(new String[]{"", "", "", "patch_level"});
    mdmd.setPrimaryKeys(mrs);
    handler.prepareGlobalResultSet(rs);
    rs.addRow(new Integer[] {new Integer(13)});
    
    table.createPatchStoreIfNeeded();
    
    commonVerifications();
    verifyNotCommitted();
    verifyPreparedStatementParameter(0, 1, "milestone");
    verifyPreparedStatementNotPresent(table.getSql("patches.upgrade"));
    verifyPreparedStatementNotPresent(table.getSql("patches.create"));
}
 
示例4
/**
 * Validates that the system recognizes an existing patches table.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testVerifyAndUpgradePatchesTable() throws Exception
{
    // Test-specific setup
    handler = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = handler.createResultSet();
    
    MockDatabaseMetaData mdmd = (MockDatabaseMetaData) conn.getMetaData();
    MockResultSet mrs = handler.createResultSet();
    mrs.addRow(new String[]{"", "", "", "system_name"});
    mdmd.setPrimaryKeys(mrs);
    handler.prepareGlobalResultSet(rs);
    rs.addRow(new Integer[] {new Integer(13)});
    
    table.createPatchStoreIfNeeded();
    
    commonVerifications();
    verifyCommitted();
    verifyPreparedStatementParameter(0, 1, "milestone");
    verifyPreparedStatementPresent(table.getSql("patches.upgrade"));
    verifyPreparedStatementNotPresent(table.getSql("patches.create"));
}
 
示例5
/**
 * Validates that <code>getPatchLevel</code> works on an existing system.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testGetPatchLevel() throws Exception
{
    // Test-specific setup
    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.addRow(new Integer[]{new Integer(13)});
    handler.prepareGlobalResultSet(rs);

    int i = table.getPatchLevel();

    assertEquals(13, i);
    commonVerifications();
    verifyNotCommitted();
    verifyPreparedStatementParameter(1, 1, "milestone");
    verifyPreparedStatementNotPresent(table.getSql("patches.upgrade"));
    verifyPreparedStatementNotPresent(table.getSql("level.create"));
}
 
示例6
/**
 * Validates that <code>getPatchLevel</code> works on a new system.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testGetPatchLevelFirstTime() throws Exception
{
    // Test-specific setup
    handler = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = handler.createResultSet();
    // empty result set
    handler.prepareResultSet(table.getSql("level.read"), rs);
    handler.prepareThrowsSQLException(table.getSql("level.table.exists"));

    int i = table.getPatchLevel();

    assertEquals(0, i);
    commonVerifications();
    verifyPreparedStatementPresent(table.getSql("level.create"));
}
 
示例7
/**
 * Validates that the patch level can be updated.
 *  
 * @throws Exception if an unexpected error occurs
 */
public void testUpdatePatchLevel() throws Exception
{
    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.addRow(new Integer[]{new Integer(12)});
    handler.prepareResultSet(table.getSql("level.read"), rs, new String[]{"milestone"});

    table.updatePatchLevel(13);
    
    verifyPreparedStatementParameter(table.getSql("level.update"), 1, new Integer(13));
    verifyPreparedStatementParameter(table.getSql("level.update"), 2, "milestone");
    commonVerifications();
    verifyCommitted();
}
 
示例8
/**
 * Validates that <code>isPatchTableLocked</code> works when no lock exists.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testIsPatchTableNotLocked() throws Exception
{
    // Test-specific setup
    // Return a non-empty set in response to the patch lock query
    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.addRow(new String[]{"F"});
    handler.prepareResultSet(table.getSql("lock.read"), rs, new String[]{"milestone", "milestone"});
    
    assertFalse(table.isPatchStoreLocked());
    commonVerifications();
    verifyNotCommitted();
}
 
示例9
/**
 * Validates that <code>isPatchTableLocked</code> works when a lock already exists.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testIsPatchTableLocked() throws Exception
{
    // Test-specific setup
    // Return a non-empty set in response to the patch lock query
    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.addRow(new String[]{"T"});
    handler.prepareResultSet(table.getSql("lock.read"), rs, new String[]{"milestone", "milestone"});
    
    assertTrue(table.isPatchStoreLocked());
    commonVerifications();
    verifyNotCommitted();
}
 
示例10
/**
 * Validates that the patches table can be locked as long as no other lock
 * is in place.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testLockPatchTableWhenNotAlreadyLocked() throws Exception
{
    // Test-specific setup
    // Return an empty set in response to the patch lock query
    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();
    handler.prepareUpdateCount(table.getSql("lock.obtain"), 1, new String[] {"milestone", "milestone"});
    
    table.lockPatchStore();
    verifyPreparedStatementParameter(table.getSql("lock.obtain"), 1, "milestone");
    verifyPreparedStatementParameter(table.getSql("lock.obtain"), 2, "milestone");
    commonVerifications();
    verifyCommitted();
}
 
示例11
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"));
}
 
示例12
/**
 * Constructs a mock Table metadata {@link ResultSet} describing table names.
 */
private static ResultSet createTableMetadataResultSet(String... tableNames) {
  MockResultSet mockResultSet = initResultSet(TABLE_METADATA_COLUMNS);

  for (int i = 0; i < tableNames.length; i++) {
    String[] row = new String[TABLE_METADATA_COLUMNS.length];
    Arrays.fill(row, "");
    row[2] = tableNames[i];
    row[3] = "TABLE";
    mockResultSet.addRow(row);
  }

  return mockResultSet;
}
 
示例13
/**
 * Constructs a {@link MockResultSet} containing database metadata about indices for testing.
 */
private static ResultSet createIndexMetadataResultSet(String... indexNames) {
  MockResultSet mockResultSet = initResultSet("INDEX_NAME");

  for (int i = 0; i < indexNames.length; i++) {
    String[] row = new String[]{indexNames[i]};
    mockResultSet.addRow(row);
  }

  return mockResultSet;

}
 
示例14
@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();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(100, 280, 60), Collections.emptySet()
    );

    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());
}
 
示例15
@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();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(0, 3, 1), Collections.emptySet()
    );

    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());
}
 
示例16
@Test
public void testEmptyMetricFilling() throws Exception {
    MockResultSet resultSet = new MockResultSet("data");
    resultSet.addColumn("metric", new String[]{"name1", "name1"});
    resultSet.addColumn("ts", new Integer[]{100, 160});
    resultSet.addColumn("value", new Double[]{33.33, 42.0});

    StringWriter stringWriter = new StringWriter();
    JsonWriter jsonWriter = new JsonWriter(stringWriter);
    jsonWriter.beginObject();

    MetricDataRowCallbackHandler handler = new MetricDataRowCallbackHandler(
        jsonWriter, new MetricDataQueryParams(100, 280, 60), new LinkedHashSet<>(Arrays.asList("name1", "name2", "name3"))
    );

    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, Double.NaN, Double.NaN));
    expected.add("name3", createMetric(100, 280, 60, Double.NaN, Double.NaN, Double.NaN));

    Assert.assertEquals(expected.toString(), stringWriter.toString());
}
 
示例17
/**
 * Validates that an <code>IllegalStateException</code> is thrown when trying
 * to lock an already locked patches table.
 * 
 * @throws Exception if an unexpected error occurs
 */
public void testLockPatchTableWhenAlreadyLocked() throws Exception
{
    // Test-specific setup
    // Return a non-empty set in response to the patch lock query
    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);
    
    handler.prepareUpdateCount(table.getSql("lock.obtain"), 0, new String[] {"milestone", "milestone"});
    
    try
    {
        table.lockPatchStore();
        fail("Expected an IllegalStateException since a lock already exists.");
    }
    catch (IllegalStateException e)
    {
        // Expected
    }
    
    verifyPreparedStatementParameter(table.getSql("lock.obtain"), 1, "milestone");
    verifyPreparedStatementParameter(table.getSql("lock.obtain"), 2, "milestone");
    commonVerifications();
    verifyCommitted();
}
 
示例18
public void testIsPatchApplied() throws MigrationException
{
    handler = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = handler.createResultSet();
    rs.addRow(new Integer[]{new Integer(3)});
    handler.prepareGlobalResultSet(rs);

    assertEquals(true, table.isPatchApplied(3));
    commonVerifications();
    verifyPreparedStatementPresent(table.getSql("level.exists"));

}
 
示例19
public void testIsPatchAppliedWithMissingLevel() throws MigrationException
{
    handler = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = handler.createResultSet();
    handler.prepareGlobalResultSet(rs);

    assertEquals(false, table.isPatchApplied(3));
    commonVerifications();
    verifyPreparedStatementPresent(table.getSql("level.exists"));
}
 
示例20
/**
 * @param head the header
 * @param rows the rows of the RS
 * @return a RS object
 */
public MockResultSet createResultSet(final Iterable<String> head,
                                     final Iterable<List<Object>> rows) {
    final MockResultSet rs = this.resultSetHandler.createResultSet();
    for (final String name : head) {
        rs.addColumn(name);
    }

    this.resultSetHandler.prepareGlobalResultSet(rs);
    for (final List<Object> row : rows) {
        rs.addRow(row);
    }
    return rs;
}
 
示例21
@Benchmark
public void convertWithSpringData(Blackhole sink) throws Exception {

	MockResultSet resultSet = new MockResultSet("book");
	resultSet.addColumns(columns);
	resultSet.addRow(values);
	resultSet.next();

	sink.consume(this.bookEntityMapper.mapRow(resultSet, 1));
}
 
示例22
/**
 * Build a mock implementation of Result using Mockito
 */
private ResultSet buildMockResultSet()
    throws Exception {

  MockResultSet mrs = new MockResultSet(StringUtils.EMPTY);
  for (MockJdbcColumn column : COLUMNS) {
    mrs.addColumn(column.getColumnName(), ImmutableList.of(column.getValue()));
  }
  return mrs;
}
 
示例23
/**
 * Build a mock implementation of Result using Mockito
 */
private ResultSet buildMockResultSet() {

  MockResultSet mrs = new MockResultSet(StringUtils.EMPTY);
  for (MockJdbcColumn column : COLUMNS) {
    mrs.addColumn(column.getColumnName(), ImmutableList.of(column.getValue()));
  }
  return mrs;
}
 
示例24
/**
 * Test doing migrations with a lock race from a quick cluster
 *
 * @throws Exception if there is a problem
 */
public void testDoMigrationsWithLockRace() throws Exception {
    // Setup enough for the first
    PreparedStatementResultSetHandler h = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = h.createResultSet();
    rs.addRow(new Integer[]{new Integer(0)});
    h.prepareGlobalResultSet(rs);


    MockControl mockControl = MockControl.createStrictControl(PatchInfoStore.class);
    PatchInfoStore patchStore = (PatchInfoStore) mockControl.getMock();

    // First they see if it is locked, and it is, so they spin
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);

    // Second they see if it is locked again, and it isn't, so they try and fail and spin
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(false);
    patchStore.getPatchLevel();
    mockControl.setReturnValue(0);
    patchStore.lockPatchStore();
    mockControl.setThrowable(new IllegalStateException("The table is already locked"));

    // Finally they see if it is locked again, and it isn't, and it works
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(false);


    patchStore.getPatchLevel();
    mockControl.setReturnValue(2, MockControl.ONE_OR_MORE);
    patchStore.lockPatchStore();

    IMocksControl migrationRunnerStrategyControl = createStrictControl();
    MigrationRunnerStrategy migrationStrategyMock = migrationRunnerStrategyControl.createMock(MigrationRunnerStrategy.class);
    expect(migrationStrategyMock.shouldMigrationRun(anyInt(), eq(patchStore))).andReturn(true).anyTimes();

    patchStore.updatePatchLevel(4);
    patchStore.updatePatchLevel(5);
    patchStore.updatePatchLevel(6);
    patchStore.updatePatchLevel(7);
    patchStore.unlockPatchStore();

    mockControl.replay();
    migrationRunnerStrategyControl.replay();

    TestJdbcMigrationLauncher testLauncher = new TestJdbcMigrationLauncher(context);
    testLauncher.getMigrationProcess().setMigrationRunnerStrategy(migrationStrategyMock);
    testLauncher.setLockPollMillis(0);
    testLauncher.setLockPollRetries(4);
    testLauncher.setIgnoreMigrationSuccessfulEvents(false);
    testLauncher.setPatchStore(patchStore);
    testLauncher.setPatchPath("com.tacitknowledge.util.migration.tasks.normal");
    testLauncher.doMigrations();
    mockControl.verify();
}
 
示例25
/**
 * Test doing migrations with a lock override
 *
 * @throws Exception if there is a problem
 */
public void testLockOverride() throws Exception {
    // Setup enough for the first
    PreparedStatementResultSetHandler h = conn.getPreparedStatementResultSetHandler();
    MockResultSet rs = h.createResultSet();
    rs.addRow(new Integer[]{new Integer(0)});
    h.prepareGlobalResultSet(rs);


    MockControl mockControl = MockControl.createStrictControl(PatchInfoStore.class);
    PatchInfoStore patchStore = (PatchInfoStore) mockControl.getMock();

    // First they see if it is locked three times, and it is, so they spin
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(true);

    // after the third time, they unlock it
    patchStore.unlockPatchStore();

    // now the lock succeeds
    patchStore.isPatchStoreLocked();
    mockControl.setReturnValue(false);
    patchStore.getPatchLevel();
    mockControl.setReturnValue(2);
    patchStore.lockPatchStore();

    IMocksControl migrationRunnerStrategyControl = createStrictControl();
    MigrationRunnerStrategy migrationStrategyMock = migrationRunnerStrategyControl.createMock(MigrationRunnerStrategy.class);
    expect(migrationStrategyMock.shouldMigrationRun(anyInt(), eq(patchStore))).andReturn(true).anyTimes();

    patchStore.updatePatchLevel(4);
    patchStore.updatePatchLevel(5);
    patchStore.updatePatchLevel(6);
    patchStore.updatePatchLevel(7);
    patchStore.unlockPatchStore();

    TestJdbcMigrationLauncher testLauncher = new TestJdbcMigrationLauncher(context);
    testLauncher.getMigrationProcess().setMigrationRunnerStrategy(migrationStrategyMock);
    testLauncher.setLockPollMillis(0);
    testLauncher.setLockPollRetries(3);
    testLauncher.setIgnoreMigrationSuccessfulEvents(false);
    testLauncher.setPatchStore(patchStore);
    testLauncher.setPatchPath("com.tacitknowledge.util.migration.tasks.normal");

    mockControl.replay();
    migrationRunnerStrategyControl.replay();
    testLauncher.doMigrations();
    mockControl.verify();
}
 
示例26
@Test
@SuppressWarnings("unchecked")
public final void testRealDataSets() throws IOException, FastOdsException {
    final Logger logger = PowerMock.createNiceMock(Logger.class);
    final MockResultSet rs = this.tester
            .createResultSet(Arrays.asList("number", "word", "code"),
                    Arrays.asList(Arrays.<Object>asList(13, "a", "13a"),
                            Arrays.<Object>asList(14, "b", "14b"),
                            Arrays.<Object>asList(15, "c", "15c")));
    final ResultSetDataWrapper wrapper =
            ResultSetDataWrapper.builder("range", rs).logger(this.logger).noAutoFilter()
                    .build();

    PowerMock.resetAll();
    EasyMock.expect(this.walker.rowIndex()).andReturn(0);
    EasyMock.expect(this.walker.colIndex()).andReturn(0);

    this.walker.setStringValue("number");
    this.walker.setStyle(EasyMock.isA(TableCellStyle.class));
    this.walker.next();
    this.walker.setStringValue("word");
    this.walker.setStyle(EasyMock.isA(TableCellStyle.class));
    this.walker.next();
    this.walker.setStringValue("code");
    this.walker.setStyle(EasyMock.isA(TableCellStyle.class));
    this.walker.next();
    this.walker.nextRow();
    this.walker.to(0);
    this.walker.setCellValue(FloatValue.from(13));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("a"));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("13a"));
    this.walker.next();
    this.walker.nextRow();
    this.walker.to(0);
    this.walker.setCellValue(FloatValue.from(14));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("b"));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("14b"));
    this.walker.next();
    this.walker.nextRow();
    this.walker.to(0);
    this.walker.setCellValue(FloatValue.from(15));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("c"));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("15c"));
    this.walker.next();
    this.walker.nextRow();
    this.walker.to(0);
    this.walker.setStringValue("");
    this.walker.next();
    this.walker.setStringValue("");
    this.walker.next();
    this.walker.setStringValue("");
    this.walker.next();
    this.walker.nextRow();

    PowerMock.replayAll();
    wrapper.addToTable(this.walker);

    PowerMock.verifyAll();
}
 
示例27
@Test
@SuppressWarnings("unchecked")
public final void testWrapperWithColumnHints()
        throws IOException, FastOdsException {
    final Logger logger = PowerMock.createNiceMock(Logger.class);
    final MockResultSet rs = this.tester
            .createResultSet(Arrays.asList("number", "word", "code"),
                    Arrays.asList(Arrays.<Object>asList(0.13, "a", "13a")));
    final ResultSetDataWrapper wrapper =
            ResultSetDataWrapper.builder("range", rs).logger(this.logger).noAutoFilter()
                    .typeValue(0, CellType.PERCENTAGE).build();

    PowerMock.resetAll();
    EasyMock.expect(this.walker.rowIndex()).andReturn(0);
    EasyMock.expect(this.walker.colIndex()).andReturn(0);

    this.walker.setStringValue("number");
    this.walker.setStyle(EasyMock.isA(TableCellStyle.class));
    this.walker.next();
    this.walker.setStringValue("word");
    this.walker.setStyle(EasyMock.isA(TableCellStyle.class));
    this.walker.next();
    this.walker.setStringValue("code");
    this.walker.setStyle(EasyMock.isA(TableCellStyle.class));
    this.walker.next();
    this.walker.nextRow();
    this.walker.to(0);
    this.walker.setCellValue(PercentageValue.from(0.13));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("a"));
    this.walker.next();
    this.walker.setCellValue(StringValue.from("13a"));
    this.walker.next();
    this.walker.nextRow();
    this.walker.to(0);
    this.walker.setStringValue("");
    this.walker.next();
    this.walker.setStringValue("");
    this.walker.next();
    this.walker.setStringValue("");
    this.walker.next();
    this.walker.nextRow();

    PowerMock.replayAll();
    wrapper.addToTable(this.walker);

    PowerMock.verifyAll();
}
 
示例28
private DataWrapper createWrapper(final Iterable<String> head,
                                  final Iterable<List<Object>> rows, final int max) {
    final MockResultSet rs = this.tester.createResultSet(head, rows);
    return ResultSetDataWrapper.builder("range", rs).logger(this.logger).headerStyle(this.tcls)
            .max(max).noAutoFilter().build();
}
 
示例29
@Test
public void testSchema() throws Exception {
    JDBCMockObjectFactory factory = new JDBCMockObjectFactory();
    factory.registerMockDriver();
    MockConnection connection = factory.getMockConnection();
    StatementResultSetHandler statementHandler =
            connection.getStatementResultSetHandler();
    MockResultSet result = statementHandler.createResultSet();
    result.setFetchSize(0);

    MockResultSetMetaData metaData = new MockResultSetMetaData();

    Map<String, String> fakeColumnMap = new HashMap<>();
    fakeColumnMap.put("test1", "numeric");
    fakeColumnMap.put("test2", "varchar");
    fakeColumnMap.put("test3", "int8");

    Set<String> fakeColumns = fakeColumnMap.keySet();

    metaData.setColumnCount(fakeColumnMap.size());
    int i = 1;
    for (Map.Entry<String, String> fc : fakeColumnMap.entrySet()) {
        metaData.setColumnName(i, fc.getKey());
        metaData.setColumnTypeName(i, fc.getValue());
        i++;
    }

    result.setResultSetMetaData(metaData);

    statementHandler.prepareGlobalResultSet(result);

    MacroBaseConf conf = new MacroBaseConf();
    conf.set(MacroBaseConf.ATTRIBUTES, Lists.newArrayList(fakeColumns));
    conf.set(MacroBaseConf.METRICS, new ArrayList<>());
    conf.set(MacroBaseConf.BASE_QUERY, "SELECT * FROM test;");


    SQLIngester loader = new TestSQLIngester(conf, connection);
    Schema schema = loader.getSchema("foo");

    for (Schema.SchemaColumn sc : schema.getColumns()) {
        assertTrue(fakeColumns.contains(sc.getName()));
        assertEquals(fakeColumnMap.get(sc.getName()), sc.getType());
        fakeColumns.remove(sc.getName());
    }

    assertTrue(fakeColumns.isEmpty());
}
 
示例30
private ResultSet buildMockResultSet() throws Exception {

    MockResultSet mrs = new MockResultSet(StringUtils.EMPTY);

    for (MockJdbcColumn column : COLUMNS) {
      mrs.addColumn(column.getColumnName(), ImmutableList.of(column.getValue()));
    }

    return mrs;
  }