use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO 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.dao.ThreatProtectionDAO in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImplIT method testGetPolicies.
@Test
public void testGetPolicies() throws Exception {
List<ThreatProtectionPolicy> policyList = new ArrayList<>();
policyList.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
policyList.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
policyList.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
ThreatProtectionDAO dao = DAOFactory.getThreatProtectionDAO();
for (ThreatProtectionPolicy policy : policyList) {
dao.addPolicy(policy);
}
int matchedCount = 0;
List<ThreatProtectionPolicy> fromDb = dao.getPolicies();
for (ThreatProtectionPolicy policyFromDb : fromDb) {
for (ThreatProtectionPolicy originalPolicy : policyList) {
if (originalPolicy.getUuid().equals(policyFromDb.getUuid())) {
matchedCount += 1;
}
}
}
Assert.assertEquals(matchedCount, policyList.size());
}
use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImplIT method testGetThreatProtectionPolicyIdsForApi.
@Test
public void testGetThreatProtectionPolicyIdsForApi() throws Exception {
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
ThreatProtectionDAO threatProtectionDAO = DAOFactory.getThreatProtectionDAO();
threatProtectionDAO.addPolicy(policy);
API.APIBuilder builder = SampleTestObjectCreator.createDefaultAPI();
Set<String> policyIds = new HashSet<>();
policyIds.add(policy.getUuid());
builder = builder.threatProtectionPolicies(policyIds);
ApiDAO dao = DAOFactory.getApiDAO();
dao.addAPI(builder.build());
Set<String> fromDb = threatProtectionDAO.getThreatProtectionPolicyIdsForApi(builder.getId());
Assert.assertEquals(fromDb.toArray()[0].toString(), policy.getUuid());
}
use of org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO in project carbon-apimgt by wso2.
the class ThreatProtectionDAOImplIT method testUpdatePolicy.
@Test
public void testUpdatePolicy() throws Exception {
ThreatProtectionPolicy policy = SampleTestObjectCreator.createUniqueThreatProtectionPolicy();
ThreatProtectionDAO dao = DAOFactory.getThreatProtectionDAO();
dao.addPolicy(policy);
// make some changes, except UUID
policy.setName("Changed name");
policy.setPolicy("{}");
policy.setType("XML");
dao.updatePolicy(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());
}
Aggregations