Search in sources :

Example 1 with Product

use of uk.gov.pay.products.model.Product in project pay-products by alphagov.

the class ProductApiTokenManagerTest method shouldReplaceApiTokenForAProductWhichExists.

@Test
public void shouldReplaceApiTokenForAProductWhichExists() {
    Product modifiedDemoPayment = ProductEntityFixture.aProductEntity().withApiToken(NEW_API_TOKEN_FOR_DEMO_PAYMENT).build().toProduct();
    ProductFinder productFinder = mock(ProductFinder.class);
    when(productFactory.productFinder()).thenReturn(productFinder);
    when(productFinder.updatePayApiTokenByExternalId(DEMO_PAYMENT.getExternalId(), NEW_API_TOKEN_FOR_DEMO_PAYMENT)).thenReturn(Optional.of(modifiedDemoPayment));
    productApiTokenManager.replaceApiTokenForAProduct(DEMO_PAYMENT, NEW_API_TOKEN_FOR_DEMO_PAYMENT);
    verifyLog(mockAppender, loggingEventArgumentCaptor, 1, String.format("Regenerated API token for product %s of type %s", modifiedDemoPayment.getExternalId(), modifiedDemoPayment.getType()));
}
Also used : Product(uk.gov.pay.products.model.Product) Test(org.junit.jupiter.api.Test)

Example 2 with Product

use of uk.gov.pay.products.model.Product in project pay-products by alphagov.

the class ProductCreatorTest method doUpdateByGatewayAccountId_shouldNotUpdateProduct_whenNotFound.

@Test
public void doUpdateByGatewayAccountId_shouldNotUpdateProduct_whenNotFound() {
    String updatedName = "updated-name";
    String updatedDescription = "updated-description";
    Long updatedPrice = 500L;
    ProductUpdateRequest productUpdateRequest = new ProductUpdateRequest(updatedName, updatedDescription, updatedPrice, true, null, null, null);
    when(productDao.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId)).thenReturn(Optional.empty());
    Optional<Product> updatedProduct = productCreator.doUpdateByGatewayAccountId(gatewayAccountId, externalId, productUpdateRequest);
    assertFalse(updatedProduct.isPresent());
}
Also used : ProductUpdateRequest(uk.gov.pay.products.model.ProductUpdateRequest) Product(uk.gov.pay.products.model.Product) Matchers.emptyOrNullString(org.hamcrest.Matchers.emptyOrNullString) Test(org.junit.Test)

Example 3 with Product

use of uk.gov.pay.products.model.Product in project pay-products by alphagov.

the class ProductCreatorTest method shouldSuccess_whenProvidedAProductWithMinimumRequiredFields.

@Test
public void shouldSuccess_whenProvidedAProductWithMinimumRequiredFields() {
    Product basicProduct = new Product(null, PRODUCT_NAME, null, payApiToken, PRICE, null, gatewayAccountId, ProductType.DEMO, null, null, null, SupportedLanguage.ENGLISH, null);
    Product product = productCreator.doCreate(basicProduct);
    assertThat(product.getName(), is("Test product name"));
    assertThat(product.getPrice(), is(1050L));
    assertThat(product.getPayApiToken(), is(payApiToken));
    assertThat(product.getGatewayAccountId(), is(gatewayAccountId));
    verify(productDao).persist(persistedProductEntity.capture());
    ProductEntity productEntity = persistedProductEntity.getValue();
    assertThat(productEntity.getName(), is("Test product name"));
    assertThat(productEntity.getPrice(), is(1050L));
    assertThat(productEntity.getPayApiToken(), is(payApiToken));
    assertThat(productEntity.getExternalId(), is(not(emptyOrNullString())));
    assertThat(productEntity.getDateCreated(), is(notNullValue()));
    assertThat(productEntity.getGatewayAccountId(), is(notNullValue()));
    assertThat(productEntity.getGatewayAccountId(), is(gatewayAccountId));
    assertThat(productEntity.getType(), is(notNullValue()));
    assertThat(productEntity.getType(), is(ProductType.DEMO));
    assertThat(productEntity.getLanguage(), is(SupportedLanguage.ENGLISH));
}
Also used : Product(uk.gov.pay.products.model.Product) ProductEntityFixture.aProductEntity(uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) Test(org.junit.Test)

Example 4 with Product

use of uk.gov.pay.products.model.Product 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 5 with Product

use of uk.gov.pay.products.model.Product in project pay-products by alphagov.

the class ProductFinderTest method disableByGatewayAccountIdAndExternalId_shouldDisableProduct_whenFound.

@Test
public void disableByGatewayAccountIdAndExternalId_shouldDisableProduct_whenFound() {
    Integer gatewayAccountId = 1;
    String externalId = "1";
    ProductEntity productEntity = new ProductEntity();
    productEntity.setExternalId(externalId);
    productEntity.setGatewayAccountId(gatewayAccountId);
    productEntity.setReferenceEnabled(false);
    when(productDao.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId)).thenReturn(Optional.of(productEntity));
    Optional<Product> productOptional = productFinder.findByGatewayAccountIdAndExternalId(gatewayAccountId, externalId);
    assertThat(productOptional.isPresent(), is(true));
    assertThat(productOptional.get().getStatus(), is(ProductStatus.ACTIVE));
    Optional<Product> disabledProduct = productFinder.disableByGatewayAccountIdAndExternalId(gatewayAccountId, externalId);
    assertThat(disabledProduct.isPresent(), is(true));
    assertThat(disabledProduct.get().getStatus(), is(ProductStatus.INACTIVE));
}
Also used : Product(uk.gov.pay.products.model.Product) ProductEntity(uk.gov.pay.products.persistence.entity.ProductEntity) Test(org.junit.Test)

Aggregations

Product (uk.gov.pay.products.model.Product)67 Test (org.junit.Test)59 ProductEntity (uk.gov.pay.products.persistence.entity.ProductEntity)30 ValidatableResponse (io.restassured.response.ValidatableResponse)20 ImmutableMap (com.google.common.collect.ImmutableMap)11 Map (java.util.Map)11 ProductEntityFixture.aProductEntity (uk.gov.pay.products.fixtures.ProductEntityFixture.aProductEntity)10 JsonObject (javax.json.JsonObject)6 PaymentEntityFixture.aPaymentEntity (uk.gov.pay.products.fixtures.PaymentEntityFixture.aPaymentEntity)5 PaymentEntity (uk.gov.pay.products.persistence.entity.PaymentEntity)5 State (au.com.dius.pact.provider.junit.State)4 Matchers.emptyOrNullString (org.hamcrest.Matchers.emptyOrNullString)4 Test (org.junit.jupiter.api.Test)3 ProductUpdateRequest (uk.gov.pay.products.model.ProductUpdateRequest)3 FailToReplaceApiTokenException (uk.gov.pay.products.exception.FailToReplaceApiTokenException)1 ProductMetadata (uk.gov.pay.products.model.ProductMetadata)1 JsonPatchRequest (uk.gov.service.payments.commons.model.jsonpatch.JsonPatchRequest)1