Search in sources :

Example 1 with Application

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);
}
Also used : Application(io.gravitee.repository.management.model.Application) Test(org.junit.Test)

Example 2 with Application

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());
}
Also used : ApplicationEntity(io.gravitee.management.model.ApplicationEntity) UpdateApplicationEntity(io.gravitee.management.model.UpdateApplicationEntity) ArgumentMatcher(org.mockito.ArgumentMatcher) Membership(io.gravitee.repository.management.model.Membership) Application(io.gravitee.repository.management.model.Application) Test(org.junit.Test)

Example 3 with Application

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());
}
Also used : ApplicationEntity(io.gravitee.management.model.ApplicationEntity) UpdateApplicationEntity(io.gravitee.management.model.UpdateApplicationEntity) ArgumentMatcher(org.mockito.ArgumentMatcher) Membership(io.gravitee.repository.management.model.Membership) Application(io.gravitee.repository.management.model.Application) Test(org.junit.Test)

Aggregations

Application (io.gravitee.repository.management.model.Application)3 Test (org.junit.Test)3 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)2 UpdateApplicationEntity (io.gravitee.management.model.UpdateApplicationEntity)2 Membership (io.gravitee.repository.management.model.Membership)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2