Skip to content

Commit

Permalink
create dataset of type report - moved report from varArg to Object pr…
Browse files Browse the repository at this point in the history
…operty and also added test cases for parser and serializer
  • Loading branch information
pkarthik1901 committed Nov 30, 2024
1 parent 1e044c3 commit fab9e94
Show file tree
Hide file tree
Showing 8 changed files with 341 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,5 @@ public DatasetBuilder varArgs(Map<String, Object> varArgs) {
this.varArgs = VarArgsHelper.copyMap(varArgs);
return this;
}

public DatasetBuilder report(Object value) {
this.varArgs = VarArgsHelper.varArg("report", value, this.varArgs);
return this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public JsonElement serialize(Dataset src, Type typeOfSrc, JsonSerializationConte
jsonObject.add("frequency", context.serialize(src.getFrequency()));
jsonObject.add("identifier", context.serialize(src.getIdentifier()));
jsonObject.add("type", context.serialize(src.getType()));
jsonObject.add("report", context.serialize(src.getReport()));

Map<String, Object> varArgs = src.getVarArgs();
if (varArgs != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class DatasetBuilderTest {
@Test
void constructionWithBuilderCorrectlyPopulatesAllFields() {
APIManager apiManager = Mockito.mock(APIManager.class);
Report report = Report.builder().tier("The tier").build();
Map<String, Object> varArgs = new HashMap<>();
varArgs.put("key1", "value1");
Dataset d = Dataset.builder()
Expand All @@ -25,6 +26,7 @@ void constructionWithBuilderCorrectlyPopulatesAllFields() {
.title("The title")
.frequency("The frequency")
.type("The type")
.report(report)
.rootUrl("http://foobar/api/v1/")
.catalogIdentifier("foobar")
.apiManager(apiManager)
Expand All @@ -37,6 +39,7 @@ void constructionWithBuilderCorrectlyPopulatesAllFields() {
assertThat(d.getTitle(), is(equalTo("The title")));
assertThat(d.getFrequency(), is(equalTo("The frequency")));
assertThat(d.getType(), is(equalTo("The type")));
assertThat(d.getReport(), is(equalTo(report)));
assertThat(d.getRootUrl(), is(equalTo("http://foobar/api/v1/")));
assertThat(d.getCatalogIdentifier(), is(equalTo("foobar")));
assertThat(d.getApiManager(), is(equalTo(apiManager)));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
package io.github.jpmorganchase.fusion.parsing;

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;

import io.github.jpmorganchase.fusion.api.APIManager;
import io.github.jpmorganchase.fusion.api.context.APIContext;
import io.github.jpmorganchase.fusion.model.Dataset;
import io.github.jpmorganchase.fusion.model.Report;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

public class GsonAPIResponseParserDatasetReportTest {

private static final String singleDatasetJson = loadTestResource("single-dataset-report-response.json");
private static final String multipleDatasetJson = loadTestResource("multiple-dataset-report-response.json");

private final Dataset testDataset = Dataset.builder()
.identifier("SR0001")
.description("Sample report description 1")
.linkedEntity("SR0001/")
.frequency("Daily")
.apiManager(apiContext.getApiManager())
.rootUrl(apiContext.getRootUrl())
.catalogIdentifier(apiContext.getDefaultCatalog())
.title("Sample Report 1 | North America")
.varArg("category", listOf("Category 1"))
.varArg("createdDate", "2022-02-05")
.varArg("coverageStartDate", "2022-02-05")
.varArg("coverageEndDate", "2023-03-08")
.varArg("isThirdPartyData", Boolean.FALSE)
.varArg("isInternalOnlyDataset", Boolean.FALSE)
.varArg("language", "English")
.varArg("maintainer", "Maintainer 1")
.varArg("modifiedDate", "2023-03-08")
.varArg("publisher", "Publisher 1")
.varArg("region", listOf("North America"))
.varArg("source", listOf("Source System 1"))
.varArg("subCategory", listOf("Subcategory 1"))
.varArg("tag", listOf("Tag1"))
.varArg("isRestricted", Boolean.FALSE)
.varArg("isRawData", Boolean.FALSE)
.varArg("hasSample", Boolean.FALSE)
.type("Report")
.report(Report.builder().tier("Tier 1").build())
.build();

private final Dataset testDataset2 = Dataset.builder()
.identifier("SR0002")
.description("Sample report description 2")
.linkedEntity("SR0002/")
.frequency("Daily")
.title("Sample Report 2 | North America")
.apiManager(apiContext.getApiManager())
.rootUrl(apiContext.getRootUrl())
.catalogIdentifier(apiContext.getDefaultCatalog())
.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)
.type("Report")
.report(Report.builder().tier("Tier 2").build())
.build();

private final Dataset testDataset3 = Dataset.builder()
.identifier("SR0003")
.description("Sample report description 3")
.linkedEntity("SR0003/")
.frequency("Daily")
.title("Sample Report 3 | North America")
.apiManager(apiContext.getApiManager())
.rootUrl(apiContext.getRootUrl())
.catalogIdentifier(apiContext.getDefaultCatalog())
.varArg("category", listOf("Category 3"))
.varArg("createdDate", "2022-02-07")
.varArg("coverageStartDate", "2022-02-07")
.varArg("coverageEndDate", "2023-03-10")
.varArg("isThirdPartyData", Boolean.FALSE)
.varArg("isInternalOnlyDataset", Boolean.FALSE)
.varArg("language", "English")
.varArg("maintainer", "Maintainer 3")
.varArg("modifiedDate", "2023-03-10")
.varArg("publisher", "Publisher 3")
.varArg("region", listOf("North America"))
.varArg("source", listOf("Source System 3"))
.varArg("subCategory", listOf("Subcategory 3"))
.varArg("tag", listOf("Tag3"))
.varArg("isRestricted", Boolean.FALSE)
.varArg("isRawData", Boolean.FALSE)
.varArg("hasSample", Boolean.FALSE)
.type("Report")
.report(Report.builder().tier("Tier 3").build())
.build();

private static final APIContext apiContext = APIContext.builder()
.apiManager(Mockito.mock(APIManager.class))
.rootUrl("http://foobar/api/v1/")
.defaultCatalog("foobar")
.build();

private static final APIResponseParser responseParser = new GsonAPIResponseParser(apiContext);

@Test
public void singleDatasetInResourcesParsesCorrectly() {
Map<String, Dataset> datasetMap = responseParser.parseDatasetResponse(singleDatasetJson);
assertThat(datasetMap.size(), is(1));

Dataset testDatasetResponse = datasetMap.get("SR0001");
assertThat(testDatasetResponse, is(equalTo(testDataset)));
}

@Test
public void multipleCatalogsInResourcesParseCorrectly() {
Map<String, Dataset> datasetMap = responseParser.parseDatasetResponse(multipleDatasetJson);
assertThat(datasetMap.size(), is(3));

Dataset testDatasetResponse = datasetMap.get("SR0001");
assertThat(testDatasetResponse, is(equalTo(testDataset)));

Dataset testDatasetResponse2 = datasetMap.get("SR0002");
assertThat(testDatasetResponse2, is(equalTo(testDataset2)));

Dataset testDatasetResponse3 = datasetMap.get("SR0003");
assertThat(testDatasetResponse3, is(equalTo(testDataset3)));
}

private static String loadTestResource(String resourceName) {
URL url = GsonAPIResponseParser.class.getResource(resourceName);
try {
Path path = Paths.get(url.toURI());
return new String(Files.readAllBytes(path), StandardCharsets.UTF_8);
} catch (Exception e) {
throw new RuntimeException("Failed to load test data", e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import static org.hamcrest.MatcherAssert.assertThat;

import io.github.jpmorganchase.fusion.model.Dataset;
import io.github.jpmorganchase.fusion.model.Report;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
Expand Down Expand Up @@ -41,6 +42,8 @@ public void testDatasetSerializesCorrectly() {
.varArg("isRestricted", Boolean.FALSE)
.varArg("isRawData", Boolean.FALSE)
.varArg("hasSample", Boolean.FALSE)
.type("Report")
.report(Report.builder().tier("Tier 1").build())
.build();

GsonAPIRequestSerializer serializer = new GsonAPIRequestSerializer();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
{
"@context": {
"@vocab": "https://www.w3.org/ns/dcat3.jsonld",
"@base": "https://fusion-api.jpmorgan.com/fusion/v1/catalogs/test/"
},
"@id": "datasets/",
"description": "A list of available datasets (for access or download in one or more formats)",
"identifier": "datasets",
"resources": [
{
"category": [
"Category 1"
],
"createdDate": "2022-02-05",
"coverageStartDate": "2022-02-05",
"coverageEndDate": "2023-03-08",
"description": "Sample report description 1",
"frequency": "Daily",
"identifier": "SR0001",
"isThirdPartyData": false,
"isInternalOnlyDataset": false,
"language": "English",
"maintainer": "Maintainer 1",
"modifiedDate": "2023-03-08",
"publisher": "Publisher 1",
"region": [
"North America"
],
"source": [
"Source System 1"
],
"subCategory": [
"Subcategory 1"
],
"title": "Sample Report 1 | North America",
"tag": [
"Tag1"
],
"isRestricted": false,
"isRawData": false,
"hasSample": false,
"@id": "SR0001/",
"type": "Report",
"report": {
"tier": "Tier 1"
}
},
{
"category": [
"Category 2"
],
"createdDate": "2022-02-06",
"coverageStartDate": "2022-02-06",
"coverageEndDate": "2023-03-09",
"description": "Sample report description 2",
"frequency": "Daily",
"identifier": "SR0002",
"isThirdPartyData": false,
"isInternalOnlyDataset": false,
"language": "English",
"maintainer": "Maintainer 2",
"modifiedDate": "2023-03-09",
"publisher": "Publisher 2",
"region": [
"North America"
],
"source": [
"Source System 2"
],
"subCategory": [
"Subcategory 2"
],
"title": "Sample Report 2 | North America",
"tag": [
"Tag2"
],
"isRestricted": false,
"isRawData": false,
"hasSample": false,
"@id": "SR0002/",
"type": "Report",
"report": {
"tier": "Tier 2"
}
},
{
"category": [
"Category 3"
],
"createdDate": "2022-02-07",
"coverageStartDate": "2022-02-07",
"coverageEndDate": "2023-03-10",
"description": "Sample report description 3",
"frequency": "Daily",
"identifier": "SR0003",
"isThirdPartyData": false,
"isInternalOnlyDataset": false,
"language": "English",
"maintainer": "Maintainer 3",
"modifiedDate": "2023-03-10",
"publisher": "Publisher 3",
"region": [
"North America"
],
"source": [
"Source System 3"
],
"subCategory": [
"Subcategory 3"
],
"title": "Sample Report 3 | North America",
"tag": [
"Tag3"
],
"isRestricted": false,
"isRawData": false,
"hasSample": false,
"@id": "SR0003/",
"type": "Report",
"report": {
"tier": "Tier 3"
}
}
],
"title": "Datasets"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"@context": {
"@vocab": "https://www.w3.org/ns/dcat3.jsonld",
"@base": "https://fusion-api.jpmorgan.com/fusion/v1/catalogs/test/"
},
"@id": "datasets/",
"description": "A list of available datasets (for access or download in one or more formats)",
"identifier": "datasets",
"resources": [
{
"category": [
"Category 1"
],
"createdDate": "2022-02-05",
"coverageStartDate": "2022-02-05",
"coverageEndDate": "2023-03-08",
"description": "Sample report description 1",
"frequency": "Daily",
"identifier": "SR0001",
"isThirdPartyData": false,
"isInternalOnlyDataset": false,
"language": "English",
"maintainer": "Maintainer 1",
"modifiedDate": "2023-03-08",
"publisher": "Publisher 1",
"region": [
"North America"
],
"source": [
"Source System 1"
],
"subCategory": [
"Subcategory 1"
],
"title": "Sample Report 1 | North America",
"tag": [
"Tag1"
],
"isRestricted": false,
"isRawData": false,
"hasSample": false,
"@id": "SR0001/",
"type": "Report",
"report": {
"tier": "Tier 1"
}
}
],
"title": "Datasets"
}
Loading

0 comments on commit fab9e94

Please sign in to comment.