Search in sources :

Example 16 with ApiMgtDAOMockCreator

use of org.wso2.carbon.apimgt.impl.ApiMgtDAOMockCreator in project carbon-apimgt by wso2.

the class APIUtilTierTest method testAddDefaultTenantAdvancedThrottlePoliciesAppLevel.

@Test
public void testAddDefaultTenantAdvancedThrottlePoliciesAppLevel() throws Exception {
    int tenantId = 1;
    String tenantDomain = "test.com";
    ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(tenantId);
    ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();
    String[] appPolicies = new String[] { APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_UNLIMITED };
    for (String policy : appPolicies) {
        Mockito.when(apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_APP), eq(tenantId), eq(policy))).thenReturn(false);
        Mockito.when(apiMgtDAO.isPolicyDeployed(eq(PolicyConstants.POLICY_LEVEL_APP), eq(tenantId), eq(policy))).thenReturn(false);
    }
    mockPolicyRetrieval(apiMgtDAO);
    APIUtil.addDefaultTenantAdvancedThrottlePolicies(tenantDomain, tenantId);
    Mockito.verify(apiMgtDAO, Mockito.times(appPolicies.length)).addApplicationPolicy(Mockito.any(ApplicationPolicy.class));
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) ApiMgtDAOMockCreator(org.wso2.carbon.apimgt.impl.ApiMgtDAOMockCreator) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 17 with ApiMgtDAOMockCreator

use of org.wso2.carbon.apimgt.impl.ApiMgtDAOMockCreator in project carbon-apimgt by wso2.

the class APIUtilTierTest method testAddDefaultSuperTenantAdvancedThrottlePoliciesAppLevelAlreadyAdded.

@Test
public void testAddDefaultSuperTenantAdvancedThrottlePoliciesAppLevelAlreadyAdded() throws Exception {
    ApiMgtDAOMockCreator daoMockHolder = new ApiMgtDAOMockCreator(1);
    ApiMgtDAO apiMgtDAO = daoMockHolder.getMock();
    String[] appPolicies = new String[] { APIConstants.DEFAULT_APP_POLICY_FIFTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TWENTY_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_TEN_REQ_PER_MIN, APIConstants.DEFAULT_APP_POLICY_UNLIMITED };
    // If policy added already
    for (String policy : appPolicies) {
        Mockito.when(apiMgtDAO.isPolicyExist(eq(PolicyConstants.POLICY_LEVEL_APP), eq(MultitenantConstants.SUPER_TENANT_ID), eq(policy))).thenReturn(true);
    }
    try {
        APIUtil.addDefaultSuperTenantAdvancedThrottlePolicies();
        Mockito.verify(apiMgtDAO, Mockito.never()).addApplicationPolicy(Mockito.any(ApplicationPolicy.class));
    } catch (APIManagementException e) {
        Assert.assertTrue("Exception thrown", false);
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) ApiMgtDAOMockCreator(org.wso2.carbon.apimgt.impl.ApiMgtDAOMockCreator) ApiMgtDAO(org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO) Matchers.anyString(org.mockito.Matchers.anyString) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ApiMgtDAOMockCreator (org.wso2.carbon.apimgt.impl.ApiMgtDAOMockCreator)17 Test (org.junit.Test)16 Matchers.anyString (org.mockito.Matchers.anyString)16 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)16 ApiMgtDAO (org.wso2.carbon.apimgt.impl.dao.ApiMgtDAO)16 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)6 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)6 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)5 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)5 Tier (org.wso2.carbon.apimgt.api.model.Tier)4 APIManagerConfiguration (org.wso2.carbon.apimgt.impl.APIManagerConfiguration)4 APIManagerConfigurationService (org.wso2.carbon.apimgt.impl.APIManagerConfigurationService)4 APIMConfigService (org.wso2.carbon.apimgt.impl.config.APIMConfigService)4 ThrottleProperties (org.wso2.carbon.apimgt.impl.dto.ThrottleProperties)4 ServiceReferenceHolder (org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder)4 RealmService (org.wso2.carbon.user.core.service.RealmService)4 TenantManager (org.wso2.carbon.user.core.tenant.TenantManager)4 Before (org.junit.Before)1