use of uk.gov.pay.adminusers.exception.StripeAgreementExistsException in project pay-adminusers by alphagov.
the class StripeAgreementService method doCreate.
public void doCreate(String serviceExternalId, InetAddress ipAddress) {
ServiceEntity serviceEntity = serviceDao.findByExternalId(serviceExternalId).orElseThrow(() -> new ServiceNotFoundException(serviceExternalId));
if (stripeAgreementDao.findByServiceExternalId(serviceExternalId).isPresent()) {
throw new StripeAgreementExistsException();
}
logger.info(format("Creating stripe agreement for service %s", serviceExternalId));
ZonedDateTime agreementTime = ZonedDateTime.now(ZoneId.of("UTC"));
stripeAgreementDao.persist(new StripeAgreementEntity(serviceEntity, ipAddress.getHostAddress(), agreementTime));
}
use of uk.gov.pay.adminusers.exception.StripeAgreementExistsException in project pay-adminusers by alphagov.
the class StripeAgreementServiceTest method shouldThrowException_whenStripeAgreementAlreadyExists.
@Test
public void shouldThrowException_whenStripeAgreementAlreadyExists() throws UnknownHostException {
String serviceExternalId = "abc123";
ServiceEntity mockServiceEntity = mock(ServiceEntity.class);
when(mockedServiceDao.findByExternalId(serviceExternalId)).thenReturn(Optional.of(mockServiceEntity));
StripeAgreementEntity mockStripeAgreementEntity = mock(StripeAgreementEntity.class);
when(mockedStripeAgreementDao.findByServiceExternalId(serviceExternalId)).thenReturn(Optional.of(mockStripeAgreementEntity));
StripeAgreementExistsException exception = assertThrows(StripeAgreementExistsException.class, () -> stripeAgreementService.doCreate(serviceExternalId, InetAddress.getByName("192.0.2.0")));
assertThat(exception.getMessage(), is("Stripe agreement information is already stored for this service"));
}
Aggregations