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