Search in sources :

Example 66 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testDeletePolicy.

@Test(description = "Test delete policy")
public void testDeletePolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName())).thenReturn(apiPolicy);
    adminService.deletePolicy(apiPolicy.getPolicyName(), APIMgtAdminService.PolicyLevel.api);
    Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
    Mockito.verify(policyDAO, Mockito.times(1)).deletePolicy(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
    // Error path
    Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).deletePolicy(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName());
    try {
        adminService.deletePolicy(apiPolicy.getPolicyName(), APIMgtAdminService.PolicyLevel.api);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't delete policy with name: " + apiPolicy.getPolicyName() + ", level: " + APIMgtAdminService.PolicyLevel.api);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 67 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testAddSubscriptionPolicy.

@Test(description = "Test add subscription policy")
public void testAddSubscriptionPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    adminService.addSubscriptionPolicy(policy);
    Mockito.verify(policyDAO, Mockito.times(1)).addSubscriptionPolicy(policy);
    // Error path
    Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).addSubscriptionPolicy(policy);
    try {
        adminService.addSubscriptionPolicy(policy);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't add Subscription policy for uuid: " + policy.getUuid());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 68 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testGetSubscriptionPolicies.

@Test(description = "Test getting all Subscription Policies")
public void testGetSubscriptionPolicies() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    adminService.getSubscriptionPolicies();
    Mockito.verify(policyDAO, Mockito.times(1)).getSubscriptionPolicies();
    // Error path
    Mockito.when(policyDAO.getSubscriptionPolicies()).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getSubscriptionPolicies();
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't retrieve Subscription policies");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 69 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testGetApplicationPolicy.

@Test(description = "Test getting Application policy")
public void testGetApplicationPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    Mockito.when(policyDAO.getApplicationPolicy(applicationPolicy.getPolicyName())).thenReturn(applicationPolicy);
    adminService.getApplicationPolicy(applicationPolicy.getPolicyName());
    Mockito.verify(policyDAO, Mockito.times(1)).getApplicationPolicy(applicationPolicy.getPolicyName());
    // Error path
    Mockito.when(policyDAO.getApplicationPolicy(applicationPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getApplicationPolicy(applicationPolicy.getPolicyName());
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't retrieve Application policy with name: " + applicationPolicy.getPolicyName());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 70 with PolicyDAO

use of org.wso2.carbon.apimgt.core.dao.PolicyDAO in project carbon-apimgt by wso2.

the class APIMgtAdminServiceImplTestCase method testGetApiPolicy.

@Test(description = "Test getting API policy")
public void testGetApiPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    Mockito.when(policyDAO.getApiPolicy(apiPolicy.getPolicyName())).thenReturn(apiPolicy);
    adminService.getApiPolicy(apiPolicy.getPolicyName());
    Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicy(apiPolicy.getPolicyName());
    // Error path
    Mockito.when(policyDAO.getApiPolicy(apiPolicy.getPolicyName())).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getApiPolicy(apiPolicy.getPolicyName());
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policy with name: " + apiPolicy.getPolicyName());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Aggregations

PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)106 Test (org.testng.annotations.Test)102 APIGateway (org.wso2.carbon.apimgt.core.api.APIGateway)50 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)50 APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)45 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)36 ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)33 ApiDAO (org.wso2.carbon.apimgt.core.dao.ApiDAO)30 API (org.wso2.carbon.apimgt.core.models.API)28 APIBuilder (org.wso2.carbon.apimgt.core.models.API.APIBuilder)27 APILifecycleManager (org.wso2.carbon.apimgt.core.api.APILifecycleManager)24 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)24 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)23 BeforeTest (org.testng.annotations.BeforeTest)20 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)20 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)17 LabelDAO (org.wso2.carbon.apimgt.core.dao.LabelDAO)16 Application (org.wso2.carbon.apimgt.core.models.Application)15 WorkflowDAO (org.wso2.carbon.apimgt.core.dao.WorkflowDAO)14 Endpoint (org.wso2.carbon.apimgt.core.models.Endpoint)13