-
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.
Initial commits of the dataset create operation
- Loading branch information
Showing
22 changed files
with
311 additions
and
29 deletions.
There are no files selected for viewing
55 changes: 55 additions & 0 deletions
55
src/it/java/io/github/jpmorganchase/fusion/packaging/DatasetOperations.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,55 @@ | ||
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 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.RegisterExtension; | ||
|
||
import java.io.IOException; | ||
|
||
public class DatasetOperations { | ||
|
||
// WireMock server running on port 8080 | ||
@RegisterExtension | ||
public WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.wireMockConfig().port(8080)).build(); | ||
|
||
private Fusion sdk; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
sdk = Fusion.builder().configuration(FusionConfiguration.builder() | ||
.rootURL("http://localhost:8080/v1") | ||
.build()).build(); | ||
} | ||
|
||
public void testGetDataFromApi() throws IOException, InterruptedException { | ||
// Stub WireMock to respond with a custom JSON | ||
WireMock.stubFor(WireMock.get(WireMock.urlEqualTo("/api/data")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBody("{\"message\": \"Success\"}"))); | ||
|
||
Dataset dataset = Dataset.builder() | ||
.identifier("SD0001") | ||
.description("Sample dataset description 1") | ||
.linkedEntity("SD0001/") | ||
.title("Sample Dataset 1 | North America") | ||
.frequency("Daily") | ||
.build(); | ||
|
||
// Call your SDK method | ||
sdk.create(dataset); | ||
|
||
// Verify the response | ||
//MatcherAssert.assertThat("{\"message\": \"Success\"}", Matchers.is(Matchers.equalTo("abc"))); | ||
} | ||
|
||
} |
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
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
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
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
9 changes: 9 additions & 0 deletions
9
src/main/java/io/github/jpmorganchase/fusion/serializing/APIRequestSerializer.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,9 @@ | ||
package io.github.jpmorganchase.fusion.serializing; | ||
|
||
import io.github.jpmorganchase.fusion.model.Dataset; | ||
|
||
public interface APIRequestSerializer { | ||
|
||
String serializeDatasetRequest(Dataset dataset); | ||
|
||
} |
64 changes: 64 additions & 0 deletions
64
src/main/java/io/github/jpmorganchase/fusion/serializing/GsonAPIRequestSerializer.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,64 @@ | ||
package io.github.jpmorganchase.fusion.serializing; | ||
|
||
import com.google.gson.*; | ||
import io.github.jpmorganchase.fusion.model.Dataset; | ||
import io.github.jpmorganchase.fusion.parsing.GsonAPIResponseParser; | ||
import io.github.jpmorganchase.fusion.serializing.APIRequestSerializer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.lang.invoke.MethodHandles; | ||
import java.lang.reflect.Type; | ||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
import java.util.Map; | ||
|
||
public class GsonAPIRequestSerializer implements APIRequestSerializer { | ||
|
||
private static final Logger logger = | ||
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
private final Gson gson; | ||
|
||
public GsonAPIRequestSerializer() { | ||
GsonBuilder gsonBuilder = new GsonBuilder(); | ||
gsonBuilder.registerTypeAdapter(Dataset.class, new DatasetSerializer()); | ||
gson = gsonBuilder.create(); | ||
} | ||
|
||
@Override | ||
public String serializeDatasetRequest(Dataset dataset) { | ||
logger.debug("Attempting to serialize dataset {}", dataset); | ||
return gson.toJson(dataset); | ||
} | ||
|
||
private static final class DatasetSerializer implements JsonSerializer<Dataset> { | ||
|
||
@Override | ||
public JsonElement serialize(Dataset src, Type typeOfSrc, JsonSerializationContext context) { | ||
|
||
JsonObject jsonObject = new JsonObject(); | ||
|
||
jsonObject.add("description", context.serialize(src.getDescription())); | ||
jsonObject.add("@id", context.serialize(src.getLinkedEntity())); | ||
jsonObject.add("title", context.serialize(src.getTitle())); | ||
jsonObject.add("frequency", context.serialize(src.getFrequency())); | ||
jsonObject.add("identifier", context.serialize(src.getIdentifier())); | ||
|
||
Map<String, Object> varArgs = src.getVarArgs(); | ||
if (varArgs != null) { | ||
varArgs.forEach((key, value) -> jsonObject.add(key, context.serialize(value))); | ||
} | ||
|
||
|
||
if (jsonObject.has("varArgs")){ | ||
jsonObject.remove("varArgs"); | ||
} | ||
|
||
return jsonObject; | ||
} | ||
} | ||
|
||
|
||
} |
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
Oops, something went wrong.