Search in sources :

Example 6 with Membership

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

the class ApiService_UpdateTest method testUpdateWithContextPath.

private void testUpdateWithContextPath(String existingContextPath, String contextPathToCreate) throws TechnicalException {
    when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
    when(apiRepository.update(any())).thenReturn(api);
    when(api.getId()).thenReturn(API_ID2);
    when(api.getName()).thenReturn(API_NAME);
    when(existingApi.getName()).thenReturn(API_NAME);
    when(existingApi.getVersion()).thenReturn("v1");
    when(existingApi.getDescription()).thenReturn("Ma description");
    final Proxy proxy = mock(Proxy.class);
    when(existingApi.getProxy()).thenReturn(proxy);
    when(proxy.getContextPath()).thenReturn(contextPathToCreate);
    when(apiRepository.findAll()).thenReturn(new HashSet<>(Collections.singletonList(api)));
    when(api.getDefinition()).thenReturn("{\"id\": \"" + API_ID + "\",\"name\": \"" + API_NAME + "\",\"proxy\": {\"context_path\": \"" + existingContextPath + "\"}}");
    Membership po1 = new Membership("admin", API_ID, MembershipReferenceType.API);
    po1.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
    when(membershipRepository.findByReferencesAndRole(MembershipReferenceType.API, Collections.singletonList(API_ID), RoleScope.API, SystemRole.PRIMARY_OWNER.name())).thenReturn(Collections.singleton(po1));
    Membership po2 = new Membership("admin", API_ID2, MembershipReferenceType.API);
    po2.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
    when(membershipRepository.findByReferencesAndRole(MembershipReferenceType.API, Collections.singletonList(API_ID2), RoleScope.API, SystemRole.PRIMARY_OWNER.name())).thenReturn(Collections.singleton(po2));
    apiService.update(API_ID, existingApi);
}
Also used : Proxy(io.gravitee.definition.model.Proxy) Membership(io.gravitee.repository.management.model.Membership)

Example 7 with Membership

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

the class ApiService_UpdateTest method shouldUpdate.

@Test
public void shouldUpdate() throws TechnicalException {
    when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
    when(apiRepository.update(any())).thenReturn(api);
    when(api.getName()).thenReturn(API_NAME);
    when(existingApi.getName()).thenReturn(API_NAME);
    when(existingApi.getVersion()).thenReturn("v1");
    when(existingApi.getDescription()).thenReturn("Ma description");
    final Proxy proxy = mock(Proxy.class);
    when(existingApi.getProxy()).thenReturn(proxy);
    when(proxy.getContextPath()).thenReturn("/context");
    Membership po = new Membership(USER_NAME, API_ID, MembershipReferenceType.API);
    po.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
    when(membershipRepository.findByReferencesAndRole(any(), any(), any(), any())).thenReturn(Collections.singleton(po));
    final ApiEntity apiEntity = apiService.update(API_ID, existingApi);
    assertNotNull(apiEntity);
    assertEquals(API_NAME, apiEntity.getName());
}
Also used : Proxy(io.gravitee.definition.model.Proxy) Membership(io.gravitee.repository.management.model.Membership) ApiEntity(io.gravitee.management.model.ApiEntity) UpdateApiEntity(io.gravitee.management.model.UpdateApiEntity) Test(org.junit.Test)

Example 8 with Membership

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

the class ApplicationService_FindByIdTest method shouldFindById.

@Test
public void shouldFindById() throws TechnicalException {
    when(applicationRepository.findById(APPLICATION_ID)).thenReturn(Optional.of(application));
    when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
    Membership po = new Membership(USER_NAME, APPLICATION_ID, MembershipReferenceType.APPLICATION);
    po.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
    when(membershipRepository.findByReferenceAndRole(any(), any(), eq(RoleScope.APPLICATION), any())).thenReturn(Collections.singleton(po));
    when(userService.findByUsername(USER_NAME, false)).thenReturn(new UserEntity());
    final ApplicationEntity applicationEntity = applicationService.findById(APPLICATION_ID);
    assertNotNull(applicationEntity);
}
Also used : ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Membership(io.gravitee.repository.management.model.Membership) UserEntity(io.gravitee.management.model.UserEntity) Test(org.junit.Test)

