use of uk.gov.pay.products.model.ProductMetadata in project pay-products by alphagov.
the class ProductCreatorTest method doUpdateByGatewayAccountId_referenceEnabled_shouldUpdateProduct.
@Test
public void doUpdateByGatewayAccountId_referenceEnabled_shouldUpdateProduct() {
String updatedName = "updated-name";
String updatedDescription = "updated-description";
Long updatedPrice = 500L;
String updatedReferenceLabel = "updated-reference-label";
String updatedReferenceHint = "updated-reference-hint";
ProductMetadata metadata = new ProductMetadata("key-1", "value-1");
ProductUpdateRequest productUpdateRequest = new ProductUpdateRequest(updatedName, updatedDescription, updatedPrice, true, updatedReferenceLabel, updatedReferenceHint, List.of(metadata));
ProductEntity productEntity = aProductEntity().build();
when(productDao.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId)).thenReturn(Optional.of(productEntity));
Optional<Product> maybeUpdatedProduct = productCreator.doUpdateByGatewayAccountId(gatewayAccountId, externalId, productUpdateRequest);
assertTrue(maybeUpdatedProduct.isPresent());
Product updatedProduct = maybeUpdatedProduct.get();
assertThat(updatedProduct.getName(), is(updatedName));
assertThat(updatedProduct.getDescription(), is(updatedDescription));
assertThat(updatedProduct.getPrice(), is(updatedPrice));
assertThat(updatedProduct.getReferenceEnabled(), is(productUpdateRequest.getReferenceEnabled()));
assertThat(updatedProduct.getReferenceLabel(), is(updatedReferenceLabel));
assertThat(updatedProduct.getReferenceHint(), is(updatedReferenceHint));
assertThat(updatedProduct.getMetadata(), contains(metadata));
verify(productMetadataDao).deleteForProductExternalId("external-id");
}
use of uk.gov.pay.products.model.ProductMetadata in project pay-products by alphagov.
the class MetadataDeserializer method extractMetadata.
public static List<ProductMetadata> extractMetadata(JsonNode payload, String fieldName) {
List<ProductMetadata> metadataList = new ArrayList<>();
JsonNode metadata = payload.get(fieldName);
if (metadata != null && !metadata.isEmpty()) {
Iterator<String> fieldNames = metadata.fieldNames();
while (fieldNames.hasNext()) {
String key = fieldNames.next();
String value = metadata.get(key).textValue();
metadataList.add(new ProductMetadata(key, value));
}
}
return metadataList.isEmpty() ? null : metadataList;
}
Aggregations