Search in sources :

Example 61 with PolicyDAO

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

the class APIMgtAdminServiceImplTestCase method testGetPolicy.

@Test(description = "Get policy by level and name")
public void testGetPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    Policy policy = Mockito.mock(Policy.class);
    Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenReturn(policy);
    adminService.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
    Mockito.verify(policyDAO, Mockito.times(1)).getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
    // Error path
    Mockito.when(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME)).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, POLICY_NAME);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't retrieve Throttle Policy with level: " + APIMgtAdminService.PolicyLevel.application.name() + ", name: " + POLICY_NAME);
    }
}
Also used : ThreatProtectionPolicy(org.wso2.carbon.apimgt.core.models.policy.ThreatProtectionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 62 with PolicyDAO

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

the class APIMgtAdminServiceImplTestCase method testUpdateSubscriptionPolicy.

@Test(description = "Test update subscription policy")
public void testUpdateSubscriptionPolicy() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    adminService.updateSubscriptionPolicy(subscriptionPolicy);
    Mockito.verify(policyDAO, Mockito.times(1)).updateSubscriptionPolicy(subscriptionPolicy);
    // Error path
    Mockito.doThrow(APIMgtDAOException.class).when(policyDAO).updateSubscriptionPolicy(subscriptionPolicy);
    try {
        adminService.updateSubscriptionPolicy(subscriptionPolicy);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't update Subscription policy for uuid: " + subscriptionPolicy.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 63 with PolicyDAO

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

the class APIMgtAdminServiceImplTestCase method testAddBlockCondition.

@Test(description = "Test adding block condition")
public void testAddBlockCondition() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIGateway apiGateway = Mockito.mock(APIGateway.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO, apiGateway);
    BlockConditions blockConditions = SampleTestObjectCreator.createDefaultBlockCondition(BLOCK_CONDITION_TYPE);
    String uuid = adminService.addBlockCondition(blockConditions);
    Assert.assertNotNull(uuid);
    // Error path
    Mockito.when(policyDAO.addBlockConditions(blockConditions)).thenThrow(APIMgtDAOException.class);
    try {
        adminService.addBlockCondition(blockConditions);
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't add block condition with condition type: " + blockConditions.getConditionType() + ", condition value: " + blockConditions.getConditionValue());
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) BlockConditions(org.wso2.carbon.apimgt.core.models.BlockConditions) APIGateway(org.wso2.carbon.apimgt.core.api.APIGateway) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 64 with PolicyDAO

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

the class APIMgtAdminServiceImplTestCase method testGetApiPolicyByUuid.

@Test(description = "Test getting API policy by UUID")
public void testGetApiPolicyByUuid() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    Mockito.when(policyDAO.getApiPolicyByUuid(apiPolicy.getUuid())).thenReturn(apiPolicy);
    adminService.getApiPolicyByUuid(apiPolicy.getUuid());
    Mockito.verify(policyDAO, Mockito.times(1)).getApiPolicyByUuid(apiPolicy.getUuid());
    // Error path
    Mockito.when(policyDAO.getApiPolicyByUuid(apiPolicy.getUuid())).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getApiPolicyByUuid(apiPolicy.getUuid());
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't retrieve API policy with id: " + apiPolicy.getUuid());
    }
}
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)

Example 65 with PolicyDAO

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

the class APIMgtAdminServiceImplTestCase method testGetApplicationPolicies.

@Test(description = "Test getting all Application Policies")
public void testGetApplicationPolicies() throws APIManagementException {
    PolicyDAO policyDAO = Mockito.mock(PolicyDAO.class);
    APIMgtAdminServiceImpl adminService = getAPIMgtAdminServiceImpl(policyDAO);
    adminService.getApplicationPolicies();
    Mockito.verify(policyDAO, Mockito.times(1)).getApplicationPolicies();
    // Error path
    Mockito.when(policyDAO.getApplicationPolicies()).thenThrow(APIMgtDAOException.class);
    try {
        adminService.getApplicationPolicies();
    } catch (APIManagementException e) {
        Assert.assertEquals(e.getMessage(), "Couldn't retrieve Application policies");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) 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