Search in sources :

Example 16 with ApplicationEntity

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());
}
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

ApplicationEntity (io.gravitee.management.model.ApplicationEntity)16 Test (org.junit.Test)9 Membership (io.gravitee.repository.management.model.Membership)6 UserEntity (io.gravitee.management.model.UserEntity)5 Permission (io.gravitee.management.rest.security.Permission)4 RolePermission (io.gravitee.management.model.permissions.RolePermission)3 Permissions (io.gravitee.management.rest.security.Permissions)3 MediaType (io.gravitee.common.http.MediaType)2 ApiEntity (io.gravitee.management.model.ApiEntity)2 UpdateApplicationEntity (io.gravitee.management.model.UpdateApplicationEntity)2 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)2 ApplicationService (io.gravitee.management.service.ApplicationService)2 Application (io.gravitee.repository.management.model.Application)2 Api (io.swagger.annotations.Api)2 Principal (java.security.Principal)2 Function (java.util.function.Function)2 Collectors (java.util.stream.Collectors)2 Inject (javax.inject.Inject)2 GET (javax.ws.rs.GET)2 Produces (javax.ws.rs.Produces)2