Search in sources :

Example 26 with ApiEntity

use of io.gravitee.management.model.ApiEntity 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 27 with ApiEntity

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

the class AnalyticsServiceImpl method getAPIMetadata.

private Map<String, String> getAPIMetadata(String api) {
    Map<String, String> metadata = new HashMap<>();
    try {
        ApiEntity apiEntity = apiService.findById(api);
        metadata.put("name", apiEntity.getName());
        metadata.put("version", apiEntity.getVersion());
    } catch (ApiNotFoundException anfe) {
        metadata.put("name", "Deleted API");
        metadata.put("deleted", "true");
    }
    return metadata;
}
Also used : ApiEntity(io.gravitee.management.model.ApiEntity)

Example 28 with ApiEntity

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

the class ApiPagesResourceAdminTest method shouldGetPublicApiPublishedPage.

@Test
public void shouldGetPublicApiPublishedPage() {
    reset(apiService, pageService, membershipService);
    final ApiEntity apiMock = mock(ApiEntity.class);
    when(apiMock.getVisibility()).thenReturn(Visibility.PUBLIC);
    when(apiMock.getName()).thenReturn(API_NAME);
    doReturn(apiMock).when(apiService).findById(API_NAME);
    final PageEntity pageMock = new PageEntity();
    pageMock.setPublished(true);
    pageMock.setName(PAGE_NAME);
    doReturn(pageMock).when(pageService).findById(PAGE_NAME, false);
    final Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    final PageEntity responsePage = response.readEntity(PageEntity.class);
    assertNotNull(responsePage);
    assertEquals(PAGE_NAME, responsePage.getName());
    verify(membershipService, never()).getRole(any(), any(), any(), any());
    verify(apiService, times(1)).findById(API_NAME);
    verify(pageService, times(1)).findById(PAGE_NAME, false);
    verify(pageService, never()).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) Test(org.junit.Test)

Example 29 with ApiEntity

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

the class ApiPagesResourceNotAdminTest method shouldNotGetPrivateApiPublishedPage.

@Test
public void shouldNotGetPrivateApiPublishedPage() {
    reset(apiService, pageService, membershipService);
    final ApiEntity apiMock = mock(ApiEntity.class);
    when(apiMock.getVisibility()).thenReturn(Visibility.PRIVATE);
    when(apiMock.getName()).thenReturn(API_NAME);
    doReturn(apiMock).when(apiService).findById(API_NAME);
    final PageEntity pageMock = new PageEntity();
    pageMock.setPublished(true);
    pageMock.setName(PAGE_NAME);
    doReturn(pageMock).when(pageService).findById(PAGE_NAME, false);
    doReturn(false).when(pageService).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
    doReturn(true).when(roleService).hasPermission(any(), eq(ApiPermission.DOCUMENTATION), eq(new RolePermissionAction[] { RolePermissionAction.READ }));
    when(groupService.isUserAuthorizedToAccessApiData(any(), any(), any())).thenReturn(Boolean.FALSE);
    when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
    final Response response = target().request().get();
    assertEquals(UNAUTHORIZED_401, response.getStatus());
    verify(apiService, atLeastOnce()).findById(API_NAME);
    verify(pageService, times(1)).findById(PAGE_NAME, false);
    verify(pageService, times(1)).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) Response(javax.ws.rs.core.Response) ApiEntity(io.gravitee.management.model.ApiEntity) RolePermissionAction(io.gravitee.management.model.permissions.RolePermissionAction) Test(org.junit.Test)

Example 30 with ApiEntity

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

the class ApiPagesResourceNotAdminTest method shouldGetPublicApiPublishedPage.

@Test
public void shouldGetPublicApiPublishedPage() {
    reset(apiService, pageService, membershipService);
    final ApiEntity apiMock = mock(ApiEntity.class);
    when(apiMock.getVisibility()).thenReturn(Visibility.PUBLIC);
    when(apiMock.getName()).thenReturn(API_NAME);
    doReturn(apiMock).when(apiService).findById(API_NAME);
    final PageEntity pageMock = new PageEntity();
    pageMock.setPublished(true);
    pageMock.setName(PAGE_NAME);
    when(groupService.isUserAuthorizedToAccessApiData(any(), any(), any())).thenReturn(Boolean.TRUE);
    when(permissionService.hasPermission(any(), any(), any())).thenReturn(true);
    doReturn(pageMock).when(pageService).findById(PAGE_NAME, false);
    doReturn(true).when(pageService).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
    final Response response = target().request().get();
    assertEquals(OK_200, response.getStatus());
    final PageEntity responsePage = response.readEntity(PageEntity.class);
    assertNotNull(responsePage);
    assertEquals(PAGE_NAME, responsePage.getName());
    verify(membershipService, never()).getRole(any(), any(), any(), eq(RoleScope.API));
    verify(apiService, times(1)).findById(API_NAME);
    verify(pageService, times(1)).findById(PAGE_NAME, false);
    verify(pageService, times(1)).isDisplayable(apiMock, pageMock.isPublished(), USER_NAME);
}
Also used : PageEntity(io.gravitee.management.model.PageEntity) Response(javax.ws.rs.core.Response) 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