MongoDbTableProvider extends InMemoryMetaTableProvider { @Override public BeamSqlTable buildBeamSqlTable(Table table) { return new MongoDbTable(table); }  @Override String getTableType(); @Override BeamSqlTable buildBeamSqlTable(Table table);  }
@Test public void testBuildBeamSqlTable() { Table table = fakeTable("TEST", "mongodb: BeamSqlTable sqlTable = provider.buildBeamSqlTable(table); assertNotNull(sqlTable); assertTrue(sqlTable instanceof MongoDbTable); MongoDbTable mongoTable = (MongoDbTable) sqlTable; assertEquals("mongodb: assertEquals("database", mongoTable.dbName); assertEquals("collection", mongoTable.dbCollection); }
@Test public void testBuildBeamSqlTable_withUsernameOnly() { Table table = fakeTable("TEST", "mongodb: BeamSqlTable sqlTable = provider.buildBeamSqlTable(table); assertNotNull(sqlTable); assertTrue(sqlTable instanceof MongoDbTable); MongoDbTable mongoTable = (MongoDbTable) sqlTable; assertEquals("mongodb: assertEquals("database", mongoTable.dbName); assertEquals("collection", mongoTable.dbCollection); }
@Test public void testBuildBeamSqlTable_withUsernameAndPassword() { Table table = fakeTable("TEST", "mongodb: BeamSqlTable sqlTable = provider.buildBeamSqlTable(table); assertNotNull(sqlTable); assertTrue(sqlTable instanceof MongoDbTable); MongoDbTable mongoTable = (MongoDbTable) sqlTable; assertEquals("mongodb: assertEquals("database", mongoTable.dbName); assertEquals("collection", mongoTable.dbCollection); }
@Test public void testBuildBeamSqlTable_withBadLocation_throwsException() { ImmutableList<String> badLocations = ImmutableList.of( "mongodb: "mongodb: "localhost:27017/database/collection", "mongodb: "mongodb: "mongodb: "mongodb: for (String badLocation : badLocations) { Table table = fakeTable("TEST", badLocation); assertThrows(IllegalArgumentException.class, () -> provider.buildBeamSqlTable(table)); } }