use of io.gravitee.repository.management.model.Application in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_UpdateTest method shouldNotUpdateBecauseDifferentApplication.
@Test(expected = ClientIdAlreadyExistsException.class)
public void shouldNotUpdateBecauseDifferentApplication() throws TechnicalException {
Application other = mock(Application.class);
when(other.getId()).thenReturn("other-app");
when(other.getClientId()).thenReturn(CLIENT_ID);
when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
when(applicationRepository.findAll(ApplicationStatus.ACTIVE)).thenReturn(Sets.newSet(other));
when(application.getId()).thenReturn(APPLICATION_ID);
when(existingApplication.getClientId()).thenReturn(CLIENT_ID);
applicationService.update(APPLICATION_ID, existingApplication);
}
use of io.gravitee.repository.management.model.Application in project gravitee-management-rest-api by gravitee-io.
the class ApplicationService_UpdateTest method shouldUpdate.
@Test
public void shouldUpdate() throws TechnicalException {
when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
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());
}
use of io.gravitee.repository.management.model.Application 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