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);
}
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);
}
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;
}
Aggregations