-
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.
* Added CRUD operations for Attribute * Corrected Unit-Tests. * spotless * spotless * spotless * Consolidated IT Tests
- Loading branch information
Showing
24 changed files
with
638 additions
and
104 deletions.
There are no files selected for viewing
242 changes: 242 additions & 0 deletions
242
src/it/java/io/github/jpmorganchase/fusion/packaging/AttributeOperationsIT.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,242 @@ | ||
package io.github.jpmorganchase.fusion.packaging; | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock; | ||
import com.github.tomakehurst.wiremock.junit5.WireMockExtension; | ||
import io.github.jpmorganchase.fusion.model.Attribute; | ||
import io.github.jpmorganchase.fusion.test.TestUtils; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
|
||
import java.util.Map; | ||
|
||
import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; | ||
|
||
@ExtendWith(WireMockExtension.class) | ||
public class AttributeOperationsIT extends BaseOperationsIT { | ||
|
||
@Test | ||
public void testCreateAttribute() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-create-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Attribute a = getSdk().builders().attribute() | ||
.dataset("SD0001") | ||
.identifier("name") | ||
.title("Name") | ||
.description("The name") | ||
.index(0) | ||
.key(true) | ||
.varArg("source", "Source System 1") | ||
.varArg("term", "bizterm1") | ||
.varArg("dataType", "String") | ||
.varArg("sourceFieldId", "src_name") | ||
.build(); | ||
|
||
//When | ||
a.create(); | ||
|
||
//Then | ||
|
||
} | ||
|
||
@Test | ||
public void testCreateAttributeWithoutVarArgs() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/alternate")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-alternate-create-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Attribute a = getSdk().builders().attribute() | ||
.dataset("SD0001") | ||
.identifier("alternate") | ||
.title("Alternate") | ||
.description("The alternate") | ||
.index(0) | ||
.key(true) | ||
.build(); | ||
|
||
//When | ||
a.create(); | ||
|
||
//Then | ||
|
||
} | ||
|
||
@Test | ||
public void testCreateAttributeWithCatalogOverride() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001/attributes/name")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-create-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Attribute a = getSdk().builders().attribute() | ||
.dataset("SD0001") | ||
.identifier("name") | ||
.title("Name") | ||
.description("The name") | ||
.index(0) | ||
.key(true) | ||
.varArg("source", "Source System 1") | ||
.varArg("term", "bizterm1") | ||
.varArg("dataType", "String") | ||
.varArg("sourceFieldId", "src_name") | ||
.catalogIdentifier("foobar") | ||
.build(); | ||
|
||
//When | ||
a.create(); | ||
|
||
//Then | ||
//TODO :: Need to assert something here; return to be formulated | ||
|
||
} | ||
|
||
@Test | ||
public void testUpdateAttribute() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.put(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-update-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Attribute a = getSdk().builders().attribute() | ||
.dataset("SD0001") | ||
.identifier("name") | ||
.title("Name") | ||
.description("The name updated") | ||
.index(0) | ||
.key(true) | ||
.varArg("source", "Source System 1") | ||
.varArg("term", "bizterm1") | ||
.varArg("dataType", "String") | ||
.varArg("sourceFieldId", "src_name") | ||
.varArg("id", 1) | ||
.build(); | ||
|
||
//When | ||
a.update(); | ||
|
||
//Then | ||
|
||
} | ||
|
||
@Test | ||
public void testUpdateAttributeWithCatalogOverride() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.put(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001/attributes/name")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-update-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Attribute a = getSdk().builders().attribute() | ||
.dataset("SD0001") | ||
.identifier("name") | ||
.title("Name") | ||
.description("The name updated") | ||
.index(0) | ||
.key(true) | ||
.varArg("source", "Source System 1") | ||
.varArg("term", "bizterm1") | ||
.varArg("dataType", "String") | ||
.varArg("sourceFieldId", "src_name") | ||
.varArg("id", 1) | ||
.catalogIdentifier("foobar") | ||
.build(); | ||
|
||
//When | ||
a.update(); | ||
|
||
//Then | ||
|
||
} | ||
|
||
@Test | ||
public void testUpdateAttributeRetrieveFromListFunction() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.get(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200) | ||
.withBodyFile("attribute/multiple-attribute-response.json"))); | ||
|
||
wireMockRule.stubFor(WireMock.put(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) | ||
.withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-update-request.json"))) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Map<String, Attribute> attributes = getSdk().listAttributes("SD0001"); | ||
Attribute original = attributes.get("name"); | ||
|
||
Attribute a = original.toBuilder() | ||
.description("The name updated") | ||
.build(); | ||
|
||
//When | ||
a.update(); | ||
|
||
//Then | ||
|
||
} | ||
|
||
@Test | ||
public void testDeleteAttribute() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.delete(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Attribute a = getSdk().builders().attribute() | ||
.dataset("SD0001") | ||
.identifier("name") | ||
.build(); | ||
|
||
//When | ||
a.delete(); | ||
|
||
//Then | ||
|
||
} | ||
|
||
@Test | ||
public void testDeleteAttributeWithCatalogOverride() { | ||
|
||
// Given | ||
wireMockRule.stubFor(WireMock.delete(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001/attributes/name")) | ||
.willReturn(WireMock.aResponse() | ||
.withHeader("Content-Type", "application/json") | ||
.withStatus(200))); | ||
|
||
Attribute a = getSdk().builders().attribute() | ||
.catalogIdentifier("foobar") | ||
.dataset("SD0001") | ||
.identifier("name") | ||
.build(); | ||
|
||
//When | ||
a.delete(); | ||
|
||
//Then | ||
|
||
} | ||
|
||
|
||
} |
40 changes: 40 additions & 0 deletions
40
src/it/java/io/github/jpmorganchase/fusion/packaging/BaseOperationsIT.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,40 @@ | ||
package io.github.jpmorganchase.fusion.packaging; | ||
|
||
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 lombok.Getter; | ||
import org.junit.jupiter.api.BeforeEach; | ||
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; | ||
|
||
@ExtendWith(WireMockExtension.class) | ||
public class BaseOperationsIT { | ||
|
||
private static final Logger logger = | ||
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); | ||
|
||
@RegisterExtension | ||
public static WireMockExtension wireMockRule = WireMockExtension.newInstance().options(WireMockConfiguration.wireMockConfig().dynamicPort()).build(); | ||
|
||
@Getter | ||
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(); | ||
} | ||
|
||
} |
Oops, something went wrong.