use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UsersResourceTest method shouldFinalizeRegistration.
@Test
public void shouldFinalizeRegistration() {
// init
FinalizeRegistrationInput input = new FinalizeRegistrationInput().token("token").password("P4s5vv0Rd").firstname("Firstname").lastname("LASTNAME");
RegisterUserEntity registerUserEntity = new RegisterUserEntity();
doReturn(registerUserEntity).when(userMapper).convert(input);
doReturn(new UserEntity()).when(userService).finalizeRegistration(registerUserEntity);
// test
final Response response = target("registration/_finalize").request().post(Entity.json(input));
assertEquals(HttpStatusCode.OK_200, response.getStatus());
Mockito.verify(userMapper).convert(input);
Mockito.verify(userService).finalizeRegistration(registerUserEntity);
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class MembershipCommandHandlerTest method handleWithAdminRole.
@Test
public void handleWithAdminRole() {
MembershipPayload membershipPayload = new MembershipPayload();
membershipPayload.setUserId("user#1");
membershipPayload.setOrganizationId("orga#1");
membershipPayload.setReferenceType(MembershipReferenceType.ENVIRONMENT.name());
membershipPayload.setReferenceId("env#1");
membershipPayload.setRole("ENVIRONMENT_PRIMARY_OWNER");
MembershipCommand command = new MembershipCommand(membershipPayload);
UserEntity user = new UserEntity();
user.setId(UUID.random().toString());
RoleEntity role = new RoleEntity();
role.setId(UUID.random().toString());
role.setScope(RoleScope.ENVIRONMENT);
role.setName("ADMIN");
when(userService.findBySource(COCKPIT_SOURCE, membershipPayload.getUserId(), false)).thenReturn(user);
when(roleService.findByScopeAndName(RoleScope.ENVIRONMENT, "ADMIN")).thenReturn(Optional.of(role));
TestObserver<MembershipReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertNoErrors();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
ArgumentCaptor<MembershipService.MembershipReference> membershipReference = ArgumentCaptor.forClass(MembershipService.MembershipReference.class);
ArgumentCaptor<MembershipService.MembershipMember> membershipMember = ArgumentCaptor.forClass(MembershipService.MembershipMember.class);
ArgumentCaptor<List<MembershipService.MembershipRole>> membershipRoles = ArgumentCaptor.forClass(List.class);
verify(membershipService).updateRolesToMemberOnReference(membershipReference.capture(), membershipMember.capture(), membershipRoles.capture(), eq(COCKPIT_SOURCE), eq(false));
assertEquals(MembershipReferenceType.ENVIRONMENT, membershipReference.getValue().getType());
assertEquals(membershipPayload.getReferenceId(), membershipReference.getValue().getId());
assertEquals(MembershipMemberType.USER, membershipMember.getValue().getMemberType());
assertEquals(user.getId(), membershipMember.getValue().getMemberId());
assertTrue(membershipRoles.getValue().size() == 1 && membershipRoles.getValue().stream().allMatch(membershipRole -> membershipRole.getScope() == role.getScope() && membershipRole.getName().equals(role.getName())));
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class MembershipCommandHandlerTest method handleWithUnknownRole.
@Test
public void handleWithUnknownRole() {
MembershipPayload membershipPayload = new MembershipPayload();
membershipPayload.setUserId("user#1");
membershipPayload.setOrganizationId("orga#1");
membershipPayload.setReferenceType(MembershipReferenceType.ENVIRONMENT.name());
membershipPayload.setReferenceId("env#1");
membershipPayload.setRole("UNKNOWN");
MembershipCommand command = new MembershipCommand(membershipPayload);
UserEntity user = new UserEntity();
user.setId(UUID.random().toString());
RoleEntity role = new RoleEntity();
role.setId(UUID.random().toString());
when(userService.findBySource(COCKPIT_SOURCE, membershipPayload.getUserId(), false)).thenReturn(user);
when(roleService.findByScopeAndName(RoleScope.ENVIRONMENT, "UNKNOWN")).thenReturn(Optional.empty());
TestObserver<MembershipReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertNoErrors();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.ERROR));
verifyZeroInteractions(membershipService);
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserCommandHandlerTest method handleUpdate.
@Test
public void handleUpdate() {
UserPayload userPayload = new UserPayload();
UserCommand command = new UserCommand(userPayload);
final String sourceId = "user#1";
userPayload.setId(sourceId);
userPayload.setOrganizationId("orga#1");
userPayload.setUsername("New Username");
userPayload.setFirstName("New Firstname");
userPayload.setLastName("New Lastname");
userPayload.setPicture("https://gravitee.io/my-new-picture");
userPayload.setEmail("my-new-email@gravitee.io");
HashMap<String, Object> additionalInformation = new HashMap<>();
additionalInformation.put("info1", "new_value1");
additionalInformation.put("new_info3", "new_value3");
userPayload.setAdditionalInformation(additionalInformation);
UserEntity existingCockpitUser = new UserEntity();
existingCockpitUser.setId("apim_user#1");
existingCockpitUser.setSourceId(sourceId);
existingCockpitUser.setSource("cockpit");
existingCockpitUser.setFirstname("Firstname");
existingCockpitUser.setLastname("Lastname");
existingCockpitUser.setEmail("email@gravitee.io");
existingCockpitUser.setPicture("https://gravitee.io/picture");
HashMap<String, Object> customFields = new HashMap<>();
customFields.put("info1", "value1");
customFields.put("info2", "value2");
existingCockpitUser.setCustomFields(customFields);
when(userService.findBySource("cockpit", sourceId, false)).thenReturn(existingCockpitUser);
when(userService.update(eq("apim_user#1"), argThat(updatedUser -> updatedUser.getFirstname().equals(userPayload.getFirstName()) && updatedUser.getLastname().equals(userPayload.getLastName()) && updatedUser.getEmail().equals(userPayload.getEmail()) && updatedUser.getPicture().equals(userPayload.getPicture()) && updatedUser.getCustomFields().get("info1").equals(additionalInformation.get("info1")) && updatedUser.getCustomFields().get("new_info3").equals(additionalInformation.get("new_info3")) && updatedUser.getCustomFields().get(PICTURE).equals(userPayload.getPicture()) && updatedUser.getCustomFields().get(SUB).equals(userPayload.getUsername())))).thenReturn(new UserEntity());
TestObserver<UserReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
use of io.gravitee.rest.api.model.UserEntity in project gravitee-management-rest-api by gravitee-io.
the class UserCommandHandlerTest method handleCreation.
@Test
public void handleCreation() {
UserPayload userPayload = new UserPayload();
UserCommand command = new UserCommand(userPayload);
final String sourceId = "user#1";
userPayload.setId(sourceId);
userPayload.setOrganizationId("orga#1");
userPayload.setUsername("Username");
userPayload.setFirstName("Firstname");
userPayload.setLastName("Lastname");
userPayload.setPicture("https://gravitee.io/my-picture");
userPayload.setEmail("email@gravitee.io");
HashMap<String, Object> additionalInformation = new HashMap<>();
additionalInformation.put("info1", "value1");
additionalInformation.put("info2", "value2");
userPayload.setAdditionalInformation(additionalInformation);
when(userService.findBySource("cockpit", sourceId, false)).thenThrow(new UserNotFoundException(sourceId));
when(userService.create(argThat(newUser -> newUser.getSourceId().equals(userPayload.getId()) && newUser.getSource().equals("cockpit") && newUser.getFirstname().equals(userPayload.getFirstName()) && newUser.getLastname().equals(userPayload.getLastName()) && newUser.getEmail().equals(userPayload.getEmail()) && newUser.getPicture().equals(userPayload.getPicture()) && newUser.getCustomFields().get("info1").equals(additionalInformation.get("info1")) && newUser.getCustomFields().get("info2").equals(additionalInformation.get("info2")) && newUser.getCustomFields().get(PICTURE).equals(userPayload.getPicture()) && newUser.getCustomFields().get(SUB).equals(userPayload.getUsername())), eq(false))).thenReturn(new UserEntity());
TestObserver<UserReply> obs = cut.handle(command).test();
obs.awaitTerminalEvent();
obs.assertValue(reply -> reply.getCommandId().equals(command.getId()) && reply.getCommandStatus().equals(CommandStatus.SUCCEEDED));
}
Aggregations