use of org.wso2.carbon.apimgt.core.models.events.PolicyEvent in project carbon-apimgt by wso2.
the class PolicyUtilTest method testAddPolicy_APPType.
@Test
public void testAddPolicy_APPType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
ApplicationPolicy policy = TestUtil.getPolicyAppLevel();
ApplicationPolicyEvent policyEvent = new ApplicationPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_CREATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType());
PolicyUtil.deployPolicy(policy, policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).deployExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.apimgt.core.models.events.PolicyEvent in project carbon-apimgt by wso2.
the class PolicyUtilTest method testDeletePolicy_AppType.
@Test
public void testDeletePolicy_AppType() throws ExecutionPlanConfigurationException {
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());
Mockito.when(eventProcessorService.getActiveExecutionPlan(policy.getTenantDomain() + "_" + PolicyConstants.POLICY_LEVEL_APP + "_" + policy.getName())).thenReturn("EXECUTION_PLAN");
PolicyUtil.undeployPolicy(policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).undeployActiveExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.apimgt.core.models.events.PolicyEvent in project carbon-apimgt by wso2.
the class PolicyUtilTest method testAddPolicy_GlobalType.
@Test
public void testAddPolicy_GlobalType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenThrow(executionPlanConfigurationException);
GlobalPolicy policy = TestUtil.getPolicyGlobalLevel();
GlobalPolicyEvent policyEvent = new GlobalPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_CREATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName());
PolicyUtil.deployPolicy(policy, policyEvent);
Mockito.verify(eventProcessorService, Mockito.times(1)).deployExecutionPlan(Mockito.anyString());
}
use of org.wso2.carbon.apimgt.core.models.events.PolicyEvent 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.core.models.events.PolicyEvent 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());
}
Aggregations