Search in sources :

Example 6 with StripeAgreementEntity

use of uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity in project pay-adminusers by alphagov.

the class StripeAgreementDaoIT method shouldPersistStripeAgreementEntity.

@Test
public void shouldPersistStripeAgreementEntity() {
    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);
    assertThat(stripeAgreementEntity.getId(), is(notNullValue()));
    List<Map<String, Object>> searchResults = databaseHelper.findStripeAgreementById(stripeAgreementEntity.getId());
    assertThat(searchResults.size(), is(1));
    assertThat(searchResults.get(0).get("service_id"), is(stripeAgreementEntity.getService().getId()));
    assertThat(searchResults.get(0).get("ip_address"), is(stripeAgreementEntity.getIpAddress()));
    assertThat(searchResults.get(0).get("id"), is(stripeAgreementEntity.getId()));
    assertThat(searchResults.get(0).get("agreement_time"), is(Timestamp.from(stripeAgreementEntity.getAgreementTime().toInstant())));
}
Also used : StripeAgreementEntity(uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity) Service(uk.gov.pay.adminusers.model.Service) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Example 7 with StripeAgreementEntity

use of uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity in project pay-adminusers by alphagov.

the class StripeAgreementDaoIT method shouldFindStripeAgreementEntityByServiceId.

@Test
public void shouldFindStripeAgreementEntityByServiceId() {
    Service service = serviceDbFixture(databaseHelper).insertService();
    ZonedDateTime agreementTime = ZonedDateTime.now(ZoneOffset.UTC);
    String ipAddress = "192.0.2.0";
    stripeAgreementDbFixture(databaseHelper).withAgreementTime(agreementTime).withIpAddress(ipAddress).withServiceId(service.getId()).insert();
    Optional<StripeAgreementEntity> maybeStripeAgreementEntity = stripeAgreementDao.findByServiceExternalId(service.getExternalId());
    assertTrue(maybeStripeAgreementEntity.isPresent());
    assertThat(maybeStripeAgreementEntity.get().getIpAddress(), is(ipAddress));
    assertThat(maybeStripeAgreementEntity.get().getService().getId(), is(service.getId()));
    assertThat(maybeStripeAgreementEntity.get().getAgreementTime(), is(agreementTime));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) StripeAgreementEntity(uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity) Service(uk.gov.pay.adminusers.model.Service) Test(org.junit.jupiter.api.Test)

Aggregations

StripeAgreementEntity (uk.gov.pay.adminusers.persistence.entity.StripeAgreementEntity)7 Test (org.junit.jupiter.api.Test)6 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)5 Service (uk.gov.pay.adminusers.model.Service)4 ZonedDateTime (java.time.ZonedDateTime)3 StripeAgreementExistsException (uk.gov.pay.adminusers.exception.StripeAgreementExistsException)2 Map (java.util.Map)1 RollbackException (javax.persistence.RollbackException)1 ServiceNotFoundException (uk.gov.pay.adminusers.exception.ServiceNotFoundException)1 StripeAgreement (uk.gov.pay.adminusers.model.StripeAgreement)1