Search in sources :

Example 1 with CustomBrandingConverter

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

the class DatabaseTestHelper method addService.

public DatabaseTestHelper addService(Service service, String... gatewayAccountIds) {
    jdbi.withHandle(handle -> {
        PGobject customBranding = service.getCustomBranding() == null ? null : new CustomBrandingConverter().convertToDatabaseColumn(service.getCustomBranding());
        MerchantDetails merchantDetails = service.getMerchantDetails();
        if (merchantDetails == null) {
            merchantDetails = new MerchantDetails();
        }
        return handle.createUpdate("INSERT INTO services(" + "id, custom_branding, " + "merchant_name, merchant_telephone_number, merchant_address_line1, merchant_address_line2, merchant_address_city, " + "merchant_address_postcode, merchant_address_country, merchant_email, merchant_url, external_id, experimental_features_enabled) " + "VALUES (:id, :customBranding, :merchantName, :merchantTelephoneNumber, :merchantAddressLine1, :merchantAddressLine2, " + ":merchantAddressCity, :merchantAddressPostcode, :merchantAddressCountry, :merchantEmail, :merchantUrl, :externalId, :experimentalFeaturesEnabled)").bind("id", service.getId()).bindBySqlType("customBranding", customBranding, OTHER).bind("merchantName", merchantDetails.getName()).bind("merchantTelephoneNumber", merchantDetails.getTelephoneNumber()).bind("merchantAddressLine1", merchantDetails.getAddressLine1()).bind("merchantAddressLine2", merchantDetails.getAddressLine2()).bind("merchantAddressCity", merchantDetails.getAddressCity()).bind("merchantAddressPostcode", merchantDetails.getAddressPostcode()).bind("merchantAddressCountry", merchantDetails.getAddressCountry()).bind("merchantEmail", merchantDetails.getEmail()).bind("merchantUrl", merchantDetails.getUrl()).bind("externalId", service.getExternalId()).bind("experimentalFeaturesEnabled", service.isExperimentalFeaturesEnabled()).execute();
    });
    addServiceName(ServiceNameEntity.from(SupportedLanguage.ENGLISH, service.getName()), service.getId());
    for (String gatewayAccountId : gatewayAccountIds) {
        jdbi.withHandle(handle -> handle.createUpdate("INSERT INTO service_gateway_accounts(service_id, gateway_account_id) VALUES (:serviceId, :gatewayAccountId)").bind("serviceId", service.getId()).bind("gatewayAccountId", gatewayAccountId).execute());
    }
    return this;
}
Also used : MerchantDetails(uk.gov.pay.adminusers.model.MerchantDetails) CustomBrandingConverter(uk.gov.pay.adminusers.persistence.entity.CustomBrandingConverter) PGobject(org.postgresql.util.PGobject)

Example 2 with CustomBrandingConverter

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

the class DatabaseTestHelper method insertServiceEntity.

