-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from jpmorganchase/feature/create_dataset_of_t…
…ype_report create dataset of type report
- Loading branch information
Showing
13 changed files
with
500 additions
and
3 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
15 changes: 15 additions & 0 deletions
15
src/main/java/io/github/jpmorganchase/fusion/model/Report.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,15 @@ | ||
package io.github.jpmorganchase.fusion.model; | ||
|
||
import lombok.Builder; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.ToString; | ||
import lombok.Value; | ||
|
||
@Builder | ||
@Value | ||
@EqualsAndHashCode() | ||
@ToString() | ||
public class Report { | ||
|
||
String tier; | ||
} |
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
16 changes: 16 additions & 0 deletions
16
src/test/java/io/github/jpmorganchase/fusion/model/ReportTest.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,16 @@ | ||
package io.github.jpmorganchase.fusion.model; | ||
|
||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.is; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
public class ReportTest { | ||
|
||
@Test | ||
void constructionWithBuilderCorrectlyPopulatesAllFields() { | ||
Report report = Report.builder().tier("The tier").build(); | ||
assertThat(report.getTier(), is(equalTo("The tier"))); | ||
} | ||
} |
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
35 changes: 34 additions & 1 deletion
35
src/test/resources/__files/dataset/dataset-SD0002-create-request.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 |
---|---|---|
@@ -1 +1,34 @@ | ||
{"description":"Sample dataset description 2","@id":"SD0002/","title":"Sample Dataset 2 | North America","frequency":"Daily","identifier":"SD0002","subCategory":["Subcategory 2"],"isRawData":false,"isInternalOnlyDataset":false,"language":"English","source":["Source System 2"],"coverageEndDate":"2023-03-09","maintainer":"Maintainer 2","coverageStartDate":"2022-02-06","createdDate":"2022-02-06","isThirdPartyData":false,"modifiedDate":"2023-03-09","publisher":"Publisher 2","tag":["Tag2"],"category":["Category 2"],"region":["North America"],"hasSample":false,"isRestricted":false} | ||
{ | ||
"description": "Sample dataset description 2", | ||
"@id": "SD0002/", | ||
"title": "Sample Dataset 2 | North America", | ||
"frequency": "Daily", | ||
"identifier": "SD0002", | ||
"subCategory": [ | ||
"Subcategory 2" | ||
], | ||
"isRawData": false, | ||
"isInternalOnlyDataset": false, | ||
"language": "English", | ||
"source": [ | ||
"Source System 2" | ||
], | ||
"coverageEndDate": "2023-03-09", | ||
"maintainer": "Maintainer 2", | ||
"coverageStartDate": "2022-02-06", | ||
"createdDate": "2022-02-06", | ||
"isThirdPartyData": false, | ||
"modifiedDate": "2023-03-09", | ||
"publisher": "Publisher 2", | ||
"tag": [ | ||
"Tag2" | ||
], | ||
"category": [ | ||
"Category 2" | ||
], | ||
"region": [ | ||
"North America" | ||
], | ||
"hasSample": false, | ||
"isRestricted": false | ||
} |
Oops, something went wrong.