Skip to content

Commit

Permalink
Add test for error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Hamza Jugon committed Oct 23, 2024
1 parent 637b622 commit 2c11c8c
Showing 1 changed file with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.util.SocketUtils;

import com.fasterxml.jackson.core.type.TypeReference;
Expand All @@ -51,6 +52,7 @@
import com.fasterxml.jackson.module.paramnames.ParameterNamesModule;

import com.expediagroup.beekeeper.api.BeekeeperApiApplication;
import com.expediagroup.beekeeper.api.error.ErrorResponse;
import com.expediagroup.beekeeper.api.response.HousekeepingMetadataResponse;
import com.expediagroup.beekeeper.api.response.HousekeepingPathResponse;
import com.expediagroup.beekeeper.core.model.HousekeepingMetadata;
Expand Down Expand Up @@ -111,7 +113,7 @@ public final void afterEach() {

@Test
public void testGetMetadataWhenTableNotFoundReturnsEmptyList()
throws SQLException, InterruptedException, IOException {
throws SQLException, InterruptedException, IOException {

for (HousekeepingMetadata testMetadata : Arrays.asList(testMetadataB, testMetadataC)) {
insertExpiredMetadata(testMetadata);
Expand Down Expand Up @@ -302,4 +304,23 @@ private HousekeepingPath createHousekeepingPath(
.build();
}

}
@Test
public void testInvalidSortParameter() throws SQLException, IOException, InterruptedException {
insertExpiredMetadata(testMetadataA);

String filters = "?sort=nonExistentProperty,asc";
HttpResponse<String> response = testClient.getMetadata(someDatabase, someTable, filters);

assertThat(response.statusCode()).isEqualTo(HttpStatus.BAD_REQUEST.value());

String body = response.body();
ErrorResponse errorResponse = mapper.readValue(body, ErrorResponse.class);

assertThat(errorResponse.getStatus()).isEqualTo(HttpStatus.BAD_REQUEST.value());
assertThat(errorResponse.getMessage()).contains("Invalid sort parameter");
assertThat(errorResponse.getError()).isEqualTo("Bad Request");
assertThat(errorResponse.getPath()).contains("/api/v1/database/some_database/table/some_table/metadata");
assertThat(errorResponse.getTimestamp()).isNotNull();
}

}

0 comments on commit 2c11c8c

Please sign in to comment.