use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testAddThreatProtectionPolicy.
@Test(description = "Test adding threat protection policy")
public void testAddThreatProtectionPolicy() throws APIManagementException {
ThreatProtectionDAO threatProtectionDAO = Mockito.mock(ThreatProtectionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(threatProtectionDAO);
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
Mockito.doThrow(APIMgtDAOException.class).when(threatProtectionDAO).updatePolicy(policy);
Mockito.doThrow(APIMgtDAOException.class).when(threatProtectionDAO).addPolicy(policy);
// Error path
try {
adminService.addThreatProtectionPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error adding threat protection policy");
}
try {
policy.setUuid("");
adminService.addThreatProtectionPolicy(policy);
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error adding threat protection policy");
}
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetThreatProtectionPolicy.
@Test(description = "Test getting a threat protection policy")
public void testGetThreatProtectionPolicy() throws APIManagementException {
ThreatProtectionDAO threatProtectionDAO = Mockito.mock(ThreatProtectionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(threatProtectionDAO);
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
Mockito.when(threatProtectionDAO.getPolicy(policy.getUuid())).thenReturn(policy);
ThreatProtectionPolicy policyReturned = adminService.getThreatProtectionPolicy(policy.getUuid());
Assert.assertEquals(policyReturned, policy);
// Error path
Mockito.when(threatProtectionDAO.getPolicy(policy.getUuid())).thenThrow(APIMgtDAOException.class);
try {
adminService.getThreatProtectionPolicy(policy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error while retrieving threat protection policy");
}
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class MappingUtil method toThreatProtectionPolicyDTO.
/**
* Converts ThreatProtectionPolicy core model ThreatProtectionPolicyDTO rest api core model
* @param policy apimgt core model of ThreatProtectionPolicy
* @return ThreatProtectionPolicyDTO rest api core model
*/
public static ThreatProtectionPolicyDTO toThreatProtectionPolicyDTO(ThreatProtectionPolicy policy) {
if (policy == null)
return null;
ThreatProtectionPolicyDTO dto = new ThreatProtectionPolicyDTO();
dto.setUuid(policy.getUuid());
dto.setName(policy.getName());
dto.setType(policy.getType());
dto.setPolicy(policy.getPolicy());
return dto;
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class ThreatProtectionPoliciesApiServiceImpl method threatProtectionPoliciesGet.
/**
* Get a list of all threat protection policies
*
* @param request
* @return List of threat protection policies
* @throws NotFoundException
*/
@Override
public Response threatProtectionPoliciesGet(Request request) throws NotFoundException {
try {
APIMgtAdminService apiMgtAdminService = APIManagerFactory.getInstance().getAPIMgtAdminService();
List<ThreatProtectionPolicy> policyList = apiMgtAdminService.getThreatProtectionPolicyList();
ThreatProtectionPolicyListDTO listDTO = new ThreatProtectionPolicyListDTO();
for (ThreatProtectionPolicy policy : policyList) {
listDTO.addListItem(MappingUtil.toThreatProtectionPolicyDTO(policy));
}
return Response.ok().entity(listDTO).build();
} catch (APIManagementException e) {
log.error(e.getMessage(), e);
}
return Response.status(500).entity("Internal Server Error.").build();
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class APIGatewayPublisherImpl method updateThreatProtectionPolicy.
/**
* {@inheritDoc}
*/
@Override
public void updateThreatProtectionPolicy(ThreatProtectionPolicy policy) throws GatewayException {
ThreatProtectionEvent event = new ThreatProtectionEvent(APIMgtConstants.GatewayEventTypes.THREAT_PROTECTION_POLICY_UPDATE);
event.setPolicy(policy);
publishToThreatProtectionTopic(event);
}
Aggregations