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