use of org.wso2.carbon.event.processor.core.EventProcessorService 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.event.processor.core.EventProcessorService 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.event.processor.core.EventProcessorService in project carbon-apimgt by wso2.
the class PolicyUtilTest method testDeletePolicy_APIType.
@Test
public void testDeletePolicy_APIType() throws ExecutionPlanConfigurationException {
ApiPolicy policy = TestUtil.getPolicyAPILevel();
List<Integer> deletedConditionGroupIds = new ArrayList<>();
deletedConditionGroupIds.add(5);
deletedConditionGroupIds.add(6);
Mockito.when(eventProcessorService.getActiveExecutionPlan(policy.getTenantDomain() + "_" + PolicyConstants.POLICY_LEVEL_RESOURCE + "_" + policy.getName() + "_condition_5")).thenReturn("EXECUTION_PLAN");
Mockito.when(eventProcessorService.getActiveExecutionPlan(policy.getTenantDomain() + "_" + PolicyConstants.POLICY_LEVEL_RESOURCE + "_" + policy.getName() + "_condition_6")).thenReturn("EXECUTION_PLAN");
Mockito.when(eventProcessorService.getActiveExecutionPlan(policy.getTenantDomain() + "_" + PolicyConstants.POLICY_LEVEL_RESOURCE + "_" + policy.getName() + "_default")).thenReturn("EXECUTION_PLAN");
APIPolicyEvent policyEvent = new APIPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_DELETE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType(), null, deletedConditionGroupIds);
PolicyUtil.undeployPolicy(policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(3)).undeployActiveExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.event.processor.core.EventProcessorService in project carbon-apimgt by wso2.
the class PolicyUtilTest method testAddPolicy_SubType.
@Test
public void testAddPolicy_SubType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
SubscriptionPolicy policy = TestUtil.getPolicySubLevel();
SubscriptionPolicyEvent policyEvent = new SubscriptionPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_CREATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType(), policy.getRateLimitCount(), policy.getRateLimitTimeUnit(), policy.isStopOnQuotaReach(), policy.getGraphQLMaxDepth(), policy.getGraphQLMaxComplexity(), policy.getSubscriberCount());
PolicyUtil.deployPolicy(policy, policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).deployExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.event.processor.core.EventProcessorService in project carbon-apimgt by wso2.
the class PolicyUtilTest method setUp.
@Before
public void setUp() throws Exception {
System.setProperty("carbon.home", PolicyUtilTest.class.getResource("/").getFile());
PowerMockito.mockStatic(PrivilegedCarbonContext.class);
PrivilegedCarbonContext privilegedCarbonContext = Mockito.mock(PrivilegedCarbonContext.class);
Mockito.when(privilegedCarbonContext.getTenantDomain()).thenReturn("carbon.super");
PowerMockito.when(PrivilegedCarbonContext.getThreadLocalCarbonContext()).thenReturn(privilegedCarbonContext);
eventProcessorService = Mockito.mock(EventProcessorService.class);
PowerMockito.mockStatic(ServiceReferenceHolder.class);
ServiceReferenceHolder serviceReferenceHolder = Mockito.mock(ServiceReferenceHolder.class);
Mockito.when(serviceReferenceHolder.getEventProcessorService()).thenReturn(eventProcessorService);
APIManagerConfiguration apiManagerConfiguration = Mockito.mock(APIManagerConfiguration.class);
ThrottleProperties throttleProperties = Mockito.mock(ThrottleProperties.class);
String[] skipThrottlePolicies = { "skipPolicy1" };
Mockito.when(throttleProperties.getSkipRedeployingPolicies()).thenReturn(skipThrottlePolicies);
Mockito.when(apiManagerConfiguration.getThrottleProperties()).thenReturn(throttleProperties);
Mockito.when(apiManagerConfiguration.getFirstProperty(APIConstants.VELOCITY_LOGGER)).thenReturn(null);
Mockito.when(serviceReferenceHolder.getAPIMConfiguration()).thenReturn(apiManagerConfiguration);
PowerMockito.when(ServiceReferenceHolder.getInstance()).thenReturn(serviceReferenceHolder);
policyRetriever = Mockito.mock(PolicyRetriever.class);
PowerMockito.whenNew(PolicyRetriever.class).withNoArguments().thenReturn(policyRetriever);
}
Aggregations