use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIMgtDAOTest method testAddAndGetApplicationPolicy.
@Test
public void testAddAndGetApplicationPolicy() throws Exception {
ApplicationPolicy applicationPolicy = (ApplicationPolicy) getApplicationPolicy("testAddAndGetSubscriptionPolicy");
String customAttributes = "{api:abc}";
applicationPolicy.setTenantId(-1234);
applicationPolicy.setCustomAttributes(customAttributes.getBytes());
apiMgtDAO.addApplicationPolicy(applicationPolicy);
ApplicationPolicy retrievedPolicy = apiMgtDAO.getApplicationPolicy(applicationPolicy.getPolicyName(), -1234);
ApplicationPolicy retrievedPolicyFromUUID = apiMgtDAO.getApplicationPolicyByUUID(retrievedPolicy.getUUID());
assertEquals(retrievedPolicy.getDescription(), retrievedPolicyFromUUID.getDescription());
assertEquals(retrievedPolicy.getDisplayName(), retrievedPolicyFromUUID.getDisplayName());
retrievedPolicyFromUUID.setCustomAttributes(customAttributes.getBytes());
apiMgtDAO.updateApplicationPolicy(retrievedPolicyFromUUID);
ApplicationPolicy[] applicationPolicies = apiMgtDAO.getApplicationPolicies(-1234);
assertTrue(applicationPolicies.length > 0);
apiMgtDAO.setPolicyDeploymentStatus(PolicyConstants.POLICY_LEVEL_APP, applicationPolicy.getPolicyName(), -1234, true);
assertTrue(apiMgtDAO.getPolicyNames(PolicyConstants.POLICY_LEVEL_APP, "admin").length > 0);
assertTrue(apiMgtDAO.isPolicyDeployed(PolicyConstants.POLICY_LEVEL_APP, -1234, applicationPolicy.getPolicyName()));
assertTrue(apiMgtDAO.isPolicyExist(PolicyConstants.POLICY_LEVEL_APP, -1234, applicationPolicy.getPolicyName()));
apiMgtDAO.removeThrottlePolicy(PolicyConstants.POLICY_LEVEL_APP, "testAddAndGetSubscriptionPolicy", -1234);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIMgtDAOTest method getApplicationPolicy.
private Policy getApplicationPolicy(String policyName) {
ApplicationPolicy policy = new ApplicationPolicy(policyName);
policy.setDescription(policyName);
policy.setDescription("Application policy Description");
policy.setTenantId(4);
BandwidthLimit defaultLimit = new BandwidthLimit();
defaultLimit.setTimeUnit("min");
defaultLimit.setUnitTime(5);
defaultLimit.setDataAmount(600);
defaultLimit.setDataUnit("KB");
QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
defaultQuotaPolicy.setLimit(defaultLimit);
defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
policy.setDefaultQuotaPolicy(defaultQuotaPolicy);
return policy;
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class APIMgtDAOTest method testUpdateApplicationPolicy.
@Test
public void testUpdateApplicationPolicy() throws APIManagementException {
String policyName = "TestUpdateAppPolicy";
ApplicationPolicy policy = (ApplicationPolicy) getApplicationPolicy(policyName);
apiMgtDAO.addApplicationPolicy(policy);
policy = apiMgtDAO.getApplicationPolicy(policyName, 4);
policy.setDescription("Updated application description");
apiMgtDAO.updateApplicationPolicy(policy);
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class PolicyUtilTest method testUpdatePolicy_APPType.
@Test
public void testUpdatePolicy_APPType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenReturn("EXECUTION_PLAN");
ApplicationPolicy policy = TestUtil.getPolicyAppLevel();
ApplicationPolicyEvent policyEvent = new ApplicationPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_UPDATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType());
PolicyUtil.deployPolicy(policy, policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).editActiveExecutionPlan(Mockito.anyString(), Mockito.anyString());
}
use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy in project carbon-apimgt by wso2.
the class PolicyUtilTest method testDeployAllPolicies.
@Test
public void testDeployAllPolicies() throws ExecutionPlanConfigurationException, ThrottlePolicyDeployerException, ExecutionPlanDependencyValidationException {
ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
Map<String, ExecutionPlanConfiguration> executionPlanConfigurationMap = new HashMap<>();
ExecutionPlanConfiguration executionPlanConfiguration = Mockito.mock(ExecutionPlanConfiguration.class);
executionPlanConfigurationMap.put("sample_policy", executionPlanConfiguration);
Mockito.when(eventProcessorService.getAllActiveExecutionConfigurations()).thenReturn(executionPlanConfigurationMap);
SubscriptionPolicyList subscriptionPolicyList = new SubscriptionPolicyList();
SubscriptionPolicy subscriptionPolicy = TestUtil.getPolicySubLevel();
List<SubscriptionPolicy> subscriptionPolicies = new ArrayList<>();
subscriptionPolicies.add(subscriptionPolicy);
subscriptionPolicyList.setList(subscriptionPolicies);
Mockito.when(policyRetriever.getAllSubscriptionPolicies()).thenReturn(subscriptionPolicyList);
ApplicationPolicyList applicationPolicyList = new ApplicationPolicyList();
ApplicationPolicy applicationPolicy = TestUtil.getPolicyAppLevel();
List<ApplicationPolicy> applicationPolicies = new ArrayList<>();
applicationPolicies.add(applicationPolicy);
applicationPolicyList.setList(applicationPolicies);
Mockito.when(policyRetriever.getAllApplicationPolicies()).thenReturn(applicationPolicyList);
ApiPolicyList apiPolicyList = new ApiPolicyList();
ApiPolicy apiPolicy = TestUtil.getPolicyAPILevel();
List<ApiPolicy> apiPolicies = new ArrayList<>();
apiPolicies.add(apiPolicy);
apiPolicyList.setList(apiPolicies);
Mockito.when(policyRetriever.getAllApiPolicies()).thenReturn(apiPolicyList);
GlobalPolicyList globalPolicyList = new GlobalPolicyList();
GlobalPolicy globalPolicy = TestUtil.getPolicyGlobalLevel();
List<GlobalPolicy> globalPolicies = new ArrayList<>();
globalPolicies.add(globalPolicy);
globalPolicyList.setList(globalPolicies);
Mockito.when(policyRetriever.getAllGlobalPolicies()).thenReturn(globalPolicyList);
PolicyUtil.deployAllPolicies();
Mockito.verify(eventProcessorService, Mockito.times(5)).deployExecutionPlan(Mockito.anyString());
}
Aggregations