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()));
}
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())));
}
Aggregations