use of io.gravitee.rest.api.model.MembershipEntity in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_UpdateTest method shouldUpdateBecauseSameApplication.
@Test
public void shouldUpdateBecauseSameApplication() throws TechnicalException {
when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
when(application.getId()).thenReturn(APPLICATION_ID);
Map<String, String> metadata = new HashMap<>();
metadata.put("client_id", CLIENT_ID);
when(application.getMetadata()).thenReturn(metadata);
ApplicationSettings settings = new ApplicationSettings();
SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
clientSettings.setClientId(CLIENT_ID);
settings.setApp(clientSettings);
when(existingApplication.getSettings()).thenReturn(settings);
when(application.getName()).thenReturn(APPLICATION_NAME);
when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
when(application.getType()).thenReturn(ApplicationType.SIMPLE);
when(existingApplication.getName()).thenReturn(APPLICATION_NAME);
when(existingApplication.getDescription()).thenReturn("My description");
when(applicationRepository.update(any())).thenReturn(application);
when(roleService.findPrimaryOwnerRoleByOrganization(any(), any())).thenReturn(mock(RoleEntity.class));
MembershipEntity po = new MembershipEntity();
po.setMemberId(USER_NAME);
po.setMemberType(MembershipMemberType.USER);
po.setReferenceId(APPLICATION_ID);
po.setReferenceType(MembershipReferenceType.APPLICATION);
po.setRoleId("APPLICATION_PRIMARY_OWNER");
when(membershipService.getMembershipsByReferencesAndRole(any(), any(), any())).thenReturn(Collections.singleton(po));
final ApplicationEntity applicationEntity = applicationService.update(APPLICATION_ID, existingApplication);
verify(applicationRepository).update(argThat(application -> APPLICATION_NAME.equals(application.getName()) && application.getUpdatedAt() != null));
assertNotNull(applicationEntity);
assertEquals(APPLICATION_NAME, applicationEntity.getName());
}
Aggregations