Search in sources :

Example 46 with ApiEntity

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());
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) NewApiEntity(io.gravitee.management.model.NewApiEntity) UserEntity(io.gravitee.management.model.UserEntity) Test(org.junit.Test)

Example 47 with ApiEntity

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);
}
Also used : Membership(io.gravitee.repository.management.model.Membership) ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 48 with 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));
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) MemberEntity(io.gravitee.management.model.MemberEntity) Test(org.junit.Test)

Example 49 with ApiEntity

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));
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 50 with ApiEntity

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());
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Aggregations

ApiEntity (io.gravitee.management.model.ApiEntity)50 Test (org.junit.Test)34 Response (javax.ws.rs.core.Response)19 UpdateApiEntity (io.gravitee.management.model.UpdateApiEntity)13 PageEntity (io.gravitee.management.model.PageEntity)5 NewApiEntity (io.gravitee.management.model.NewApiEntity)4 NewTopApiEntity (io.gravitee.management.model.NewTopApiEntity)3 TopApiEntity (io.gravitee.management.model.TopApiEntity)3 UpdateTopApiEntity (io.gravitee.management.model.UpdateTopApiEntity)3 Permission (io.gravitee.management.rest.security.Permission)3 HashMap (java.util.HashMap)3 Collectors (java.util.stream.Collectors)3 Proxy (io.gravitee.definition.model.Proxy)2 ApplicationEntity (io.gravitee.management.model.ApplicationEntity)2 MemberEntity (io.gravitee.management.model.MemberEntity)2 SubscriptionEntity (io.gravitee.management.model.SubscriptionEntity)2 UserEntity (io.gravitee.management.model.UserEntity)2 RolePermission (io.gravitee.management.model.permissions.RolePermission)2 RolePermissionAction (io.gravitee.management.model.permissions.RolePermissionAction)2 SubscriptionQuery (io.gravitee.management.model.subscription.SubscriptionQuery)2