public DatabaseTestHelper insertServiceEntity(ServiceEntity serviceEntity) {
    jdbi.withHandle(handle -> {
        PGobject customBranding = serviceEntity.getCustomBranding() == null ? null : new CustomBrandingConverter().convertToDatabaseColumn(serviceEntity.getCustomBranding());
        MerchantDetailsEntity merchantDetails = serviceEntity.getMerchantDetailsEntity();
        return handle.createUpdate("INSERT INTO services(" + "id, custom_branding, " + "merchant_name, merchant_telephone_number, merchant_address_line1, merchant_address_line2, merchant_address_city, " + "merchant_address_postcode, merchant_address_country, merchant_email, merchant_url, external_id, redirect_to_service_immediately_on_terminal_state, " + "current_go_live_stage, experimental_features_enabled, current_psp_test_account_stage, created_date) " + "VALUES (:id, :customBranding, :merchantName, :merchantTelephoneNumber, :merchantAddressLine1, :merchantAddressLine2, " + ":merchantAddressCity, :merchantAddressPostcode, :merchantAddressCountry, :merchantEmail, :merchantUrl, :externalId, :redirectToServiceImmediatelyOnTerminalState, " + ":currentGoLiveStage, :experimentalFeaturesEnabled, :pspTestAccountStage, :createdDate)").bind("id", serviceEntity.getId()).bindBySqlType("customBranding", customBranding, OTHER).bind("merchantName", merchantDetails.getName()).bind("merchantTelephoneNumber", merchantDetails.getTelephoneNumber()).bind("merchantAddressLine1", merchantDetails.getAddressLine1()).bind("merchantAddressLine2", merchantDetails.getAddressLine2()).bind("merchantAddressCity", merchantDetails.getAddressCity()).bind("merchantAddressPostcode", merchantDetails.getAddressPostcode()).bind("merchantAddressCountry", merchantDetails.getAddressCountryCode()).bind("merchantEmail", merchantDetails.getEmail()).bind("merchantUrl", merchantDetails.getUrl()).bind("externalId", serviceEntity.getExternalId()).bind("redirectToServiceImmediatelyOnTerminalState", serviceEntity.isRedirectToServiceImmediatelyOnTerminalState()).bind("currentGoLiveStage", serviceEntity.getCurrentGoLiveStage()).bind("experimentalFeaturesEnabled", serviceEntity.isExperimentalFeaturesEnabled()).bind("pspTestAccountStage", serviceEntity.getCurrentPspTestAccountStage()).bind("createdDate", serviceEntity.getCreatedDate()).execute();
    });
    serviceEntity.getGatewayAccountIds().forEach(gatewayAccount -> jdbi.withHandle(handle -> handle.createUpdate("INSERT INTO service_gateway_accounts(service_id, gateway_account_id) VALUES (:serviceId, :gatewayAccountId)").bind("serviceId", serviceEntity.getId()).bind("gatewayAccountId", gatewayAccount.getGatewayAccountId()).execute()));
    serviceEntity.getServiceNames().values().forEach((name) -> addServiceName(name, serviceEntity.getId()));
    return this;
}
Also used : Jdbi(org.jdbi.v3.core.Jdbi) MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) User(uk.gov.pay.adminusers.model.User) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) Timestamp(java.sql.Timestamp) ZonedDateTime(java.time.ZonedDateTime) Permission(uk.gov.pay.adminusers.model.Permission) Role(uk.gov.pay.adminusers.model.Role) ZoneId(java.time.ZoneId) OTHER(java.sql.Types.OTHER) PGobject(org.postgresql.util.PGobject) List(java.util.List) ForgottenPassword(uk.gov.pay.adminusers.model.ForgottenPassword) ServiceNameEntity(uk.gov.pay.adminusers.persistence.entity.service.ServiceNameEntity) Map(java.util.Map) Service(uk.gov.pay.adminusers.model.Service) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) CustomBrandingConverter(uk.gov.pay.adminusers.persistence.entity.CustomBrandingConverter) Timestamp.from(java.sql.Timestamp.from) MerchantDetails(uk.gov.pay.adminusers.model.MerchantDetails) MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) CustomBrandingConverter(uk.gov.pay.adminusers.persistence.entity.CustomBrandingConverter) PGobject(org.postgresql.util.PGobject)

Example 3 with CustomBrandingConverter

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

the class ServiceDaoIT method shouldSaveAService_withoutCustomisations_andServiceName.

