use of org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO in project carbon-apimgt by wso2.
the class ResourcesApiServiceImplTestCase method resourcesGetApiVersionEmptyTest.
@Test
public void resourcesGetApiVersionEmptyTest() throws Exception {
Response response = getResponse(API_CONTEXT, null);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(((ResourcesListDTO) response.getEntity()).getList().size(), 0);
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO in project carbon-apimgt by wso2.
the class ResourcesApiServiceImplTestCase method resourcesGetApiContextEmptyTest.
@Test
public void resourcesGetApiContextEmptyTest() throws Exception {
Response response = getResponse(null, API_VERSION);
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(((ResourcesListDTO) response.getEntity()).getList().size(), 0);
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO in project carbon-apimgt by wso2.
the class ResourcesApiServiceImpl method resourcesGet.
@Override
public Response resourcesGet(String apiContext, String apiVersion, String accept, Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<UriTemplate> resourcesOfApi = new ArrayList<>();
if (!StringUtils.isEmpty(apiContext) && !StringUtils.isEmpty(apiVersion)) {
resourcesOfApi = apiMgtAdminService.getAllResourcesForApi(apiContext, apiVersion);
}
ResourcesListDTO resourcesListDTO = new ResourcesListDTO();
resourcesListDTO.setList(MappingUtil.convertToResourceListDto(resourcesOfApi));
return Response.ok(resourcesListDTO).build();
} catch (APIManagementException e) {
String errorMessage = "Error while retrieving resources.";
Map<String, String> paramList = new HashMap<String, String>();
if (!StringUtils.isEmpty(apiContext)) {
paramList.put(APIMgtConstants.ExceptionsConstants.API_CONTEXT, apiContext);
}
if (!StringUtils.isEmpty(apiVersion)) {
paramList.put(APIMgtConstants.ExceptionsConstants.API_VERSION, apiVersion);
}
org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
log.error(errorMessage, e);
return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
}
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO in project carbon-apimgt by wso2.
the class MappingUtil method convertToResourceListDto.
/**
* Convert Uritemplate list to UriTemplateDTO list
*
* @param resourcesOfApi list of uriTemplates
* @return ResourcesListDTO
*/
public static List<UriTemplateDTO> convertToResourceListDto(List<UriTemplate> resourcesOfApi) {
List<UriTemplateDTO> uriTemplateDTOArrayList = new ArrayList<>();
resourcesOfApi.forEach((v) -> {
UriTemplateDTO uriTemplateDTO = new UriTemplateDTO();
uriTemplateDTO.setUriTemplate(v.getUriTemplate());
uriTemplateDTO.setAuthType(v.getAuthType());
uriTemplateDTO.setPolicy(v.getPolicy().getUuid());
uriTemplateDTO.setHttpVerb(v.getHttpVerb());
uriTemplateDTO.setScope("");
uriTemplateDTOArrayList.add(uriTemplateDTO);
});
return uriTemplateDTOArrayList;
}
use of org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO in project carbon-apimgt by wso2.
the class ResourcesApiServiceImplTestCase method resourcesGetTest.
@Test
public void resourcesGetTest() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
APIManagerFactory instance = Mockito.mock(APIManagerFactory.class);
PowerMockito.mockStatic(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(instance);
Mockito.when(instance.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
ResourcesApiServiceImpl resourcesApiService = new ResourcesApiServiceImpl();
UriTemplate uriTemplateOne = SampleTestObjectCreator.createUniqueUriTemplate();
UriTemplate uriTemplateTwo = SampleTestObjectCreator.createUniqueUriTemplate();
UriTemplate uriTemplateThree = SampleTestObjectCreator.createUniqueUriTemplate();
List<UriTemplate> uriTemplateList = new ArrayList<>();
uriTemplateList.add(uriTemplateOne);
uriTemplateList.add(uriTemplateTwo);
uriTemplateList.add(uriTemplateThree);
Mockito.when(apiMgtAdminService.getAllResourcesForApi(API_CONTEXT, API_VERSION)).thenReturn(uriTemplateList);
Response response = resourcesApiService.resourcesGet(API_CONTEXT, API_VERSION, null, getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
Assert.assertEquals(((ResourcesListDTO) response.getEntity()).getList().size(), 3);
}
Aggregations