Java Code Examples for com.mockrunner.mock.jdbc.JDBCMockObjectFactory

The following examples show how to use com.mockrunner.mock.jdbc.JDBCMockObjectFactory. These examples are extracted from open source projects. 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
/**
 * Set up the metadata for Hibernate to generate schema statements.
 */
@Before
public void setup() throws SQLException {
  JDBCMockObjectFactory jdbcMockObjectFactory = new JDBCMockObjectFactory();
  jdbcMockObjectFactory.registerMockDriver();

  this.connection = jdbcMockObjectFactory.getMockConnection();
  this.connection.setMetaData(MockJdbcUtils.metaDataBuilder().build());
  jdbcMockObjectFactory.getMockDriver().setupConnection(this.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-drop")
      .build();
}
 
Example 2
/**
 * Set up the metadata for Hibernate to generate schema statements.
 */
@Before
public void setup() throws SQLException {
  JDBCMockObjectFactory jdbcMockObjectFactory = new JDBCMockObjectFactory();
  jdbcMockObjectFactory.registerMockDriver();

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

  this.registry = new StandardServiceRegistryBuilder()
      .applySetting("hibernate.dialect", SpannerDialect.class.getName())
      .applySetting("hibernate.connection.url", "unused")
      .build();

  this.metadata =
      new MetadataSources(this.registry).addAnnotatedClass(TestEntity.class).buildMetadata();
}
 
Example 3
/**
 * 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 4
/**
 * Set up the metadata for Hibernate to generate schema statements.
 */
@Before
public void setup() {
  this.jdbcMockObjectFactory = new JDBCMockObjectFactory();
  this.jdbcMockObjectFactory.registerMockDriver();

  mockConnection = this.jdbcMockObjectFactory.createMockConnection();

  this.jdbcMockObjectFactory
      .getMockDriver()
      .setupConnection(mockConnection);

  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", "update")
      .build();
}
 
Example 5
Source Project: tessera   Source File: CmdLineExecutorTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void exportTypeJdbc() throws Exception {

    final JDBCMockObjectFactory mockObjectFactory = new JDBCMockObjectFactory();

    try {
        mockObjectFactory.registerMockDriver();

        final String dbConfigPath = getClass().getResource("/dbconfig.properties").getFile();

        final Path inputFile = Paths.get(getClass().getResource("/dir/").toURI());

        final String[] args =
                new String[] {
                    "-storetype",
                    "dir",
                    "-inputpath",
                    inputFile.toString(),
                    "-outputfile",
                    outputPath.toString(),
                    "-exporttype",
                    "jdbc",
                    "-dbconfig",
                    dbConfigPath,
                    "-dbpass",
                    "-dbuser"
                };

        commandLine.execute(args);
        final CliResult result = commandLine.getExecutionResult();
    } finally {
        mockObjectFactory.restoreDrivers();
    }
}
 
Example 6
Source Project: fastods   Source File: ResultSetTester.java    License: 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 7
Source Project: macrobase   Source File: SQLIngesterTest.java    License: 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());
}