@Test
void shouldSaveAService_withoutCustomisations_andServiceName() {
    ServiceEntity insertedServiceEntity = ServiceEntityBuilder.aServiceEntity().withCustomBranding(null).withServiceNameEntity(SupportedLanguage.ENGLISH, EN_NAME).withServiceNameEntity(SupportedLanguage.WELSH, CY_NAME).build();
    serviceDao.persist(insertedServiceEntity);
    List<Map<String, Object>> savedService = databaseHelper.findServiceByExternalId(insertedServiceEntity.getExternalId());
    assertThat(savedService.size(), is(1));
    assertThat(savedService.get(0).get("external_id"), is(insertedServiceEntity.getExternalId()));
    Map<String, Object> storedBranding = new CustomBrandingConverter().convertToEntityAttribute((PGobject) savedService.get(0).get("custom_branding"));
    assertNull(storedBranding);
    List<Map<String, Object>> savedServiceName = databaseHelper.findServiceNameByServiceId(insertedServiceEntity.getId());
    savedServiceName.sort(comparing(item -> String.valueOf(item.get("language"))));
    assertThat(savedServiceName.size(), is(2));
    assertThat(savedServiceName.get(0).get("service_id"), is(Long.valueOf(insertedServiceEntity.getId())));
    assertThat(savedServiceName.get(0).get("language"), is("cy"));
    assertThat(savedServiceName.get(0).get("name"), is(CY_NAME));
    assertThat(savedServiceName.get(1).get("service_id"), is(Long.valueOf(insertedServiceEntity.getId())));
    assertThat(savedServiceName.get(1).get("language"), is("en"));
    assertThat(savedServiceName.get(1).get("name"), is(EN_NAME));
}
Also used : RandomUtils(org.apache.commons.lang3.RandomUtils) BeforeEach(org.junit.jupiter.api.BeforeEach) Role.role(uk.gov.pay.adminusers.model.Role.role) IntStream.range(java.util.stream.IntStream.range) User(uk.gov.pay.adminusers.model.User) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertNull(org.junit.jupiter.api.Assertions.assertNull) Permission(uk.gov.pay.adminusers.model.Permission) Role(uk.gov.pay.adminusers.model.Role) Matchers.hasItems(org.hamcrest.Matchers.hasItems) Matchers.hasKey(org.hamcrest.Matchers.hasKey) PGobject(org.postgresql.util.PGobject) MerchantDetailsEntityBuilder(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntityBuilder) HashSet(java.util.HashSet) ServiceName(uk.gov.pay.adminusers.model.ServiceName) ServiceNameEntity(uk.gov.pay.adminusers.persistence.entity.service.ServiceNameEntity) Map(java.util.Map) RandomIdGenerator.randomInt(uk.gov.pay.adminusers.app.util.RandomIdGenerator.randomInt) Is.is(org.hamcrest.core.Is.is) Service(uk.gov.pay.adminusers.model.Service) Comparator.comparing(java.util.Comparator.comparing) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TypeReference(com.fasterxml.jackson.core.type.TypeReference) CustomBrandingConverter(uk.gov.pay.adminusers.persistence.entity.CustomBrandingConverter) GoLiveStage(uk.gov.pay.adminusers.model.GoLiveStage) GatewayAccountIdEntity(uk.gov.pay.adminusers.persistence.entity.GatewayAccountIdEntity) RandomIdGenerator.randomUuid(uk.gov.pay.adminusers.app.util.RandomIdGenerator.randomUuid) MerchantDetailsEntity(uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Set(java.util.Set) PspTestAccountStage(uk.gov.pay.adminusers.model.PspTestAccountStage) Test(org.junit.jupiter.api.Test) ServiceEntityBuilder(uk.gov.pay.adminusers.persistence.entity.ServiceEntityBuilder) List(java.util.List) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) UTC(java.time.ZoneOffset.UTC) Optional(java.util.Optional) SupportedLanguage(uk.gov.service.payments.commons.model.SupportedLanguage) UserDbFixture(uk.gov.pay.adminusers.fixtures.UserDbFixture) Collections(java.util.Collections) ServiceEntity(uk.gov.pay.adminusers.persistence.entity.ServiceEntity) CustomBrandingConverter(uk.gov.pay.adminusers.persistence.entity.CustomBrandingConverter) Map(java.util.Map) Test(org.junit.jupiter.api.Test)

Aggregations

PGobject (org.postgresql.util.PGobject)3 CustomBrandingConverter (uk.gov.pay.adminusers.persistence.entity.CustomBrandingConverter)3 ZonedDateTime (java.time.ZonedDateTime)2 List (java.util.List)2 Map (java.util.Map)2 MerchantDetails (uk.gov.pay.adminusers.model.MerchantDetails)2 Permission (uk.gov.pay.adminusers.model.Permission)2 Role (uk.gov.pay.adminusers.model.Role)2 Service (uk.gov.pay.adminusers.model.Service)2 User (uk.gov.pay.adminusers.model.User)2 MerchantDetailsEntity (uk.gov.pay.adminusers.persistence.entity.MerchantDetailsEntity)2 ServiceEntity (uk.gov.pay.adminusers.persistence.entity.ServiceEntity)2 ServiceNameEntity (uk.gov.pay.adminusers.persistence.entity.service.ServiceNameEntity)2 SupportedLanguage (uk.gov.service.payments.commons.model.SupportedLanguage)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Timestamp (java.sql.Timestamp)1 Timestamp.from (java.sql.Timestamp.from)1 OTHER (java.sql.Types.OTHER)1 ZoneId (java.time.ZoneId)1