Search in sources :

Example 36 with GlobalPolicy

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.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());
}
Also used : ApplicationPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicyList) HashMap(java.util.HashMap) GlobalPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy) ArrayList(java.util.ArrayList) ApiPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicy) ExecutionPlanConfigurationException(org.wso2.carbon.event.processor.core.exception.ExecutionPlanConfigurationException) SubscriptionPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicy) ExecutionPlanConfiguration(org.wso2.carbon.event.processor.core.ExecutionPlanConfiguration) ApplicationPolicy(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApplicationPolicy) SubscriptionPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.SubscriptionPolicyList) ApiPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.ApiPolicyList) GlobalPolicyList(org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicyList) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 37 with GlobalPolicy

use of org.wso2.carbon.apimgt.throttle.policy.deployer.dto.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());
}
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 38 with GlobalPolicy

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

Aggregations

GlobalPolicy (org.wso2.carbon.apimgt.api.model.policy.GlobalPolicy)19 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)10 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)9 GlobalPolicy (org.wso2.carbon.apimgt.throttle.policy.deployer.dto.GlobalPolicy)9 InputStream (java.io.InputStream)7 GlobalPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.GlobalPolicyEvent)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 SQLException (java.sql.SQLException)6 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)6 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)6 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)6 ResultSet (java.sql.ResultSet)5 APIPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.APIPolicyEvent)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)4 ApplicationPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.ApplicationPolicyEvent)4 SubscriptionPolicyEvent (org.wso2.carbon.apimgt.impl.notifier.events.SubscriptionPolicyEvent)4