-
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.
create dataset of type report - moved report from varArg to Object pr…
…operty and also added test cases for parser and serializer
- Loading branch information
1 parent
1e044c3
commit fab9e94
Showing
8 changed files
with
341 additions
and
6 deletions.
There are no files selected for viewing
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
157 changes: 157 additions & 0 deletions
157
...t/java/io/github/jpmorganchase/fusion/parsing/GsonAPIResponseParserDatasetReportTest.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,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); | ||
} | ||
} | ||
} |
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
126 changes: 126 additions & 0 deletions
126
...st/resources/io/github/jpmorganchase/fusion/parsing/multiple-dataset-report-response.json
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,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" | ||
} |
50 changes: 50 additions & 0 deletions
50
...test/resources/io/github/jpmorganchase/fusion/parsing/single-dataset-report-response.json
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,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" | ||
} |
Oops, something went wrong.