Search in sources :

Example 1 with PolicyListDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyListDTO in project carbon-apimgt by wso2.

the class PoliciesApiServiceImpl method policiesGet.

@Override
public Response policiesGet(String accept, Request request) throws NotFoundException {
    PolicyListDTO policyListDTO = new PolicyListDTO();
    try {
        APIMgtAdminService adminService = RestApiUtil.getAPIMgtAdminService();
        List<PolicyDTO> policyDTOList = MappingUtil.convertToPolicyDtoList(adminService.getAllPolicies());
        policyListDTO.setList(policyDTOList);
        policyListDTO.setCount(policyDTOList.size());
        return Response.ok().entity(policyListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving Policies";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIMgtAdminService(org.wso2.carbon.apimgt.core.api.APIMgtAdminService) PolicyDTO(org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.PolicyListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)

Example 2 with PolicyListDTO

use of org.wso2.carbon.apimgt.rest.api.core.dto.PolicyListDTO in project carbon-apimgt by wso2.

the class PoliciesApiServiceImplTestCase method policiesGetTest.

@Test
public void policiesGetTest() 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);
    PoliciesApiServiceImpl policiesApiService = new PoliciesApiServiceImpl();
    PolicyValidationData policyValidationDataOne = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
    PolicyValidationData policyValidationDataTwo = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
    PolicyValidationData policyValidationDataThree = new PolicyValidationData(UUID.randomUUID().toString(), "APPLICATION_POLICY", true);
    Set<PolicyValidationData> policyValidationDataHashSet = new LinkedHashSet<>();
    policyValidationDataHashSet.add(policyValidationDataOne);
    policyValidationDataHashSet.add(policyValidationDataTwo);
    policyValidationDataHashSet.add(policyValidationDataThree);
    Mockito.when(apiMgtAdminService.getAllPolicies()).thenReturn(policyValidationDataHashSet);
    Response response = policiesApiService.policiesGet(null, getRequest());
    Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
    Assert.assertEquals(((PolicyListDTO) response.getEntity()).getList().size(), 3);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Response(javax.ws.rs.core.Response) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) PolicyListDTO(org.wso2.carbon.apimgt.rest.api.core.dto.PolicyListDTO) PolicyValidationData(org.wso2.carbon.apimgt.core.models.PolicyValidationData) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

PolicyListDTO (org.wso2.carbon.apimgt.rest.api.core.dto.PolicyListDTO)2 LinkedHashSet (java.util.LinkedHashSet)1 Response (javax.ws.rs.core.Response)1 Test (org.junit.Test)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)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 PolicyValidationData (org.wso2.carbon.apimgt.core.models.PolicyValidationData)1 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)1 PolicyDTO (org.wso2.carbon.apimgt.rest.api.core.dto.PolicyDTO)1