Search in sources :

Example 1 with ThreatProtectionDAO

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);
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) ThreatProtectionDAO(org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO) Test(org.testng.annotations.Test)

Example 2 with ThreatProtectionDAO

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());
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) ThreatProtectionDAO(org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO) Test(org.testng.annotations.Test)

Example 3 with ThreatProtectionDAO

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");
    }
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ArrayList(java.util.ArrayList) ThreatProtectionDAO(org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO) Test(org.testng.annotations.Test)

Example 4 with ThreatProtectionDAO

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");
    }
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ThreatProtectionDAO(org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO) Test(org.testng.annotations.Test)

Example 5 with ThreatProtectionDAO

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");
    }
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ThreatProtectionDAO(org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)9 ThreatProtectionDAO (org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO)9 ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)9 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)4 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)1 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)1 API (org.wso2.carbon.apimgt.core.models.API)1