use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImplIT method testPolicyExists.
@Test
public void testPolicyExists() throws Exception {
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
ThreatProtectionDAO dao = DAOFactory.getThreatProtectionDAO();
dao.addPolicy(policy);
Assert.assertEquals(dao.isPolicyExists(policy.getUuid()), true);
ThreatProtectionPolicy policy2 = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
Assert.assertEquals(dao.isPolicyExists(policy2.getUuid()), false);
}
use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImplIT method testAddPolicy.
@Test
public void testAddPolicy() throws Exception {
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
ThreatProtectionDAO dao = DAOFactory.getThreatProtectionDAO();
dao.addPolicy(policy);
ThreatProtectionPolicy fromDb = dao.getPolicy(policy.getUuid());
Assert.assertEquals(fromDb.getUuid(), policy.getUuid());
Assert.assertEquals(fromDb.getName(), policy.getName());
Assert.assertEquals(fromDb.getType(), policy.getType());
Assert.assertEquals(fromDb.getPolicy(), policy.getPolicy());
}
use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testGetThreatProtectionPolicyList.
@Test(description = "Test getting list of all threat protection policies")
public void testGetThreatProtectionPolicyList() throws APIManagementException {
ThreatProtectionDAO threatProtectionDAO = Mockito.mock(ThreatProtectionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(threatProtectionDAO);
List<ThreatProtectionPolicy> policyList = new ArrayList<>();
policyList.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
policyList.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
Mockito.when(threatProtectionDAO.getPolicies()).thenReturn(policyList);
List<ThreatProtectionPolicy> policyListReturned = adminService.getThreatProtectionPolicyList();
Assert.assertEquals(policyListReturned.size(), policyList.size());
// Error path
Mockito.when(threatProtectionDAO.getPolicies()).thenThrow(APIMgtDAOException.class);
try {
adminService.getThreatProtectionPolicyList();
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error while retrieving threat protection policy list");
}
}
use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO in project carbon-apimgt by wso2.
the class APIMgtAdminServiceImplTestCase method testDeleteThreatProtectionPolicy.
@Test(description = "Test delete threat protection policy")
public void testDeleteThreatProtectionPolicy() throws APIManagementException {
ThreatProtectionDAO threatProtectionDAO = Mockito.mock(ThreatProtectionDAO.class);
APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(threatProtectionDAO);
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
// Error path
Mockito.doThrow(APIMgtDAOException.class).when(threatProtectionDAO).deletePolicy(policy.getUuid());
try {
adminService.deleteThreatProtectionPolicy(policy.getUuid());
} catch (APIManagementException e) {
Assert.assertEquals(e.getMessage(), "Error deleting threat protection policy");
}
}
use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO 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");
}
}
Aggregations