-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CatalogResource now a first class entity; able to invoke api operations. Dataset first entity to utilise api operations available to children of CatalogResources. Create operation supported. CatalogResource serialisation now supported. CatalogResource varArgs now parsed. Integration tests now added using WireMock.
- Loading branch information
Showing
38 changed files
with
1,244 additions
and
61 deletions.
There are no files selected for viewing
185 changes: 185 additions & 0 deletions
185
src/it/java/io/github/jpmorganchase/fusion/packaging/DatasetOperationsIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,185 @@ | ||
package io.github.jpmorganchase.fusion.packaging; | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockExtension; | ||
import io.github.jpmorganchase.fusion.Fusion; | ||
import io.github.jpmorganchase.fusion.FusionConfiguration; | ||
import io.github.jpmorganchase.fusion.model.Dataset; | ||
import io.github.jpmorganchase.fusion.test.TestUtils; | ||
import org.hamcrest.MatcherAssert; | ||
import org.hamcrest.Matchers; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; | ||
import static io.github.jpmorganchase.fusion.test.TestUtils.listOf; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
@ExtendWith(WireMockExtension.class) | ||
public class DatasetOperationsIT { | ||
|
||
private static final Logger logger = | ||
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
@RegisterExtension | ||
public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.wireMockConfig().dynamicPort()).build(); | ||
|
||
private Fusion sdk; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
int port = wireMockRule.getRuntimeInfo().getHttpPort(); | ||
logger.debug("Wiremock is configured to port {}", port); | ||
|
||
sdk = Fusion.builder() | ||
.bearerToken("my-token") | ||
.configuration(FusionConfiguration.builder() | ||
.rootURL("http://localhost:" + port + "/") | ||
.build()).build(); | ||
} | ||
|
||
@Test | ||
public void testCreateDataset() { | ||
// Given | ||
wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("dataset/dataset-SD0001-create-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("dataset/dataset-create-response.json"))); | ||
|
||
Dataset dataset = sdk.builders().dataset() | ||
.identifier("SD0001") | ||
.description("Sample dataset description 1") | ||
.linkedEntity("SD0001/") | ||
.title("Sample Dataset 1 | North America") | ||
.frequency("Daily") | ||
.build(); | ||
|
||
// When | ||
dataset.create(); | ||
|
||
// Then Verify the response | ||
//TODO :: Contract for response of dataset.create() needs to be decided | ||
} | ||
|
||
@Test | ||
public void testCreateDatasetWithVarArgs() { | ||
// Given | ||
wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/common/datasets/SD0002")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("dataset/dataset-SD0002-create-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("dataset/dataset-create-response.json"))); | ||
|
||
Dataset dataset = sdk.builders().dataset() | ||
.identifier("SD0002") | ||
.description("Sample dataset description 2") | ||
.linkedEntity("SD0002/") | ||
.title("Sample Dataset 2 | North America") | ||
.frequency("Daily") | ||
.varArg("category", listOf("Category 2")) | ||
.varArg("createdDate", "2022-02-06") | ||
.varArg("coverageStartDate", "2022-02-06") | ||
.varArg("coverageEndDate", "2023-03-09") | ||
.varArg("isThirdPartyData", Boolean.FALSE) | ||
.varArg("isInternalOnlyDataset", Boolean.FALSE) | ||
.varArg("language", "English") | ||
.varArg("maintainer", "Maintainer 2") | ||
.varArg("modifiedDate", "2023-03-09") | ||
.varArg("publisher", "Publisher 2") | ||
.varArg("region", listOf("North America")) | ||
.varArg("source", listOf("Source System 2")) | ||
.varArg("subCategory", listOf("Subcategory 2")) | ||
.varArg("tag", listOf("Tag2")) | ||
.varArg("isRestricted", Boolean.FALSE) | ||
.varArg("isRawData", Boolean.FALSE) | ||
.varArg("hasSample", Boolean.FALSE) | ||
.build(); | ||
|
||
// When | ||
dataset.create(); | ||
|
||
|
||
// Then Verify the response | ||
//TODO :: Contract for response of dataset.create() needs to be decided | ||
} | ||
|
||
@Test | ||
public void testCreateDatasetOverrideDefaultCatalog() { | ||
// Given | ||
wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("dataset/dataset-SD0001-create-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("dataset/dataset-create-response.json"))); | ||
|
||
Dataset dataset = sdk.builders().dataset() | ||
.identifier("SD0001") | ||
.description("Sample dataset description 1") | ||
.linkedEntity("SD0001/") | ||
.title("Sample Dataset 1 | North America") | ||
.frequency("Daily") | ||
.catalogIdentifier("foobar") | ||
.build(); | ||
|
||
// When | ||
dataset.create(); | ||
|
||
// Then Verify the response | ||
//TODO :: Contract for response of dataset.create() needs to be decided | ||
} | ||
|
||
@Test | ||
public void testListDatasets() { | ||
// Given | ||
wireMockRule.stubFor(WireMock.get(WireMock.urlEqualTo("/catalogs/common/datasets")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("dataset/multiple-dataset-response.json"))); | ||
|
||
// When | ||
Map<String, Dataset> 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))); | ||
|
||
} | ||
|
||
@Test | ||
public void testListDatasetsUsingIdContains() { | ||
// Given | ||
wireMockRule.stubFor(WireMock.get(WireMock.urlEqualTo("/catalogs/common/datasets")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("dataset/multiple-dataset-response.json"))); | ||
|
||
// When | ||
Map<String, Dataset> 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))); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/io/github/jpmorganchase/fusion/builders/APIConfiguredBuilders.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package io.github.jpmorganchase.fusion.builders; | ||
|
||
import io.github.jpmorganchase.fusion.FusionConfiguration; | ||
import io.github.jpmorganchase.fusion.api.APIManager; | ||
import io.github.jpmorganchase.fusion.model.Dataset; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public class APIConfiguredBuilders implements Builders { | ||
|
||
APIManager apiManager; | ||
FusionConfiguration configuration; | ||
|
||
@Override | ||
public Dataset.DatasetBuilder dataset() { | ||
return Dataset.builder() | ||
.apiManager(apiManager) | ||
.rootUrl(configuration.getRootURL()) | ||
.catalogIdentifier(configuration.getDefaultCatalog()); | ||
} | ||
} |
Oops, something went wrong.