diff --git a/src/it/java/io/github/jpmorganchase/fusion/packaging/DatasetOperationsIT.java b/src/it/java/io/github/jpmorganchase/fusion/packaging/DatasetOperationsIT.java index 2b0dc08..31e6f7a 100644 --- a/src/it/java/io/github/jpmorganchase/fusion/packaging/DatasetOperationsIT.java +++ b/src/it/java/io/github/jpmorganchase/fusion/packaging/DatasetOperationsIT.java @@ -24,6 +24,7 @@ import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; import static io.github.jpmorganchase.fusion.test.TestUtils.listOf; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.is; @@ -166,7 +167,7 @@ public void testUpdateDataset() { dataset.update(); // Then Verify the response - //TODO :: Contract for response of dataset.create() needs to be decided + //TODO :: Contract for response of dataset.update() needs to be decided } @Test @@ -197,7 +198,48 @@ public void testUpdateDatasetRetrievedFromListDatasets() { amendedDataset.update(); // Then Verify the response - //TODO :: Contract for response of dataset.create() needs to be decided + //TODO :: Contract for response of dataset.update() needs to be decided + } + + @Test + public void testDeleteDataset() { + // Given + wireMockRule.stubFor(WireMock.delete(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001")) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withStatus(200) + .withBodyFile("dataset/dataset-delete-response.json"))); + + Dataset dataset = sdk.builders().dataset() + .identifier("SD0001") + .build(); + + // When + dataset.delete(); + + // Then Verify the response + //TODO :: Contract for response of dataset.delete() needs to be decided + } + + @Test + public void testDeleteDatasetWithCatalogOverride() { + // Given + wireMockRule.stubFor(WireMock.delete(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001")) + .willReturn(WireMock.aResponse() + .withHeader("Content-Type", "application/json") + .withStatus(200) + .withBodyFile("dataset/dataset-delete-response.json"))); + + Dataset dataset = sdk.builders().dataset() + .identifier("SD0001") + .catalogIdentifier("foobar") + .build(); + + // When + dataset.delete(); + + // Then Verify the response + //TODO :: Contract for response of dataset.delete() needs to be decided } @Test @@ -213,10 +255,9 @@ public void testListDatasets() { Map datasets = sdk.listDatasets(); // Then Verify the response - MatcherAssert.assertThat(datasets.containsKey("SD0001"), is(equalTo(true))); - MatcherAssert.assertThat(datasets.containsKey("SD0002"), is(equalTo(true))); - MatcherAssert.assertThat(datasets.containsKey("SD0003"), is(equalTo(true))); - + assertThat(datasets.containsKey("SD0001"), is(equalTo(true))); + assertThat(datasets.containsKey("SD0002"), is(equalTo(true))); + assertThat(datasets.containsKey("SD0003"), is(equalTo(true))); } @Test @@ -232,9 +273,9 @@ public void testListDatasetsUsingIdContains() { Map datasets = sdk.listDatasets("common", "SD0001", true); // Then Verify the response - MatcherAssert.assertThat(datasets.containsKey("SD0001"), is(equalTo(true))); - MatcherAssert.assertThat(datasets.containsKey("SD0002"), is(equalTo(false))); - MatcherAssert.assertThat(datasets.containsKey("SD0003"), is(equalTo(false))); + assertThat(datasets.containsKey("SD0001"), is(equalTo(true))); + assertThat(datasets.containsKey("SD0002"), is(equalTo(false))); + assertThat(datasets.containsKey("SD0003"), is(equalTo(false))); } diff --git a/src/main/java/io/github/jpmorganchase/fusion/api/APIManager.java b/src/main/java/io/github/jpmorganchase/fusion/api/APIManager.java index a2af332..6eefe1a 100644 --- a/src/main/java/io/github/jpmorganchase/fusion/api/APIManager.java +++ b/src/main/java/io/github/jpmorganchase/fusion/api/APIManager.java @@ -35,4 +35,12 @@ public interface APIManager extends APIDownloadOperations, APIUploadOperations { * @throws APICallException if the response status indicates an error or the request fails */ String callAPIToPut(String apiPath, CatalogResource catalogResource); + + /** + * Sends a DELETE request to the specified API endpoint with the provided catalog resource. + * + * @param apiPath the API endpoint path to which the PUT request will be sent + * @throws APICallException if the response status indicates an error or the request fails + */ + String callAPIToDelete(String apiPath); } diff --git a/src/main/java/io/github/jpmorganchase/fusion/api/FusionAPIManager.java b/src/main/java/io/github/jpmorganchase/fusion/api/FusionAPIManager.java index 8da9527..65ba610 100644 --- a/src/main/java/io/github/jpmorganchase/fusion/api/FusionAPIManager.java +++ b/src/main/java/io/github/jpmorganchase/fusion/api/FusionAPIManager.java @@ -105,6 +105,22 @@ public String callAPIToPut(String apiPath, CatalogResource catalogResource) { return response.getBody(); } + /** + * Sends a DELETE request to the specified API endpoint with the provided catalog resource. + * + * @param apiPath the API endpoint path to which the PUT request will be sent + * @throws APICallException if the response status indicates an error or the request fails + */ + @Override + public String callAPIToDelete(String apiPath) { + Map requestHeaders = new HashMap<>(); + requestHeaders.put("Authorization", "Bearer " + tokenProvider.getSessionBearerToken()); + + HttpResponse response = httpClient.delete(apiPath, requestHeaders, null); + checkResponseStatus(response); + return response.getBody(); + } + @Override public void callAPIFileDownload( String apiPath, String fileName, String catalog, String dataset, Map headers) diff --git a/src/main/java/io/github/jpmorganchase/fusion/model/CatalogResource.java b/src/main/java/io/github/jpmorganchase/fusion/model/CatalogResource.java index b166252..54fd901 100644 --- a/src/main/java/io/github/jpmorganchase/fusion/model/CatalogResource.java +++ b/src/main/java/io/github/jpmorganchase/fusion/model/CatalogResource.java @@ -49,6 +49,10 @@ public String update() { return this.apiManager.callAPIToPut(getApiPath(), this); } + public String delete() { + return this.apiManager.callAPIToDelete(getApiPath()); + } + /** * Returns the API path used to perform operations on this catalog resource. * This path is utilized for creating, reading, updating, and deleting the resource. diff --git a/src/test/java/io/github/jpmorganchase/fusion/api/FusionApiManagerTest.java b/src/test/java/io/github/jpmorganchase/fusion/api/FusionApiManagerTest.java index e2da2b9..bfd1a84 100644 --- a/src/test/java/io/github/jpmorganchase/fusion/api/FusionApiManagerTest.java +++ b/src/test/java/io/github/jpmorganchase/fusion/api/FusionApiManagerTest.java @@ -94,6 +94,19 @@ void successfulPutCall() { thenTheResponseBodyShouldMatchExpected(); } + @Test + void successfulDeleteCall() { + givenFusionApiManager(); + givenApiPath("http://localhost:8080/test"); + givenSessionBearerToken("my-token"); + givenResponseBody("sample response"); + givenCatalogResource("dataset_one"); + givenRequestHeader("Authorization", "Bearer my-token"); + givenCallToClientToDeleteIsSuccessful(); + WhenFusionApiManagerIsCalledToDelete(); + thenTheResponseBodyShouldMatchExpected(); + } + private void givenSerializedCatalogResource(String identifier) { serializedCatalogResource = String.format("{\"identifier\":\"%s\"}", identifier); } @@ -146,6 +159,10 @@ private void WhenFusionApiManagerIsCalledToPut() { actualResponse = fusionAPIManager.callAPIToPut(apiPath, catalogResource); } + private void WhenFusionApiManagerIsCalledToDelete() { + actualResponse = fusionAPIManager.callAPIToDelete(apiPath); + } + private void givenResponseBody(String responseBody) { this.responseBody = responseBody; } @@ -174,6 +191,14 @@ private void givenCallToClientToPutIsSuccessful() { when(client.put(apiPath, serializedCatalogResource, requestHeaders)).thenReturn(expectedHttpResponse); } + private void givenCallToClientToDeleteIsSuccessful() { + HttpResponse expectedHttpResponse = HttpResponse.builder() + .statusCode(200) + .body(responseBody) + .build(); + when(client.delete(apiPath, requestHeaders, null)).thenReturn(expectedHttpResponse); + } + private void thenExceptionMessageShouldMatchExpected(String message) { assertThat(thrown.getMessage(), is(equalTo(message))); } diff --git a/src/test/resources/__files/dataset/dataset-delete-response.json b/src/test/resources/__files/dataset/dataset-delete-response.json new file mode 100644 index 0000000..6fe4726 --- /dev/null +++ b/src/test/resources/__files/dataset/dataset-delete-response.json @@ -0,0 +1 @@ +"{\"message\": \"Success\"}" \ No newline at end of file