use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class ServiceResourceCreateTest method shouldSuccess_whenCreateAServiceWithoutParameters.
@Test
public void shouldSuccess_whenCreateAServiceWithoutParameters() {
Service service = buildService(Collections.emptyList(), Collections.emptyMap());
given(mockedServiceCreator.doCreate(Collections.emptyList(), Collections.emptyMap())).willReturn(service);
Response response = RESOURCES.target(SERVICES_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.json(PAYLOAD_MAP), Response.class);
assertThat(response.getStatus(), is(201));
String body = response.readEntity(String.class);
JsonPath json = JsonPath.from(body);
assertThat(json.get("name"), is("System Generated"));
assertThat(json.get("external_id"), is(notNullValue()));
assertThat(json.get("redirect_to_service_immediately_on_terminal_state"), is(false));
assertThat(json.get("collect_billing_address"), is(true));
assertThat(json.get("default_billing_address_country"), is("GB"));
assertThat(json.getMap("service_name"), not(hasKey("cy")));
assertEnServiceNameJson("System Generated", json);
assertLinks(json.get("external_id"), json);
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class ServiceResourceCreateTest method shouldSuccess_whenCreateAServiceWithNameOnly.
@Test
public void shouldSuccess_whenCreateAServiceWithNameOnly() {
PAYLOAD_MAP.put("service_name", Map.of(SupportedLanguage.ENGLISH.toString(), EN_SERVICE_NAME));
Service service = buildService(Collections.emptyList(), Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME));
given(mockedServiceCreator.doCreate(Collections.emptyList(), Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME))).willReturn(service);
Response response = RESOURCES.target(SERVICES_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.json(PAYLOAD_MAP), Response.class);
assertThat(response.getStatus(), is(201));
String body = response.readEntity(String.class);
JsonPath json = JsonPath.from(body);
assertThat(json.get("external_id"), is(notNullValue()));
assertThat(json.get("name"), is(EN_SERVICE_NAME));
assertEnServiceNameJson(EN_SERVICE_NAME, json);
assertThat(json.getMap("service_name"), not(hasKey("cy")));
assertLinks(json.get("external_id"), json);
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class ServiceResourceCreateTest method shouldSuccess_whenCreateAServiceWithName_andGatewayAccountIds_andServiceNameVariants_englishAndCymru.
@Test
public void shouldSuccess_whenCreateAServiceWithName_andGatewayAccountIds_andServiceNameVariants_englishAndCymru() {
PAYLOAD_MAP.put(FIELD_NAME, EN_SERVICE_NAME);
String anotherGatewayAccountId = "another-gateway-account-id";
List<String> gatewayAccounts = List.of(GATEWAY_ACCOUNT_ID, anotherGatewayAccountId);
PAYLOAD_MAP.put(FIELD_GATEWAY_ACCOUNT_IDS, gatewayAccounts);
PAYLOAD_MAP.put("service_name", Map.of(SupportedLanguage.ENGLISH.toString(), EN_SERVICE_NAME, SupportedLanguage.WELSH.toString(), CY_SERVICE_NAME));
Map<SupportedLanguage, String> serviceName = Map.of(SupportedLanguage.ENGLISH, EN_SERVICE_NAME, SupportedLanguage.WELSH, CY_SERVICE_NAME);
Service service = buildService(gatewayAccounts, serviceName);
given(mockedServiceCreator.doCreate(gatewayAccounts, serviceName)).willReturn(service);
Response response = RESOURCES.target(SERVICES_RESOURCE).request(MediaType.APPLICATION_JSON).post(Entity.json(PAYLOAD_MAP), Response.class);
assertThat(response.getStatus(), is(201));
String body = response.readEntity(String.class);
JsonPath json = JsonPath.from(body);
assertThat(json.get("name"), is(EN_SERVICE_NAME));
assertThat(json.get("external_id"), is(notNullValue()));
assertEnServiceNameJson(EN_SERVICE_NAME, json);
assertCyServiceNameJson(CY_SERVICE_NAME, json);
assertLinks(json.get("external_id"), json);
assertThat(json.getList("gateway_account_ids"), hasSize(2));
assertThat(json.getList("gateway_account_ids"), containsInAnyOrder(GATEWAY_ACCOUNT_ID, anotherGatewayAccountId));
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class UserInviteCompleterTest method aUser.
private User aUser(String email) {
Service service = Service.from(serviceId, serviceExternalId, new ServiceName(Service.DEFAULT_NAME_VALUE));
ServiceRole serviceRole = ServiceRole.from(service, role(ADMIN.getId(), "Admin", "Administrator"));
return User.from(randomInt(), randomUuid(), "a-username", "random-password", email, "784rh", "8948924", Collections.singletonList(serviceRole), null, SecondFactorMethod.SMS, null, null, null);
}
use of uk.gov.pay.adminusers.model.Service in project pay-adminusers by alphagov.
the class UserDaoIT method shouldAddServiceRoleOfAnExistingUser_whenSettingANewServiceRole.
@Test
public void shouldAddServiceRoleOfAnExistingUser_whenSettingANewServiceRole() {
Role role1 = roleDbFixture(databaseHelper).insertRole();
Role role2 = roleDbFixture(databaseHelper).insertRole();
String gatewayAccountId1 = randomInt().toString();
String gatewayAccountId2 = randomInt().toString();
Service service1 = serviceDbFixture(databaseHelper).withGatewayAccountIds(gatewayAccountId1).insertService();
serviceDbFixture(databaseHelper).withGatewayAccountIds(gatewayAccountId2).insertService();
String username = randomUuid();
String email = username + "@example.com";
userDbFixture(databaseHelper).withServiceRole(service1, role1.getId()).withUsername(username).withEmail(email).insertUser();
UserEntity existingUser = userDao.findByUsername(username).get();
assertThat(existingUser.getGatewayAccountId(), is(gatewayAccountId1));
assertThat(existingUser.getRoles().size(), is(1));
assertThat(existingUser.getRoles().get(0).getId(), is(role1.getId()));
ServiceEntity serviceEntity2 = serviceDao.findByGatewayAccountId(gatewayAccountId2).get();
RoleEntity roleEntity2 = roleDao.findByRoleName(role2.getName()).get();
ServiceRoleEntity serviceRole = new ServiceRoleEntity(serviceEntity2, roleEntity2);
serviceRole.setUser(existingUser);
existingUser.addServiceRole(serviceRole);
userDao.merge(existingUser);
UserEntity changedUser = userDao.findByUsername(username).get();
List<ServiceRoleEntity> servicesRoles = changedUser.getServicesRoles();
assertThat(servicesRoles.size(), is(2));
assertThat(servicesRoles.stream().map(sr -> sr.getService().getExternalId()).collect(toUnmodifiableList()), hasItems(service1.getExternalId(), serviceEntity2.getExternalId()));
assertThat(servicesRoles.stream().map(sr -> sr.getRole().getName()).collect(toUnmodifiableList()), hasItems(role1.getName(), role2.getName()));
}
Aggregations