Example 9 with Membership

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

the class ApplicationService_FindByUserTest method shouldFindByUserAndGroup.

@Test
public void shouldFindByUserAndGroup() throws Exception {
    when(appMembership.getReferenceId()).thenReturn(APPLICATION_ID);
    when(groupAppMembership.getReferenceId()).thenReturn(GROUP_APPLICATION_ID);
    when(groupAppMembership.getRoles()).thenReturn(Collections.singletonMap(RoleScope.APPLICATION.getId(), "USER"));
    when(application.getId()).thenReturn(APPLICATION_ID);
    when(application.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
    when(groupApplication.getId()).thenReturn(GROUP_APPLICATION_ID);
    when(groupApplication.getStatus()).thenReturn(ApplicationStatus.ACTIVE);
    when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.APPLICATION)).thenReturn(Collections.singleton(appMembership));
    when(applicationRepository.findByIds(Collections.singletonList(APPLICATION_ID))).thenReturn(Collections.singleton(application));
    when(membershipRepository.findByUserAndReferenceType(USERNAME, MembershipReferenceType.GROUP)).thenReturn(Collections.singleton(groupAppMembership));
    when(applicationRepository.findByGroups(Collections.singletonList(GROUP_APPLICATION_ID), ApplicationStatus.ACTIVE)).thenReturn(Collections.singleton(groupApplication));
    Membership poApp = new Membership(USERNAME, APPLICATION_ID, MembershipReferenceType.APPLICATION);
    poApp.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
    Membership poGroupApp = new Membership(USERNAME, GROUP_APPLICATION_ID, MembershipReferenceType.APPLICATION);
    poGroupApp.setRoles(Collections.singletonMap(RoleScope.APPLICATION.getId(), SystemRole.PRIMARY_OWNER.name()));
    Set<Membership> memberships = new HashSet<>();
    memberships.add(poApp);
    memberships.add(poGroupApp);
    when(membershipRepository.findByReferencesAndRole(any(), any(), eq(RoleScope.APPLICATION), any())).thenReturn(memberships);
    when(userService.findByUsername(USERNAME, false)).thenReturn(new UserEntity());
    Set<ApplicationEntity> apps = applicationService.findByUser(USERNAME);
    Assert.assertNotNull(apps);
    Assert.assertFalse("should find apps", apps.isEmpty());
    Assert.assertEquals(2, apps.size());
}
Also used : ApplicationEntity(io.gravitee.management.model.ApplicationEntity) Membership(io.gravitee.repository.management.model.Membership) UserEntity(io.gravitee.management.model.UserEntity) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 10 with Membership

use of io.gravitee.repository.management.model.Membership 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)

Aggregations

Membership (io.gravitee.repository.management.model.Membership)20 Test (org.junit.Test)15 UserEntity (io.gravitee.management.model.UserEntity)8 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)6 RoleEntity (io.gravitee.management.model.RoleEntity)4 MemberEntity (io.gravitee.management.model.MemberEntity)3 TechnicalException (io.gravitee.repository.exceptions.TechnicalException)3 Proxy (io.gravitee.definition.model.Proxy)2 io.gravitee.management.model (io.gravitee.management.model)2 ApiEntity (io.gravitee.management.model.ApiEntity)2 GroupEntity (io.gravitee.management.model.GroupEntity)2 UpdateApplicationEntity (io.gravitee.management.model.UpdateApplicationEntity)2 Application (io.gravitee.repository.management.model.Application)2 Date (java.util.Date)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 PropertyFilter (com.fasterxml.jackson.databind.ser.PropertyFilter)1 SimpleFilterProvider (com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider)1 Path (io.gravitee.definition.model.Path)1 Policy (io.gravitee.definition.model.Policy)1 UpdateApiEntity (io.gravitee.management.model.UpdateApiEntity)1