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