|
| 1 | +package io.github.jpmorganchase.fusion.packaging; |
| 2 | + |
| 3 | +import com.github.tomakehurst.wiremock.client.WireMock; |
| 4 | +import com.github.tomakehurst.wiremock.junit5.WireMockExtension; |
| 5 | +import io.github.jpmorganchase.fusion.model.Attribute; |
| 6 | +import io.github.jpmorganchase.fusion.test.TestUtils; |
| 7 | +import org.junit.jupiter.api.Assertions; |
| 8 | +import org.junit.jupiter.api.Test; |
| 9 | +import org.junit.jupiter.api.extension.ExtendWith; |
| 10 | + |
| 11 | +import java.util.Map; |
| 12 | + |
| 13 | +import static com.github.tomakehurst.wiremock.client.WireMock.equalToJson; |
| 14 | + |
| 15 | +@ExtendWith(WireMockExtension.class) |
| 16 | +public class AttributeOperationsIT extends BaseOperationsIT { |
| 17 | + |
| 18 | + @Test |
| 19 | + public void testCreateAttribute() { |
| 20 | + |
| 21 | + // Given |
| 22 | + wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) |
| 23 | + .withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-create-request.json"))) |
| 24 | + .withHeader("Content-Type", WireMock.equalTo("application/json")) |
| 25 | + .willReturn(WireMock.aResponse() |
| 26 | + .withHeader("Content-Type", "application/json") |
| 27 | + .withStatus(200))); |
| 28 | + |
| 29 | + Attribute a = getSdk().builders().attribute() |
| 30 | + .datasetIdentifier("SD0001") |
| 31 | + .identifier("name") |
| 32 | + .title("Name") |
| 33 | + .description("The name") |
| 34 | + .index(0) |
| 35 | + .key(true) |
| 36 | + .isCriticalDataElement(true) |
| 37 | + .varArg("source", "Source System 1") |
| 38 | + .varArg("term", "bizterm1") |
| 39 | + .varArg("dataType", "String") |
| 40 | + .varArg("sourceFieldId", "src_name") |
| 41 | + .build(); |
| 42 | + |
| 43 | + // When & Then |
| 44 | + Assertions.assertDoesNotThrow(a::create); |
| 45 | + |
| 46 | + } |
| 47 | + |
| 48 | + @Test |
| 49 | + public void testCreateAttributeWithoutVarArgs() { |
| 50 | + |
| 51 | + // Given |
| 52 | + wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/alternate")) |
| 53 | + .withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-alternate-create-request.json"))) |
| 54 | + .withHeader("Content-Type", WireMock.equalTo("application/json")) |
| 55 | + .willReturn(WireMock.aResponse() |
| 56 | + .withHeader("Content-Type", "application/json") |
| 57 | + .withStatus(200))); |
| 58 | + |
| 59 | + Attribute a = getSdk().builders().attribute() |
| 60 | + .datasetIdentifier("SD0001") |
| 61 | + .identifier("alternate") |
| 62 | + .title("Alternate") |
| 63 | + .description("The alternate") |
| 64 | + .index(0) |
| 65 | + .key(true) |
| 66 | + .build(); |
| 67 | + |
| 68 | + // When & Then |
| 69 | + Assertions.assertDoesNotThrow(a::create); |
| 70 | + |
| 71 | + } |
| 72 | + |
| 73 | + @Test |
| 74 | + public void testCreateAttributeWithCatalogOverride() { |
| 75 | + |
| 76 | + // Given |
| 77 | + wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001/attributes/name")) |
| 78 | + .withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-create-request.json"))) |
| 79 | + .withHeader("Content-Type", WireMock.equalTo("application/json")) |
| 80 | + .willReturn(WireMock.aResponse() |
| 81 | + .withHeader("Content-Type", "application/json") |
| 82 | + .withStatus(200))); |
| 83 | + |
| 84 | + Attribute a = getSdk().builders().attribute() |
| 85 | + .datasetIdentifier("SD0001") |
| 86 | + .identifier("name") |
| 87 | + .title("Name") |
| 88 | + .description("The name") |
| 89 | + .index(0) |
| 90 | + .key(true) |
| 91 | + .varArg("source", "Source System 1") |
| 92 | + .varArg("term", "bizterm1") |
| 93 | + .varArg("dataType", "String") |
| 94 | + .varArg("sourceFieldId", "src_name") |
| 95 | + .catalogIdentifier("foobar") |
| 96 | + .isCriticalDataElement(true) |
| 97 | + .build(); |
| 98 | + |
| 99 | + // When & Then |
| 100 | + Assertions.assertDoesNotThrow(a::create); |
| 101 | + } |
| 102 | + |
| 103 | + @Test |
| 104 | + public void testUpdateAttribute() { |
| 105 | + |
| 106 | + // Given |
| 107 | + wireMockRule.stubFor(WireMock.put(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) |
| 108 | + .withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-update-request.json"))) |
| 109 | + .withHeader("Content-Type", WireMock.equalTo("application/json")) |
| 110 | + .willReturn(WireMock.aResponse() |
| 111 | + .withHeader("Content-Type", "application/json") |
| 112 | + .withStatus(200))); |
| 113 | + |
| 114 | + Attribute a = getSdk().builders().attribute() |
| 115 | + .datasetIdentifier("SD0001") |
| 116 | + .identifier("name") |
| 117 | + .title("Name") |
| 118 | + .description("The name updated") |
| 119 | + .index(0) |
| 120 | + .key(true) |
| 121 | + .varArg("source", "Source System 1") |
| 122 | + .varArg("term", "bizterm1") |
| 123 | + .varArg("dataType", "String") |
| 124 | + .varArg("sourceFieldId", "src_name") |
| 125 | + .varArg("id", 1) |
| 126 | + .isCriticalDataElement(true) |
| 127 | + .build(); |
| 128 | + |
| 129 | + // When & Then |
| 130 | + Assertions.assertDoesNotThrow(a::update); |
| 131 | + } |
| 132 | + |
| 133 | + @Test |
| 134 | + public void testUpdateAttributeWithCatalogOverride() { |
| 135 | + |
| 136 | + // Given |
| 137 | + wireMockRule.stubFor(WireMock.put(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001/attributes/name")) |
| 138 | + .withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-update-request.json"))) |
| 139 | + .withHeader("Content-Type", WireMock.equalTo("application/json")) |
| 140 | + .willReturn(WireMock.aResponse() |
| 141 | + .withHeader("Content-Type", "application/json") |
| 142 | + .withStatus(200))); |
| 143 | + |
| 144 | + Attribute a = getSdk().builders().attribute() |
| 145 | + .datasetIdentifier("SD0001") |
| 146 | + .identifier("name") |
| 147 | + .title("Name") |
| 148 | + .description("The name updated") |
| 149 | + .index(0) |
| 150 | + .key(true) |
| 151 | + .varArg("source", "Source System 1") |
| 152 | + .varArg("term", "bizterm1") |
| 153 | + .varArg("dataType", "String") |
| 154 | + .varArg("sourceFieldId", "src_name") |
| 155 | + .varArg("id", 1) |
| 156 | + .catalogIdentifier("foobar") |
| 157 | + .isCriticalDataElement(true) |
| 158 | + .build(); |
| 159 | + |
| 160 | + // When & Then |
| 161 | + Assertions.assertDoesNotThrow(a::update); |
| 162 | + |
| 163 | + } |
| 164 | + |
| 165 | + @Test |
| 166 | + public void testUpdateAttributeRetrieveFromListFunction() { |
| 167 | + |
| 168 | + // Given |
| 169 | + wireMockRule.stubFor(WireMock.get(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes")) |
| 170 | + .willReturn(WireMock.aResponse() |
| 171 | + .withHeader("Content-Type", "application/json") |
| 172 | + .withStatus(200) |
| 173 | + .withBodyFile("attribute/multiple-attribute-response.json"))); |
| 174 | + |
| 175 | + wireMockRule.stubFor(WireMock.put(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) |
| 176 | + .withRequestBody(equalToJson(TestUtils.loadJsonForIt("attribute/attribute-name-update-request.json"))) |
| 177 | + .withHeader("Content-Type", WireMock.equalTo("application/json")) |
| 178 | + .willReturn(WireMock.aResponse() |
| 179 | + .withHeader("Content-Type", "application/json") |
| 180 | + .withStatus(200))); |
| 181 | + |
| 182 | + Map<String, Attribute> attributes = getSdk().listAttributes("SD0001"); |
| 183 | + Attribute original = attributes.get("name"); |
| 184 | + |
| 185 | + Attribute a = original.toBuilder() |
| 186 | + .description("The name updated") |
| 187 | + .build(); |
| 188 | + |
| 189 | + // When & Then |
| 190 | + Assertions.assertDoesNotThrow(a::update); |
| 191 | + } |
| 192 | + |
| 193 | + @Test |
| 194 | + public void testDeleteAttribute() { |
| 195 | + |
| 196 | + // Given |
| 197 | + wireMockRule.stubFor(WireMock.delete(WireMock.urlEqualTo("/catalogs/common/datasets/SD0001/attributes/name")) |
| 198 | + .willReturn(WireMock.aResponse() |
| 199 | + .withHeader("Content-Type", "application/json") |
| 200 | + .withStatus(200))); |
| 201 | + |
| 202 | + Attribute a = getSdk().builders().attribute() |
| 203 | + .datasetIdentifier("SD0001") |
| 204 | + .identifier("name") |
| 205 | + .build(); |
| 206 | + |
| 207 | + // When & Then |
| 208 | + Assertions.assertDoesNotThrow(a::delete); |
| 209 | + } |
| 210 | + |
| 211 | + @Test |
| 212 | + public void testDeleteAttributeWithCatalogOverride() { |
| 213 | + |
| 214 | + // Given |
| 215 | + wireMockRule.stubFor(WireMock.delete(WireMock.urlEqualTo("/catalogs/foobar/datasets/SD0001/attributes/name")) |
| 216 | + .willReturn(WireMock.aResponse() |
| 217 | + .withHeader("Content-Type", "application/json") |
| 218 | + .withStatus(200))); |
| 219 | + |
| 220 | + Attribute a = getSdk().builders().attribute() |
| 221 | + .catalogIdentifier("foobar") |
| 222 | + .datasetIdentifier("SD0001") |
| 223 | + .identifier("name") |
| 224 | + .build(); |
| 225 | + |
| 226 | + // When & Then |
| 227 | + Assertions.assertDoesNotThrow(a::delete); |
| 228 | + } |
| 229 | +} |
0 commit comments