Search in sources :

Example 1 with CustomThrottlePolicyTemplateBuilder

use of org.wso2.carbon.apimgt.core.template.CustomThrottlePolicyTemplateBuilder in project carbon-apimgt by wso2.

the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForCustomPolicy.

@Test
public void testSiddhiQueryForCustomPolicy() throws APITemplateException {
    CustomPolicy policy = SampleTestObjectCreator.createDefaultCustomPolicy();
    CustomThrottlePolicyTemplateBuilder templateBuilder = new CustomThrottlePolicyTemplateBuilder(policy);
    String siddhiQuery = templateBuilder.getThrottlePolicyTemplateForCustomPolicy();
    String sampleQuery = SampleTestObjectCreator.createDefaultCustomPolicySiddhiApp();
    Assert.assertEquals(siddhiQuery, sampleQuery);
}
Also used : CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) Test(org.testng.annotations.Test)

Example 2 with CustomThrottlePolicyTemplateBuilder

use of org.wso2.carbon.apimgt.core.template.CustomThrottlePolicyTemplateBuilder in project carbon-apimgt by wso2.

the class PolicyExportManager method getCustomPolicySiddhiApps.

/**
 * Get execution plan/ siddhi apps for custom policies.
 *
 * @param customPolicies custom policy object list
 * @return Map<String, String> containing execution plan name and execution plans.
 * @throws APITemplateException If template generating fails
 */
private Map<String, String> getCustomPolicySiddhiApps(List<CustomPolicy> customPolicies) throws APITemplateException {
    if (log.isDebugEnabled()) {
        log.debug("Get execution plans for custom policies.");
    }
    Map<String, String> siddhiApps = new HashMap<>();
    String name;
    String executionPlan;
    CustomThrottlePolicyTemplateBuilder templateBuilder;
    for (CustomPolicy policy : customPolicies) {
        templateBuilder = new CustomThrottlePolicyTemplateBuilder(policy);
        name = CUSTOM + policy.getPolicyName();
        executionPlan = templateBuilder.getThrottlePolicyTemplateForCustomPolicy();
        siddhiApps.put(name, executionPlan);
    }
    return siddhiApps;
}
Also used : CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) HashMap(java.util.HashMap) CustomThrottlePolicyTemplateBuilder(org.wso2.carbon.apimgt.core.template.CustomThrottlePolicyTemplateBuilder)

Aggregations

CustomPolicy (org.wso2.carbon.apimgt.core.models.policy.CustomPolicy)2 HashMap (java.util.HashMap)1 Test (org.testng.annotations.Test)1 CustomThrottlePolicyTemplateBuilder (org.wso2.carbon.apimgt.core.template.CustomThrottlePolicyTemplateBuilder)1