Skip to content

Commit

Permalink
test: address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
landonreed committed Nov 8, 2018
1 parent fbadc7b commit d10aff3
Showing 1 changed file with 32 additions and 33 deletions.
65 changes: 32 additions & 33 deletions src/test/java/com/conveyal/gtfs/loader/JDBCTableWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -109,19 +109,15 @@ public void canCreateUpdateAndDeleteFeedInfoEntities() throws IOException, SQLEx
createdFeedInfo.id,
true
);
LOG.info("delete {} output:", feedInfoTable.name);
LOG.info(updateOutput);
LOG.info("deleted {} records from {}", deleteOutput, feedInfoTable.name);

// make sure record does not exist in DB
String sql = String.format(
assertThatSqlQueryYieldsZeroRows(String.format(
"select * from %s.%s where id=%d",
testNamespace,
feedInfoTable.name,
createdFeedInfo.id
);
LOG.info(sql);
ResultSet rs = testDataSource.getConnection().prepareStatement(sql).executeQuery();
assertThat(rs.getFetchSize(), equalTo(0));
));
}

@Test
Expand Down Expand Up @@ -214,30 +210,33 @@ public void canCreateUpdateAndDeleteFares() throws IOException, SQLException, In
createdFare.id,
true
);
LOG.info("delete {} output:", fareTable.name);
LOG.info(updateOutput);
LOG.info("deleted {} records from {}", deleteOutput, fareTable.name);

// make sure fare_attributes record does not exist in DB
String sql = String.format(
assertThatSqlQueryYieldsZeroRows(String.format(
"select * from %s.%s where id=%d",
testNamespace,
fareTable.name,
createdFare.id
);
LOG.info(sql);
ResultSet rs = testDataSource.getConnection().prepareStatement(sql).executeQuery();
assertThat(rs.getFetchSize(), equalTo(0));
));

// make sure fare_rules record does not exist in DB
String fareRulesSql = String.format(
assertThatSqlQueryYieldsZeroRows(String.format(
"select * from %s.%s where id=%d",
testNamespace,
Table.FARE_RULES.name,
createdFare.fare_rules[0].id
);
LOG.info(fareRulesSql);
ResultSet fareRulesResultSet = testDataSource.getConnection().prepareStatement(fareRulesSql).executeQuery();
assertThat(fareRulesResultSet.getFetchSize(), equalTo(0));
));
}

private void assertThatSqlQueryYieldsZeroRows(String sql) throws SQLException {
assertThatSqlQueryYieldsRowCount(sql, 0);
}

private void assertThatSqlQueryYieldsRowCount(String sql, int expectedRowCount) throws SQLException {
LOG.info(sql);
ResultSet resultSet = testDataSource.getConnection().prepareStatement(sql).executeQuery();
assertThat(resultSet.getFetchSize(), equalTo(expectedRowCount));
}

@Test
Expand All @@ -263,20 +262,22 @@ public void canCreateUpdateAndDeleteRoutes() throws IOException, SQLException, I
LOG.info(createOutput);

// parse output
RouteDTO createdFare = mapper.readValue(createOutput, routeDTOClass);
RouteDTO createdRoute = mapper.readValue(createOutput, routeDTOClass);

// make sure saved data matches expected data
assertThat(createdFare.route_id, equalTo(routeId));
assertThat(createdRoute.route_id, equalTo(routeId));
// TODO: Verify with a SQL query that the database now contains the created data (we may need to use the same
// db connection to do this successfully?)

// try to update record
String updatedRouteId = "600";
createdFare.route_id = updatedRouteId;
createdRoute.route_id = updatedRouteId;

// covert object to json and save it
JdbcTableWriter updateTableWriter = createTestTableWriter(routeTable);
String updateOutput = updateTableWriter.update(
createdFare.id,
mapper.writeValueAsString(createdFare),
createdRoute.id,
mapper.writeValueAsString(createdRoute),
true
);
LOG.info("update {} output:", routeTable.name);
Expand All @@ -286,26 +287,24 @@ public void canCreateUpdateAndDeleteRoutes() throws IOException, SQLException, I

// make sure saved data matches expected data
assertThat(updatedRouteDTO.route_id, equalTo(updatedRouteId));
// TODO: Verify with a SQL query that the database now contains the updated data (we may need to use the same
// db connection to do this successfully?)

// try to delete record
JdbcTableWriter deleteTableWriter = createTestTableWriter(routeTable);
int deleteOutput = deleteTableWriter.delete(
createdFare.id,
createdRoute.id,
true
);
LOG.info("delete {} output:", routeTable.name);
LOG.info(updateOutput);
LOG.info("deleted {} records from {}", deleteOutput, routeTable.name);

// make sure route record does not exist in DB
String sql = String.format(
assertThatSqlQueryYieldsZeroRows(String.format(
"select * from %s.%s where id=%d",
testNamespace,
routeTable.name,
createdFare.id
);
LOG.info(sql);
ResultSet rs = testDataSource.getConnection().prepareStatement(sql).executeQuery();
assertThat(rs.getFetchSize(), equalTo(0));
createdRoute.id
));
}

@AfterClass
Expand Down

0 comments on commit d10aff3

Please sign in to comment.