Search in sources :

Example 1 with FailToReplaceApiTokenException

use of uk.gov.pay.products.exception.FailToReplaceApiTokenException in project pay-products by alphagov.

the class ProductApiTokenManager method replaceApiTokenForAProduct.

public void replaceApiTokenForAProduct(Product product, String newApiToken) {
    Product modifiedProduct = productFactory.productFinder().updatePayApiTokenByExternalId(product.getExternalId(), newApiToken).orElseThrow(() -> new FailToReplaceApiTokenException(String.format("Failed to replace API token for product %s of type %s", product.getExternalId(), product.getType())));
    LOGGER.info(String.format("Regenerated API token for product %s of type %s", modifiedProduct.getExternalId(), modifiedProduct.getType()));
}
Also used : FailToReplaceApiTokenException(uk.gov.pay.products.exception.FailToReplaceApiTokenException) Product(uk.gov.pay.products.model.Product)

Example 2 with FailToReplaceApiTokenException

use of uk.gov.pay.products.exception.FailToReplaceApiTokenException in project pay-products by alphagov.

the class ProductApiTokenManagerTest method shouldThrowExceptionWhenReplacingApiTokenForAProductWhichDoesNotExist.

@Test
public void shouldThrowExceptionWhenReplacingApiTokenForAProductWhichDoesNotExist() {
    ProductFinder productFinder = mock(ProductFinder.class);
    when(productFactory.productFinder()).thenReturn(productFinder);
    when(productFinder.updatePayApiTokenByExternalId(DEMO_PAYMENT.getExternalId(), NEW_API_TOKEN_FOR_DEMO_PAYMENT)).thenReturn(Optional.empty());
    FailToReplaceApiTokenException e = assertThrows(FailToReplaceApiTokenException.class, () -> productApiTokenManager.replaceApiTokenForAProduct(DEMO_PAYMENT, NEW_API_TOKEN_FOR_DEMO_PAYMENT));
    assertThat(e.getMessage(), is(String.format("Failed to replace API token for product %s of type %s", DEMO_PAYMENT.getExternalId(), DEMO_PAYMENT.getType())));
}
Also used : FailToReplaceApiTokenException(uk.gov.pay.products.exception.FailToReplaceApiTokenException) Test(org.junit.jupiter.api.Test)

Aggregations

FailToReplaceApiTokenException (uk.gov.pay.products.exception.FailToReplaceApiTokenException)2 Test (org.junit.jupiter.api.Test)1 Product (uk.gov.pay.products.model.Product)1