Search in sources :

Example 1 with ResourcesListDTO

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);
}
Also used : Response(javax.ws.rs.core.Response) ResourcesListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 2 with ResourcesListDTO

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);
}
Also used : Response(javax.ws.rs.core.Response) ResourcesListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with ResourcesListDTO

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();
    }
}
Also used : ArrayList(java.util.ArrayList) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) Map(java.util.Map) ResourcesListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO)

Example 4 with ResourcesListDTO

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;
}
Also used : UriTemplateDTO(org.wso2.carbon.apimgt.rest.api.core.dto.UriTemplateDTO) ArrayList(java.util.ArrayList)

Example 5 with ResourcesListDTO

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);
}
Also used : Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) UriTemplate(org.wso2.carbon.apimgt.core.models.UriTemplate) ResourcesListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

ResourcesListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ResourcesListDTO)4 ArrayList (java.util.ArrayList)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 UriTemplate (org.wso2.carbon.apimgt.core.models.UriTemplate)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)1 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)1 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)1 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)1 UriTemplateDTO (org.wso2.carbon.apimgt.rest.api.core.dto.UriTemplateDTO)1