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