Search in sources :

Example 11 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class PermissionsResourceTest method init.

@Before
public void init() {
    resetAllMocks();
    ApiEntity mockApi = new ApiEntity();
    mockApi.setId(API);
    Set<ApiEntity> mockApis = new HashSet<>(Arrays.asList(mockApi));
    doReturn(mockApis).when(apiService).findPublishedByUser(any(), any());
    ApplicationListItem mockAppListItem = new ApplicationListItem();
    mockAppListItem.setId(APPLICATION);
    Set<ApplicationListItem> mockApps = new HashSet<>(Arrays.asList(mockAppListItem));
    doReturn(mockApps).when(applicationService).findByUser(any());
    ApplicationEntity mockAppEntity = new ApplicationEntity();
    mockAppEntity.setId(APPLICATION);
    doReturn(mockAppEntity).when(applicationService).findById(any());
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) ApiEntity(io.gravitee.rest.api.model.api.ApiEntity) Before(org.junit.Before)

Example 12 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationService_UpdateTest method shouldUpdate.

@Test
public void shouldUpdate() throws TechnicalException {
    ApplicationSettings settings = new ApplicationSettings();
    SimpleApplicationSettings clientSettings = new SimpleApplicationSettings();
    clientSettings.setClientId(CLIENT_ID);
    settings.setApp(clientSettings);
    when(existingApplication.getSettings()).thenReturn(settings);
    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(application.getType()).thenReturn(ApplicationType.SIMPLE);
    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());
}
Also used : RoleEntity(io.gravitee.rest.api.model.RoleEntity) ArgumentMatchers(org.mockito.ArgumentMatchers) Mock(org.mockito.Mock) TechnicalException(io.gravitee.repository.exceptions.TechnicalException) RunWith(org.junit.runner.RunWith) HashMap(java.util.HashMap) ClientRegistrationService(io.gravitee.rest.api.service.configuration.application.ClientRegistrationService) TechnicalManagementException(io.gravitee.rest.api.service.exceptions.TechnicalManagementException) Sets(org.mockito.internal.util.collections.Sets) UserService(io.gravitee.rest.api.service.UserService) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) Map(java.util.Map) ApplicationRepository(io.gravitee.repository.management.api.ApplicationRepository) MembershipMemberType(io.gravitee.rest.api.model.MembershipMemberType) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) ParameterService(io.gravitee.rest.api.service.ParameterService) InjectMocks(org.mockito.InjectMocks) MembershipEntity(io.gravitee.rest.api.model.MembershipEntity) Assert.assertNotNull(org.junit.Assert.assertNotNull) AuditService(io.gravitee.rest.api.service.AuditService) ClientIdAlreadyExistsException(io.gravitee.rest.api.service.exceptions.ClientIdAlreadyExistsException) Test(org.junit.Test) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) RoleEntity(io.gravitee.rest.api.model.RoleEntity) Mockito(org.mockito.Mockito) MembershipReferenceType(io.gravitee.rest.api.model.MembershipReferenceType) SubscriptionService(io.gravitee.rest.api.service.SubscriptionService) io.gravitee.repository.management.model(io.gravitee.repository.management.model) Optional(java.util.Optional) ApplicationNotFoundException(io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException) Collections(java.util.Collections) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Assert.assertEquals(org.junit.Assert.assertEquals) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) ApplicationServiceImpl(io.gravitee.rest.api.service.impl.ApplicationServiceImpl) ApplicationSettings(io.gravitee.rest.api.model.application.ApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) SimpleApplicationSettings(io.gravitee.rest.api.model.application.SimpleApplicationSettings) MembershipEntity(io.gravitee.rest.api.model.MembershipEntity) UpdateApplicationEntity(io.gravitee.rest.api.model.UpdateApplicationEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Test(org.junit.Test)

Example 13 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationMapperTest method init.

@Before
public void init() {
    now = Instant.now();
    Date nowDate = Date.from(now);
    applicationEntity = new ApplicationEntity();
    applicationListItem = new ApplicationListItem();
    // init
    reset(groupService);
    reset(userService);
    reset(userMapper);
    GroupEntity grpEntity = new GroupEntity();
    grpEntity.setId(APPLICATION_GROUP_ID);
    grpEntity.setName(APPLICATION_GROUP_NAME);
    when(groupService.findById(APPLICATION_GROUP_ID)).thenReturn(grpEntity);
    UserEntity userEntity = Mockito.mock(UserEntity.class);
    when(userEntity.getDisplayName()).thenReturn(APPLICATION_USER_DISPLAYNAME);
    when(userEntity.getEmail()).thenReturn(APPLICATION_USER_EMAIL);
    when(userEntity.getId()).thenReturn(APPLICATION_USER_ID);
    when(userService.findById(APPLICATION_USER_ID)).thenReturn(userEntity);
    when(userMapper.convert(userEntity)).thenCallRealMethod();
    when(userMapper.computeUserLinks(anyString(), any())).thenCallRealMethod();
    PrimaryOwnerEntity primaryOwner = new PrimaryOwnerEntity(userEntity);
    when(uriInfo.getBaseUriBuilder()).thenReturn(UriBuilder.fromPath(""));
    applicationEntity.setCreatedAt(nowDate);
    applicationEntity.setDescription(APPLICATION_DESCRIPTION);
    applicationEntity.setGroups(new HashSet<String>(Arrays.asList(APPLICATION_GROUP_ID)));
    applicationEntity.setId(APPLICATION_ID);
    applicationEntity.setName(APPLICATION_NAME);
    applicationEntity.setPrimaryOwner(primaryOwner);
    applicationEntity.setStatus(APPLICATION_STATUS);
    applicationEntity.setType(APPLICATION_TYPE);
    applicationEntity.setUpdatedAt(nowDate);
    applicationListItem.setCreatedAt(nowDate);
    applicationListItem.setDescription(APPLICATION_DESCRIPTION);
    applicationListItem.setGroups(new HashSet<String>(Arrays.asList(APPLICATION_GROUP_ID)));
    applicationListItem.setId(APPLICATION_ID);
    applicationListItem.setName(APPLICATION_NAME);
    applicationListItem.setPrimaryOwner(primaryOwner);
    applicationListItem.setStatus(APPLICATION_STATUS);
    applicationListItem.setType(APPLICATION_TYPE);
    applicationListItem.setUpdatedAt(nowDate);
}
Also used : ApplicationListItem(io.gravitee.rest.api.model.application.ApplicationListItem) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) GroupEntity(io.gravitee.rest.api.model.GroupEntity) PrimaryOwnerEntity(io.gravitee.rest.api.model.PrimaryOwnerEntity) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Date(java.util.Date) UserEntity(io.gravitee.rest.api.model.UserEntity) Before(org.junit.Before)

