use of org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy 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());
}
use of org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy in project carbon-apimgt by wso2.
the class PolicyUtilTest method testDeletePolicy_GlobalType.
@Test
public void testDeletePolicy_GlobalType() throws ExecutionPlanConfigurationException {
GlobalPolicy policy = TestUtil.getPolicyGlobalLevel();
GlobalPolicyEvent policyEvent = new GlobalPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_DELETE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName());
Mockito.when(eventProcessorService.getActiveExecutionPlan(PolicyConstants.POLICY_LEVEL_GLOBAL + "_" + policy.getName())).thenReturn("EXECUTION_PLAN");
PolicyUtil.undeployPolicy(policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).undeployActiveExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy in project carbon-apimgt by wso2.
the class ThrottlingPolicyTemplateBuilderTest method testGetThrottlePolicyForGlobalLevel.
@Test
public void testGetThrottlePolicyForGlobalLevel() throws Exception {
GlobalPolicy policy = TestUtil.getPolicyGlobalLevel();
String policyString = templateBuilder.getThrottlePolicyForGlobalLevel(policy);
Assert.assertNotNull(policyString);
}
Aggregations