use of org.wso2.carbon.apimgt.impl.template.APITemplateException in project carbon-apimgt by wso2.
the class GatewaySourceGeneratorImpl method getCompositeAPIConfigStringFromTemplate.
@Override
public String getCompositeAPIConfigStringFromTemplate(List<TemplateBuilderDTO> apiResources, List<CompositeAPIEndpointDTO> compositeApiEndpoints) throws APITemplateException {
StringWriter writer = new StringWriter();
String templatePath = "resources" + File.separator + "template" + File.separator + "composite_template.xml";
try {
// build the context for template and apply the necessary decorators
apiConfigContext.validate();
CompositeAPIConfigContext configContext = new CompositeAPIConfigContext(apiConfigContext, apiResources, compositeApiEndpoints);
VelocityContext context = configContext.getContext();
VelocityEngine velocityengine = new VelocityEngine();
velocityengine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
velocityengine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
velocityengine.setProperty(VelocityEngine.RUNTIME_LOG_LOGSYSTEM, new CommonsLogLogChute());
velocityengine.init();
Template template = velocityengine.getTemplate(templatePath);
template.merge(context, writer);
} catch (ResourceNotFoundException e) {
log.error("Template " + templatePath + " not Found", e);
throw new APITemplateException("Template " + templatePath + " not Found", ExceptionCodes.TEMPLATE_EXCEPTION);
} catch (ParseErrorException e) {
log.error("Syntax error in " + templatePath, e);
throw new APITemplateException("Syntax error in " + templatePath, ExceptionCodes.TEMPLATE_EXCEPTION);
}
return writer.toString();
}
use of org.wso2.carbon.apimgt.impl.template.APITemplateException in project carbon-apimgt by wso2.
the class APIConfigContextTestCase method testAPINameWithNumber.
@Test
public void testAPINameWithNumber() throws APITemplateException {
String apiId = UUID.randomUUID().toString();
API nameWithNumberAPI = new API.APIBuilder("provider", "1111testapi", "1.0.0").id(apiId).context("testcontext").build();
APIConfigContext apiConfigContext = new APIConfigContext(nameWithNumberAPI, "org.test");
apiConfigContext.validate();
String actualServiceName = (String) apiConfigContext.getContext().get("serviceName");
Assert.assertEquals(actualServiceName, "prefix_1111testapi_" + apiId.replaceAll("-", "_"));
}
use of org.wso2.carbon.apimgt.impl.template.APITemplateException in project carbon-apimgt by wso2.
the class ThrottleTemplateBuilderTestCase method testSiddiQueryForApp.
@Test
public void testSiddiQueryForApp() throws APITemplateException {
ApplicationPolicy policy = SampleTestObjectCreator.createDefaultApplicationPolicy();
ApplicationThrottlePolicyTemplateBuilder templateBuilder = new ApplicationThrottlePolicyTemplateBuilder(policy);
String siddhiQuery = templateBuilder.getThrottlePolicyForAppLevel();
String sampleQuery = SampleTestObjectCreator.createDefaultSiddhiAppforAppPolicy();
Assert.assertEquals(siddhiQuery, sampleQuery);
}
use of org.wso2.carbon.apimgt.impl.template.APITemplateException 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.impl.template.APITemplateException in project carbon-apimgt by wso2.
the class ThrottleTemplateBuilderTestCase method testSiddhiQueryForSubscriptionPolicy.
@Test
public void testSiddhiQueryForSubscriptionPolicy() throws APITemplateException {
SubscriptionPolicy policy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
SubscriptionThrottlePolicyTemplateBuilder templateBuilder = new SubscriptionThrottlePolicyTemplateBuilder(policy);
String siddhiQuery = templateBuilder.getThrottlePolicyForSubscriptionLevel();
String sampleQuery = SampleTestObjectCreator.createDefaultSiddhiAppforSubscriptionPolicy();
Assert.assertEquals(siddhiQuery, sampleQuery);
}
Aggregations