Skip to content

Commit

Permalink
QA improvements on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
groldan committed Dec 12, 2023
1 parent 35152ba commit 4e30aee
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
Expand Up @@ -50,32 +50,32 @@ void prepRequest() {
}

@Test
public void testGetCollections() {
protected void testGetCollections() {

var expected = Set.of("base-sirene-v3", "comptages-velo", "locations", "ouvrages-acquis-par-les-mediatheques");

ResponseEntity<Collections> response = collectionsApi.getCollections();

assertThat(response.getStatusCode().value()).isEqualTo(200);
Collections body = response.getBody();
assertThat(body.getCollections().size()).isEqualTo(expected.size());
assertThat(body.getCollections()).hasSameSizeAs(expected);

var actual = body.getCollections().stream().map(Collection::getTitle).collect(Collectors.toSet());
assertThat(actual).isEqualTo(expected);
}

@Test
public void testGetItems() {
protected void testGetItems() {
FeaturesQuery query = FeaturesQuery.of("locations").withLimit(10);
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures(query);

@Cleanup
Stream<GeodataRecord> features = response.getBody().getFeatures();
assertThat(features.toList().size()).isEqualTo(10);
assertThat(features).hasSize(10);
}

@Test
public void testGetItemsWithFilter() {
protected void testGetItemsWithFilter() {
FeaturesQuery query = FeaturesQuery.of("locations").withFilter("number = 140");
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures(query);

Expand All @@ -87,7 +87,7 @@ public void testGetItemsWithFilter() {

@ParameterizedTest
@ValueSource(strings = { "base-sirene-v3", "comptages-velo", "locations", "ouvrages-acquis-par-les-mediatheques" })
public void testGetItems_paging_natural_order(String layerName) {
protected void testGetItems_paging_natural_order(String layerName) {
FeaturesQuery query = FeaturesQuery.of(layerName);

Comparator<GeodataRecord> fidComparator = fidComparator();
Expand All @@ -102,7 +102,7 @@ public void testGetItems_paging_natural_order(String layerName) {
"comptages-velo:commune,date et heure", //
"locations:-city", //
"ouvrages-acquis-par-les-mediatheques:-type de document,editeur" })
public void testGetItems_paging_mixed_order(String layerAndSortSpec) {
protected void testGetItems_paging_mixed_order(String layerAndSortSpec) {
String layerName = layerAndSortSpec.substring(0, layerAndSortSpec.indexOf(':'));
String sortSpec = layerAndSortSpec.substring(1 + layerAndSortSpec.indexOf(':'));

Expand Down Expand Up @@ -162,14 +162,11 @@ private void testPagingConsistency(FeaturesQuery query, Comparator<GeodataRecord
records.add(rec);
});
}
// verify expected order
// var sorted = new ArrayList<>(records);
// java.util.Collections.sort(sorted, comparator);
// assertThat(records).isEqualTo(sorted);
}

@Test
public void testGetItemsWithFilter_property_name_with_spaces() throws Exception {
protected void testGetItemsWithFilter_property_name_with_spaces() throws Exception {
final String collectionName = "base-sirene-v3";
final String propetyName = "indice de répétition de l'établissement";

Expand All @@ -184,7 +181,7 @@ public void testGetItemsWithFilter_property_name_with_spaces() throws Exception
Stream<GeodataRecord> features = body.getFeatures();
int expected = (int) features.filter(c -> "B".equals(c.getProperty(propetyName).orElseThrow().getValue()))
.count();
assertThat(expected).isGreaterThan(0);
assertThat(expected).isPositive();

final String cqlFilter = "\"%s\" = 'B'".formatted(propetyName);

Expand Down
Expand Up @@ -48,7 +48,7 @@
@ActiveProfiles("postgis")
@Testcontainers
@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE)
public class CollectionsApiImplPostgisIT extends AbstractCollectionsApiImplIT {
class CollectionsApiImplPostgisIT extends AbstractCollectionsApiImplIT {

public static JdbcDatabaseContainer<?> postgis;

Expand Down Expand Up @@ -108,20 +108,18 @@ static void postgisProperties(DynamicPropertyRegistry registry) {
}

@Test
public void testGetCollections_sees_new_table(TestInfo testInfo) throws SQLException {
void testGetCollections_sees_new_table(TestInfo testInfo) throws SQLException {
final String table = testInfo.getDisplayName();

Set<String> collections = getCollectionNames();

assertThat(collections).doesNotContain(table);
assertThat(collections).containsAll(defaultTables);
assertThat(collections).doesNotContain(table).containsAll(defaultTables);

createTestTable(table);

collections = getCollectionNames();

assertThat(collections).contains(table);
assertThat(collections).containsAll(defaultTables);
assertThat(collections).contains(table).containsAll(defaultTables);
}

private Set<String> getCollectionNames() {
Expand All @@ -130,7 +128,7 @@ private Set<String> getCollectionNames() {
}

@Test
public void testGetCollections_survives_schema_change() throws SQLException {
void testGetCollections_survives_schema_change() throws SQLException {
final String table = "locations";

Set<String> collections = getCollectionNames();
Expand All @@ -148,7 +146,7 @@ public void testGetCollections_survives_schema_change() throws SQLException {
}

@Test
public void testGetCollections_survives_table_rename(TestInfo testInfo) throws SQLException {
void testGetCollections_survives_table_rename(TestInfo testInfo) throws SQLException {
final String table = testInfo.getDisplayName();
final String newName = table + "_renamed";
createTestTable(table);
Expand All @@ -159,56 +157,53 @@ public void testGetCollections_survives_table_rename(TestInfo testInfo) throws S
renameTable(table, newName);

collections = getCollectionNames();
assertThat(collections).doesNotContain(table);
assertThat(collections).contains(newName);
assertThat(collections).doesNotContain(table).contains(newName);
}

@Test
public void testGetCollections_survives_drop_table(TestInfo testInfo) throws SQLException {
void testGetCollections_survives_drop_table(TestInfo testInfo) throws SQLException {
final String table = testInfo.getDisplayName();
createTestTable(table);
pgDataStoreProvider.reInit();

var collections = getCollectionNames();

assertThat(collections).contains(table);
assertThat(collections).containsAll(defaultTables);
assertThat(collections).contains(table).containsAll(defaultTables);

dropTable(table);

collections = getCollectionNames();
assertThat(collections).doesNotContain(table);
assertThat(collections).containsAll(defaultTables);
assertThat(collections).doesNotContain(table).containsAll(defaultTables);
}

@Test
public void testGetItems_survives_schema_change() throws SQLException {
void testGetItems_survives_schema_change() throws SQLException {

FeaturesQuery query = FeaturesQuery.of("locations").withLimit(10);
ResponseEntity<FeatureCollection> response = collectionsApi.getFeatures(query);

@Cleanup
Stream<GeodataRecord> features = response.getBody().getFeatures();
assertThat(features.toList().size()).isEqualTo(10);
assertThat(features).hasSize(10);

renameColumn("locations", "year", "año");

response = collectionsApi.getFeatures(query);
@Cleanup
Stream<GeodataRecord> features1 = response.getBody().getFeatures();
assertThat(features1.toList().size()).isEqualTo(10);
assertThat(features1).hasSize(10);

dropColumn("locations", "año");

response = collectionsApi.getFeatures(query);

@Cleanup
Stream<GeodataRecord> features2 = response.getBody().getFeatures();
assertThat(features2.toList().size()).isEqualTo(10);
assertThat(features2).hasSize(10);
}

@Test
public void testGetItem_survives_schema_change() throws SQLException {
void testGetItem_survives_schema_change() throws SQLException {
FeaturesQuery query = FeaturesQuery.of("locations").withLimit(1);

@Cleanup
Expand Down
Expand Up @@ -17,7 +17,7 @@

@SpringBootTest(classes = OgcFeaturesApp.class)
@ActiveProfiles("sample-data")
public class CollectionsApiImplTest extends AbstractCollectionsApiImplIT {
class CollectionsApiImplTest extends AbstractCollectionsApiImplIT {

@Override
protected Comparator<GeodataRecord> fidComparator() {
Expand All @@ -26,7 +26,7 @@ protected Comparator<GeodataRecord> fidComparator() {
}

@Test
public void testGetItemsLinks() {
void testGetItemsLinks() {
actualRequest.setParameter("f", "geojson");
actualRequest.removeHeader("Accept");
actualRequest.addHeader("Accept", "application/geo+json");
Expand All @@ -39,7 +39,8 @@ public void testGetItemsLinks() {
assertThat(nextLink.getHref()).contains("f=geojson");
}

public @Test void testGetItemsLinksNoFParam() {
@Test
void testGetItemsLinksNoFParam() {
actualRequest.removeParameter("f");
actualRequest.removeHeader("Accept");
actualRequest.addHeader("Accept", "application/json");
Expand All @@ -52,7 +53,8 @@ public void testGetItemsLinks() {
assertThat(nextLink.getHref()).contains("f=json");
}

public @Test void testGetItemsLinksFParamAndDifferentHeaderParams() {
@Test
void testGetItemsLinksFParamAndDifferentHeaderParams() {
actualRequest.addHeader("Accept", "application/json");
actualRequest.setParameter("f", "ooxml");

Expand Down

0 comments on commit 4e30aee

Please sign in to comment.