Search in sources :

Example 6 with ThreatProtectionPolicy

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);
}
Also used : Response(javax.ws.rs.core.Response) ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) APIManagerFactory(org.wso2.carbon.apimgt.core.impl.APIManagerFactory) APIMgtAdminServiceImpl(org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl) ArrayList(java.util.ArrayList) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 7 with ThreatProtectionPolicy

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);
}
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 8 with ThreatProtectionPolicy

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());
}
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 9 with ThreatProtectionPolicy

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");
    }
}
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 10 with ThreatProtectionPolicy

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");
    }
}
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

ThreatProtectionPolicy (org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy)27 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)12 Test (org.testng.annotations.Test)10 ThreatProtectionDAO (org.wso2.carbon.apimgt.core.dao.ThreatProtectionDAO)9 ArrayList (java.util.ArrayList)7 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)6 Response (javax.ws.rs.core.Response)5 Test (org.junit.Test)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 PreparedStatement (java.sql.PreparedStatement)4 SQLException (java.sql.SQLException)4 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)3 APIManagerFactory (org.wso2.carbon.apimgt.core.impl.APIManagerFactory)3 APIMgtAdminServiceImpl (org.wso2.carbon.apimgt.core.impl.APIMgtAdminServiceImpl)3 ThreatProtectionEvent (org.wso2.carbon.apimgt.core.models.events.ThreatProtectionEvent)3 ResultSet (java.sql.ResultSet)2 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.admin.dto.ThreatProtectionPolicyDTO)2 ThreatProtectionPolicyDTO (org.wso2.carbon.apimgt.rest.api.core.dto.ThreatProtectionPolicyDTO)2