Search in sources :

Example 1 with APIThrottlePolicyTemplateBuilder

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

the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForAPIPolicy.

@Test
public void testSiddhiQueryForAPIPolicy() throws APITemplateException {
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    APIThrottlePolicyTemplateBuilder templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
    Map<String, String> siddhiQueryMap = templateBuilder.getThrottlePolicyTemplateForPipelines();
    String actualQuery = siddhiQueryMap.get("resource_SampleAPIPolicy_condition_0");
    String expectedQuery = SampleTestObjectCreator.createDefaultSiddhiAppForAPIThrottlePolicy();
    Assert.assertEquals(actualQuery, expectedQuery);
}
Also used : APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) Test(org.testng.annotations.Test)

Example 2 with APIThrottlePolicyTemplateBuilder

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

the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForAPILevelDefaultConditions.

@Test
public void testSiddhiQueryForAPILevelDefaultConditions() throws APITemplateException {
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    APIThrottlePolicyTemplateBuilder templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
    String actualQuery = templateBuilder.getThrottlePolicyTemplateForAPILevelDefaultCondition();
    String expectedQuery = SampleTestObjectCreator.createDefaultSiddhiAppForAPILevelDefaultThrottlePolicy();
    Assert.assertEquals(actualQuery, expectedQuery);
}
Also used : APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) Test(org.testng.annotations.Test)

Example 3 with APIThrottlePolicyTemplateBuilder

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

the class PolicyExportManager method getApiPolicySiddhiApps.

/**
 * Get execution plan/ siddhi apps for custom policies.
 *
 * @param apiPolicies APIPolicy object list
 * @return Map<String, String> containing execution plan name and execution plans.
 * @throws APITemplateException If template generating fails
 */
private List<Map<String, String>> getApiPolicySiddhiApps(List<APIPolicy> apiPolicies) throws APITemplateException {
    if (log.isDebugEnabled()) {
        log.debug("Get execution plans for API policies.");
    }
    List<Map<String, String>> policies = new ArrayList<>();
    Map<String, String> siddhiApps = new HashMap<>();
    APIThrottlePolicyTemplateBuilder templateBuilder;
    for (APIPolicy apiPolicy : apiPolicies) {
        templateBuilder = new APIThrottlePolicyTemplateBuilder(apiPolicy);
        if (apiPolicy.getPipelines() != null) {
            siddhiApps = templateBuilder.getThrottlePolicyTemplateForPipelines();
        }
        siddhiApps.put(RESOURCE + apiPolicy.getPolicyName() + DEFAULT, templateBuilder.getThrottlePolicyTemplateForAPILevelDefaultCondition());
        policies.add(siddhiApps);
    }
    return policies;
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) APIThrottlePolicyTemplateBuilder(org.wso2.carbon.apimgt.core.template.APIThrottlePolicyTemplateBuilder) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

APIPolicy (org.wso2.carbon.apimgt.core.models.policy.APIPolicy)3 Test (org.testng.annotations.Test)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 APIThrottlePolicyTemplateBuilder (org.wso2.carbon.apimgt.core.template.APIThrottlePolicyTemplateBuilder)1