use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_CreateTest method shouldCreateForUser.
@Test
public void shouldCreateForUser() throws TechnicalException {
when(api.getId()).thenReturn(API_ID);
when(api.getName()).thenReturn(API_NAME);
when(api.getVisibility()).thenReturn(Visibility.PRIVATE);
when(api.getLifecycleState()).thenReturn(LifecycleState.STARTED);
when(apiRepository.findById(anyString())).thenReturn(Optional.empty());
when(apiRepository.create(any())).thenReturn(api);
when(newApi.getName()).thenReturn(API_NAME);
when(newApi.getVersion()).thenReturn("v1");
when(newApi.getDescription()).thenReturn("Ma description");
when(newApi.getContextPath()).thenReturn("/context");
when(userService.findById(USER_NAME)).thenReturn(new UserEntity());
when(groupService.findByEvent(any())).thenReturn(Collections.emptySet());
final ApiEntity apiEntity = apiService.create(newApi, USER_NAME);
assertNotNull(apiEntity);
assertEquals(API_NAME, apiEntity.getName());
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class ApiService_FindByIdTest method shouldFindById.
@Test
public void shouldFindById() throws TechnicalException {
when(apiRepository.findById(API_ID)).thenReturn(Optional.of(api));
Membership po = new Membership(USER_NAME, API_ID, MembershipReferenceType.API);
po.setRoles(Collections.singletonMap(RoleScope.API.getId(), SystemRole.PRIMARY_OWNER.name()));
when(membershipRepository.findByReferenceAndRole(any(), any(), any(), any())).thenReturn(Collections.singleton(po));
final ApiEntity apiEntity = apiService.findById(API_ID);
assertNotNull(apiEntity);
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_IsDisplayableTest method shouldBeDisplayablePrivateApiAndPublishedPageAsGroupApiMember.
@Test
public void shouldBeDisplayablePrivateApiAndPublishedPageAsGroupApiMember() throws TechnicalException {
final ApiEntity apiEntityMock = mock(ApiEntity.class);
doReturn(Visibility.PRIVATE).when(apiEntityMock).getVisibility();
when(apiEntityMock.getGroups()).thenReturn(Collections.singleton("groupid"));
doReturn(null).when(membershipServiceMock).getMember(eq(MembershipReferenceType.API), any(), eq(USERNAME), eq(RoleScope.API));
doReturn(mock(MemberEntity.class)).when(membershipServiceMock).getMember(eq(MembershipReferenceType.GROUP), any(), eq(USERNAME), eq(RoleScope.API));
boolean displayable = pageService.isDisplayable(apiEntityMock, true, USERNAME);
assertTrue(displayable);
verify(membershipServiceMock, times(1)).getMember(eq(MembershipReferenceType.API), any(), eq(USERNAME), eq(RoleScope.API));
verify(membershipServiceMock, times(1)).getMember(eq(MembershipReferenceType.GROUP), any(), eq(USERNAME), eq(RoleScope.API));
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_IsDisplayableTest method shouldNotBeDisplayablePrivateApiAndPublishedPageAsNotApiMember.
@Test
public void shouldNotBeDisplayablePrivateApiAndPublishedPageAsNotApiMember() throws TechnicalException {
final ApiEntity apiEntityMock = mock(ApiEntity.class);
doReturn(Visibility.PRIVATE).when(apiEntityMock).getVisibility();
doReturn(null).when(membershipServiceMock).getMember(eq(MembershipReferenceType.API), any(), eq(USERNAME), eq(RoleScope.API));
boolean displayable = pageService.isDisplayable(apiEntityMock, true, USERNAME);
assertFalse(displayable);
verify(membershipServiceMock, times(1)).getMember(eq(MembershipReferenceType.API), any(), eq(USERNAME), eq(RoleScope.API));
verify(membershipServiceMock, never()).getMember(eq(MembershipReferenceType.GROUP), any(), any(), eq(RoleScope.API));
}
use of io.gravitee.management.model.ApiEntity in project gravitee-management-rest-api by gravitee-io.
the class PageService_IsDisplayableTest method shouldBeDisplayablePublicApiAndPublishedPageAsUnauthenticated.
/**
* *************************
* Tests for published pages
* *************************
*/
@Test
public void shouldBeDisplayablePublicApiAndPublishedPageAsUnauthenticated() throws TechnicalException {
final ApiEntity apiEntityMock = mock(ApiEntity.class);
doReturn(Visibility.PUBLIC).when(apiEntityMock).getVisibility();
boolean displayable = pageService.isDisplayable(apiEntityMock, true, null);
assertTrue(displayable);
verify(membershipServiceMock, never()).getMember(any(), any(), any(), any());
}
Aggregations