com.mockrunner.mock.jdbc.MockConnection Java Examples

The following examples show how to use com.mockrunner.mock.jdbc.MockConnection. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GeneratedSelectStatementsTests.java    From google-cloud-spanner-hibernate with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Set up the metadata for Hibernate to generate schema statements.
 */
@Before
public void setup() throws SQLException {
  this.jdbcMockObjectFactory = new JDBCMockObjectFactory();
  this.jdbcMockObjectFactory.registerMockDriver();

  MockConnection connection = this.jdbcMockObjectFactory.getMockConnection();
  connection.setMetaData(MockJdbcUtils.metaDataBuilder().build());
  this.jdbcMockObjectFactory.getMockDriver()
      .setupConnection(connection);

  this.registry = new StandardServiceRegistryBuilder()
      .applySetting("hibernate.dialect", SpannerDialect.class.getName())
      // must NOT set a driver class name so that Hibernate will use java.sql.DriverManager
      // and discover the only mock driver we have set up.
      .applySetting("hibernate.connection.url", "unused")
      .applySetting("hibernate.connection.username", "unused")
      .applySetting("hibernate.connection.password", "unused")
      .applySetting("hibernate.hbm2ddl.auto", "create")
      .build();

  this.metadata =
      new MetadataSources(this.registry).addAnnotatedClass(TestEntity.class)
          .addAnnotatedClass(SubTestEntity.class).buildMetadata();
}
 
Example #2
Source File: SqlScriptMigrationTaskTest.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
    * {@inheritDoc}
    */
   protected void setUp() throws Exception
   {
super.setUp();

MockConnection conn = getJDBCMockObjectFactory().getMockConnection();

context = new DataSourceMigrationContext();
context.setDataSource(new ConnectionWrapperDataSource(conn));
context.setSystemName("milestone");
context.setDatabaseType(new DatabaseType("postgres"));
   }
 
Example #3
Source File: ResultSetTester.java    From fastods with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @return a new ResultSetTester
 */
public static ResultSetTester create() {
    final MockConnection connection = new JDBCMockObjectFactory().getMockConnection();
    return new ResultSetTester(connection.getStatementResultSetHandler());
}
 
Example #4
Source File: SQLIngesterTest.java    From macrobase with Apache License 2.0 4 votes vote down vote up
@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());
}