use of uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity 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.persistence.entity.StripeAgreementEntity in project pay-adminusers by alphagov.
the class StripeAgreementServiceTest method shouldReturnStripeAgreement.
@Test
public void shouldReturnStripeAgreement() {
String serviceExternalId = "abc123";
String ipAddress = "192.0.2.0";
ZonedDateTime agreementTime = ZonedDateTime.now();
ServiceEntity mockServiceEntity = mock(ServiceEntity.class);
StripeAgreementEntity stripeAgreementEntity = new StripeAgreementEntity(mockServiceEntity, ipAddress, agreementTime);
when(mockedStripeAgreementDao.findByServiceExternalId(serviceExternalId)).thenReturn(Optional.of(stripeAgreementEntity));
Optional<StripeAgreement> maybeStripeAgreement = stripeAgreementService.findStripeAgreementByServiceId(serviceExternalId);
assertTrue(maybeStripeAgreement.isPresent());
assertThat(maybeStripeAgreement.get().getIpAddress().getHostAddress(), is(ipAddress));
assertThat(maybeStripeAgreement.get().getAgreementTime(), is(agreementTime));
}
use of uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity 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"));
}
use of uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity in project pay-adminusers by alphagov.
the class StripeAgreementDaoIT method shouldNotPersistStripeAgreementEntityWhenOneAlreadyExistsForService.
@Test
public void shouldNotPersistStripeAgreementEntityWhenOneAlreadyExistsForService() {
Service service = serviceDbFixture(databaseHelper).withGatewayAccountIds(randomInt().toString()).insertService();
Optional<ServiceEntity> serviceEntity = serviceDao.findByExternalId(service.getExternalId());
assertThat(serviceEntity.isPresent(), is(true));
StripeAgreementEntity stripeAgreementEntity = new StripeAgreementEntity(serviceEntity.get(), "192.0.2.0", ZonedDateTime.now(ZoneId.of("UTC")));
stripeAgreementDao.persist(stripeAgreementEntity);
StripeAgreementEntity anotherStripeAgreementEntity = new StripeAgreementEntity(serviceEntity.get(), "192.0.2.1", ZonedDateTime.now(ZoneId.of("UTC")));
try {
stripeAgreementDao.persist(anotherStripeAgreementEntity);
fail();
} catch (RollbackException e) {
assertTrue(e.getMessage().contains("Key (service_id)=(" + serviceEntity.get().getId() + ") already exists."));
}
}
use of uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity in project pay-adminusers by alphagov.
the class StripeAgreementDaoIT method shouldNotFindStripeAgreementEntityWhenNoneExistForServiceId.
@Test
public void shouldNotFindStripeAgreementEntityWhenNoneExistForServiceId() {
Service service = serviceDbFixture(databaseHelper).insertService();
stripeAgreementDbFixture(databaseHelper).withServiceId(service.getId()).insert();
Optional<StripeAgreementEntity> maybeStripeAgreementEntity = stripeAgreementDao.findByServiceExternalId("123");
assertFalse(maybeStripeAgreementEntity.isPresent());
}
Aggregations