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