use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetAllPolicies.
@Test(description = "Test getting all policies")
public void testGetAllPolicies() throws APIManagementException {
PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
Set<PolicyValidationData> policyValidationDataSetExpected = new HashSet<>();
PolicyValidationData policyValidationData = new PolicyValidationData(POLICY_ID, POLICY_NAME, true);
policyValidationDataSetExpected.add(policyValidationData);
Mockito.when(policyDAO.getAllPolicies()).thenReturn(policyValidationDataSetExpected);
Set<PolicyValidationData> policyValidationDataSetReturned = adminService.getAllPolicies();
Assert.assertEquals(policyValidationDataSetReturned, policyValidationDataSetExpected);
// Error path
Mockito.when(policyDAO.getAllPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getAllPolicies();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error occurred while retrieving policies");
}
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class MappingUtil method convertToPolicyDtoList.
/**
* Convert policy validation data list to policy dto list
*
* @param allPolicies all policies
* @return PolicyDTO list
*/
public static List<PolicyDTO> convertToPolicyDtoList(Set<PolicyValidationData> allPolicies) {
List<PolicyDTO> policyDTOList = new ArrayList<>();
allPolicies.forEach(v -> {
PolicyDTO policyDTO = new PolicyDTO();
policyDTO.setId(v.getId());
policyDTO.setName(v.getName());
policyDTO.setStopOnQuotaReach(v.isStopOnQuotaReach());
policyDTOList.add(policyDTO);
});
return policyDTOList;
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method updatePolicy.
@Override
public void updatePolicy(PolicyValidationData policyValidationData) throws GatewayException {
if (policyValidationData != null) {
PolicyEvent policyEvent = new PolicyEvent(APIMgtConstants.GatewayEventTypes.POLICY_UPDATE);
policyEvent.setId(policyValidationData.getId());
policyEvent.setName(policyValidationData.getName());
policyEvent.setStopOnQuotaReach(policyValidationData.isStopOnQuotaReach());
publishToThrottleTopic(policyEvent);
if (log.isDebugEnabled()) {
log.debug("Policy : " + policyValidationData.getName() + " update event has been successfully " + "published " + "to broker");
}
}
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData 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);
}
use of org.wso2.carbon.apimgt.core.models.PolicyValidationData in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImpl method updateApiPolicy.
@Override
public void updateApiPolicy(APIPolicy policy) throws APIManagementException {
try {
policyDAO.updateApiPolicy(policy);
PolicyValidationData policyValidationData = new PolicyValidationData(policy.getUuid(), policy.getPolicyName(), false);
apiGateway.updatePolicy(policyValidationData);
} catch (APIMgtDAOException e) {
String errorMessage = "Couldn't update API policy for uuid: " + policy.getUuid();
log.error(errorMessage, e);
throw new APIManagementException(errorMessage, e, e.getErrorHandler());
}
}
Aggregations