Search in sources :

Example 1 with ProductMetadata

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");
}
Also used : ProductUpdateRequest(uk.gov.pay.products.model.ProductUpdateRequest) Product(uk.gov.pay.products.model.Product) ProductEntityFixture.aProductEntity(uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) ProductMetadata(uk.gov.pay.products.model.ProductMetadata) Test(org.junit.Test)

Example 2 with ProductMetadata

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;
}
Also used : ArrayList(java.util.ArrayList) JsonNode(com.fasterxml.jackson.databind.JsonNode) ProductMetadata(uk.gov.pay.products.model.ProductMetadata)

Aggregations

ProductMetadata (uk.gov.pay.products.model.ProductMetadata)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayList (java.util.ArrayList)1 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)1 Test (org.junit.Test)1 ProductEntityFixture.aProductEntity (uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity)1 Product (uk.gov.pay.products.model.Product)1 ProductUpdateRequest (uk.gov.pay.products.model.ProductUpdateRequest)1 ProductEntity (uk.gov.pay.products.persistence.entity.ProductEntity)1