Search in sources :

Example 6 with PolicyEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.PolicyEvent in project carbon-apimgt by wso2.

the class PolicyUtilTest method testUpdatePolicy_GlobalType.

@Test
public void testUpdatePolicy_GlobalType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
    Mockito.when(eventProcessorService.getActiveExecutionPlan(Mockito.anyString())).thenReturn("EXECUTION_PLAN");
    GlobalPolicy policy = TestUtil.getPolicyGlobalLevel();
    GlobalPolicyEvent policyEvent = new GlobalPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_UPDATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName());
    PolicyUtil.deployPolicy(policy, policyEvent);
    Mockito.verify(eventProcessorService, Mockito.times(1)).editActiveExecutionPlan(Mockito.anyString(), Mockito.anyString());
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy) GlobalPolicyEvent(org.wso2.carbon.apimgt.impl.notifier.events.GlobalPolicyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 7 with PolicyEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.PolicyEvent in project carbon-apimgt by wso2.

the class PolicyUtilTest method testDeletePolicy_SubType.

@Test
public void testDeletePolicy_SubType() throws ExecutionPlanConfigurationException {
    SubscriptionPolicy policy = TestUtil.getPolicySubLevel();
    SubscriptionPolicyEvent policyEvent = new SubscriptionPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_DELETE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType(), policy.getRateLimitCount(), policy.getRateLimitTimeUnit(), policy.isStopOnQuotaReach(), policy.getGraphQLMaxDepth(), policy.getGraphQLMaxComplexity(), policy.getSubscriberCount());
    Mockito.when(eventProcessorService.getActiveExecutionPlan(policy.getTenantDomain() + "_" + PolicyConstants.POLICY_LEVEL_SUB + "_" + policy.getName())).thenReturn("EXECUTION_PLAN");
    PolicyUtil.undeployPolicy(policyEvent);
    Mockito.verify(eventProcessorService, Mockito.times(1)).undeployActiveExecutionPlan(Mockito.anyString());
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicy) SubscriptionPolicyEvent(org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionPolicyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with PolicyEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.PolicyEvent in project carbon-apimgt by wso2.

the class PolicyUtilTest method testUpdatePolicy_APIType.

@Test
public void testUpdatePolicy_APIType() throws ExecutionPlanConfigurationException, ExecutionPlanDependencyValidationException {
    ApiPolicy policy = TestUtil.getPolicyAPILevel();
    List<Integer> deletedConditionGroupIds = new ArrayList<>();
    deletedConditionGroupIds.add(5);
    deletedConditionGroupIds.add(6);
    APIPolicyEvent policyEvent = new APIPolicyEvent(UUID.randomUUID().toString(), System.currentTimeMillis(), APIConstants.EventType.POLICY_UPDATE.name(), -1234, policy.getTenantDomain(), policy.getId(), policy.getName(), policy.getDefaultLimit().getQuotaType(), null, deletedConditionGroupIds);
    ExecutionPlanConfigurationException executionPlanConfigurationException = Mockito.mock(ExecutionPlanConfigurationException.class);
    Mockito.when(eventProcessorService.getActiveExecutionPlan(policy.getTenantDomain() + "_" + PolicyConstants.POLICY_LEVEL_RESOURCE + "_" + policy.getName() + "_condition_1")).thenThrow(executionPlanConfigurationException);
    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");
    PolicyUtil.deployPolicy(policy, policyEvent);
    Mockito.verify(eventProcessorService, Mockito.times(2)).undeployActiveExecutionPlan(Mockito.anyString());
    Mockito.verify(eventProcessorService, Mockito.times(1)).editActiveExecutionPlan(Mockito.anyString(), Mockito.anyString());
    Mockito.verify(eventProcessorService, Mockito.times(1)).deployExecutionPlan(Mockito.anyString());
}
Also used : APIPolicyEvent(org.wso2.carbon.apimgt.impl.notifier.events.APIPolicyEvent) ApiPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy) ArrayList(java.util.ArrayList) ExecutionPlanConfigurationException(org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with PolicyEvent

use of org.wso2.carbon.apimgt.impl.notifier.events.PolicyEvent in project carbon-apimgt by wso2.

the class APIGatewayPublisherImpl method updatePolicy.

@Override
public void updatePolicy(PolicyValidationData policyValidationData) throws GatewayException {
    if (policyValidationData != null) {
        PolicyEvent policyEvent = new PolicyEvent(APIMgtConstants.GatewayEventTypes.POLICY_UPDATE);
        policyEvent.setId(policyValidationData.getId());
        policyEvent.setName(policyValidationData.getName());
        policyEvent.setStopOnQuotaReach(policyValidationData.isStopOnQuotaReach());
        publishToThrottleTopic(policyEvent);
        if (log.isDebugEnabled()) {
            log.debug("Policy : " + policyValidationData.getName() + " update event has been successfully " + "published " + "to broker");
        }
    }
}
Also used : PolicyEvent(org.wso2.carbon.apimgt.core.models.events.PolicyEvent)

Example 10 with PolicyEvent

use of org.wso2.carbon.apimgt.impl.notifier.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());
}
Also used : GlobalPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy) ExecutionPlanConfigurationException(org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException) GlobalPolicyEvent(org.wso2.carbon.apimgt.impl.notifier.events.GlobalPolicyEvent) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)12 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)12 APIPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.APIPolicyEvent)6 ExecutionPlanConfigurationException (org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException)6 ApplicationPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.ApplicationPolicyEvent)5 SubscriptionPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionPolicyEvent)5 ApiPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy)5 ApplicationPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy)5 GlobalPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy)5 SubscriptionPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicy)5 GlobalPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.GlobalPolicyEvent)4 ArrayList (java.util.ArrayList)3 PolicyEvent (org.wso2.carbon.apimgt.core.models.events.PolicyEvent)3 Gson (com.google.gson.Gson)2 PolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.PolicyEvent)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)1 EndpointCertificateDeployer (org.wso2.carbon.apimgt.gateway.EndpointCertificateDeployer)1