Search in sources :

Example 96 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class APIMgtDAOTest method testAddAndGetApplicationPolicy.

@Test
public void testAddAndGetApplicationPolicy() throws Exception {
    ApplicationPolicy applicationPolicy = (ApplicationPolicy) getApplicationPolicy("testAddAndGetSubscriptionPolicy");
    String customAttributes = "{api:abc}";
    applicationPolicy.setTenantId(-1234);
    applicationPolicy.setCustomAttributes(customAttributes.getBytes());
    apiMgtDAO.addApplicationPolicy(applicationPolicy);
    ApplicationPolicy retrievedPolicy = apiMgtDAO.getApplicationPolicy(applicationPolicy.getPolicyName(), -1234);
    ApplicationPolicy retrievedPolicyFromUUID = apiMgtDAO.getApplicationPolicyByUUID(retrievedPolicy.getUUID());
    assertEquals(retrievedPolicy.getDescription(), retrievedPolicyFromUUID.getDescription());
    assertEquals(retrievedPolicy.getDisplayName(), retrievedPolicyFromUUID.getDisplayName());
    retrievedPolicyFromUUID.setCustomAttributes(customAttributes.getBytes());
    apiMgtDAO.updateApplicationPolicy(retrievedPolicyFromUUID);
    ApplicationPolicy[] applicationPolicies = apiMgtDAO.getApplicationPolicies(-1234);
    assertTrue(applicationPolicies.length > 0);
    apiMgtDAO.setPolicyDeploymentStatus(PolicyConstants.POLICY_LEVEL_APP, applicationPolicy.getPolicyName(), -1234, true);
    assertTrue(apiMgtDAO.getPolicyNames(PolicyConstants.POLICY_LEVEL_APP, "admin").length > 0);
    assertTrue(apiMgtDAO.isPolicyDeployed(PolicyConstants.POLICY_LEVEL_APP, -1234, applicationPolicy.getPolicyName()));
    assertTrue(apiMgtDAO.isPolicyExist(PolicyConstants.POLICY_LEVEL_APP, -1234, applicationPolicy.getPolicyName()));
    apiMgtDAO.removeThrottlePolicy(PolicyConstants.POLICY_LEVEL_APP, "testAddAndGetSubscriptionPolicy", -1234);
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 97 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class APIMgtDAOTest method getApplicationPolicy.

private Policy getApplicationPolicy(String policyName) {
    ApplicationPolicy policy = new ApplicationPolicy(policyName);
    policy.setDescription(policyName);
    policy.setDescription("Application policy Description");
    policy.setTenantId(4);
    BandwidthLimit defaultLimit = new BandwidthLimit();
    defaultLimit.setTimeUnit("min");
    defaultLimit.setUnitTime(5);
    defaultLimit.setDataAmount(600);
    defaultLimit.setDataUnit("KB");
    QuotaPolicy defaultQuotaPolicy = new QuotaPolicy();
    defaultQuotaPolicy.setLimit(defaultLimit);
    defaultQuotaPolicy.setType(PolicyConstants.BANDWIDTH_TYPE);
    policy.setDefaultQuotaPolicy(defaultQuotaPolicy);
    return policy;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) QuotaPolicy(org.wso2.carbon.apimgt.api.model.policy.QuotaPolicy) BandwidthLimit(org.wso2.carbon.apimgt.api.model.policy.BandwidthLimit)

Example 98 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy in project carbon-apimgt by wso2.

the class APIMgtDAOTest method testUpdateApplicationPolicy.

@Test
public void testUpdateApplicationPolicy() throws APIManagementException {
    String policyName = "TestUpdateAppPolicy";
    ApplicationPolicy policy = (ApplicationPolicy) getApplicationPolicy(policyName);
    apiMgtDAO.addApplicationPolicy(policy);
    policy = apiMgtDAO.getApplicationPolicy(policyName, 4);
    policy.setDescription("Updated application description");
    apiMgtDAO.updateApplicationPolicy(policy);
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 99 with ApplicationPolicy

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

Example 100 with ApplicationPolicy

use of org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy 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)

Aggregations

ApplicationPolicy (org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy)56 Test (org.testng.annotations.Test)30 ApplicationPolicy (org.wso2.carbon.apimgt.api.model.policy.ApplicationPolicy)29 PolicyDAO (org.wso2.carbon.apimgt.core.dao.PolicyDAO)24 ArrayList (java.util.ArrayList)23 Test (org.junit.Test)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)18 SubscriptionPolicy (org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy)18 Application (org.wso2.carbon.apimgt.core.models.Application)17 Connection (java.sql.Connection)16 PreparedStatement (java.sql.PreparedStatement)16 SQLException (java.sql.SQLException)16 ResultSet (java.sql.ResultSet)13 BeforeTest (org.testng.annotations.BeforeTest)13 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)13 ApplicationDAO (org.wso2.carbon.apimgt.core.dao.ApplicationDAO)13 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)13 Policy (org.wso2.carbon.apimgt.core.models.policy.Policy)13 APIPolicy (org.wso2.carbon.apimgt.api.model.policy.APIPolicy)12 SubscriptionPolicy (org.wso2.carbon.apimgt.api.model.policy.SubscriptionPolicy)12