use of io.gravitee.management.model.ApplicationEntity 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(applicationRepository.findByClientId(CLIENT_ID)).thenReturn(Optional.of(application));
when(application.getId()).thenReturn(APPLICATION_ID);
when(application.getClientId()).thenReturn(CLIENT_ID);
when(existingApplication.getClientId()).thenReturn(CLIENT_ID);
when(application.getName()).thenReturn(APPLICATION_NAME);
when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
when(existingApplication.getName()).thenReturn(APPLICATION_NAME);
when(existingApplication.getDescription()).thenReturn("My description");
when(applicationRepository.update(any())).thenReturn(application);
Membership po = new Membership(USER_NAME, APPLICATION_ID, MembershipReferenceType.APPLICATION);
po.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferencesAndRole(any(), any(), eq(RoleScope.APPLICATION), any())).thenReturn(Collections.singleton(po));
final ApplicationEntity applicationEntity = applicationService.update(APPLICATION_ID, existingApplication);
verify(applicationRepository).update(argThat(new ArgumentMatcher<Application>() {
public boolean matches(Object argument) {
final Application application = (Application) argument;
return APPLICATION_NAME.equals(application.getName()) && application.getUpdatedAt() != null;
}
}));
assertNotNull(applicationEntity);
assertEquals(APPLICATION_NAME, applicationEntity.getName());
}
Aggregations