use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy in project carbon-apimgt by wso2.
the class ThreatProtectionApiServiceImplTestCase method threatProtectionPoliciesGetTestCase.
@Test
public void threatProtectionPoliciesGetTestCase() throws Exception {
APIMgtAdminServiceImpl apiMgtAdminService = Mockito.mock(APIMgtAdminServiceImpl.class);
PowerMockito.mockStatic(APIManagerFactory.class);
APIManagerFactory apiManagerFactory = Mockito.mock(APIManagerFactory.class);
PowerMockito.when(APIManagerFactory.getInstance()).thenReturn(apiManagerFactory);
PowerMockito.when(apiManagerFactory.getAPIMgtAdminService()).thenReturn(apiMgtAdminService);
List<ThreatProtectionPolicy> list = new ArrayList<>();
list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
list.add(SampleTestObjectCreator.createUniqueThreatProtectionPolicy());
PowerMockito.when(apiMgtAdminService.getThreatProtectionPolicyList()).thenReturn(list);
ThreatProtectionPoliciesApiServiceImpl threatProtectionApiService = new ThreatProtectionPoliciesApiServiceImpl();
Response response = threatProtectionApiService.threatProtectionPoliciesGet(getRequest());
Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode());
int apiCount = ((ThreatProtectionPolicyListDTO) response.getEntity()).getList().size();
Assert.assertEquals(apiCount, 3);
}
use of org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy 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.models.policy.ThreatProtectionPolicy 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.models.policy.ThreatProtectionPolicy 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.models.policy.ThreatProtectionPolicy 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");
}
}
Aggregations