Example 14 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class PermissionFilterTest method shouldBeAuthorizedWhenApplicationPermissions.

@Test
public void shouldBeAuthorizedWhenApplicationPermissions() {
    ApplicationEntity application = initApplicationMocks();
    when(roleService.hasPermission(any(), any(), any())).thenReturn(true);
    permissionFilter.filter(permissions, containerRequestContext);
    verify(apiService, never()).findById(any());
    verify(applicationService, times(1)).findById(application.getId());
    verify(roleService, times(1)).hasPermission(any(), any(), any());
    verify(membershipService, times(1)).getUserMemberPermissions(application, USERNAME);
    verify(membershipService, never()).getRoles(any(), any(), any(), any());
}
Also used : ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Test(org.junit.Test)

Example 15 with ApplicationEntity

use of io.gravitee.rest.api.model.ApplicationEntity in project gravitee-management-rest-api by gravitee-io.

the class ApplicationAlertServiceTest method shouldNotCreateMappingError.

@Test(expected = TechnicalManagementException.class)
public void shouldNotCreateMappingError() throws Exception {
    NewAlertTriggerEntity newAlert = new NewAlertTriggerEntity();
    newAlert.setId(ALERT_ID);
    newAlert.setType("METRICS_RATE");
    ApplicationEntity application = getApplication();
    prepareForCreation(newAlert);
    when(applicationService.findById(APPLICATION_ID)).thenReturn(application);
    when(mapper.writeValueAsString(any())).thenThrow(JsonProcessingException.class);
    cut.create(APPLICATION_ID, newAlert);
}
Also used : NewAlertTriggerEntity(io.gravitee.rest.api.model.alert.NewAlertTriggerEntity) ApplicationEntity(io.gravitee.rest.api.model.ApplicationEntity) Test(org.junit.Test)

Aggregations

ApplicationEntity (io.gravitee.rest.api.model.ApplicationEntity)38 Test (org.junit.Test)19 Response (javax.ws.rs.core.Response)8 ApplicationSettings (io.gravitee.rest.api.model.application.ApplicationSettings)7 SimpleApplicationSettings (io.gravitee.rest.api.model.application.SimpleApplicationSettings)7 NewApplicationEntity (io.gravitee.rest.api.model.NewApplicationEntity)6 ApplicationListItem (io.gravitee.rest.api.model.application.ApplicationListItem)6 UserEntity (io.gravitee.rest.api.model.UserEntity)5 ApiEntity (io.gravitee.rest.api.model.api.ApiEntity)5 Application (io.gravitee.rest.api.portal.rest.model.Application)5 UpdateApplicationEntity (io.gravitee.rest.api.model.UpdateApplicationEntity)4 Before (org.junit.Before)4 SubscriptionEntity (io.gravitee.rest.api.model.SubscriptionEntity)3 NewAlertTriggerEntity (io.gravitee.rest.api.model.alert.NewAlertTriggerEntity)3 OAuthClientSettings (io.gravitee.rest.api.model.application.OAuthClientSettings)3 Permissions (io.gravitee.rest.api.portal.rest.security.Permissions)3 UserService (io.gravitee.rest.api.service.UserService)3 ApplicationNotFoundException (io.gravitee.rest.api.service.exceptions.ApplicationNotFoundException)3 ForbiddenAccessException (io.gravitee.rest.api.service.exceptions.ForbiddenAccessException)3 MediaType (io.gravitee.common.http.MediaType)2