Search in sources :

Example 31 with APIConfigContext

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext in project carbon-apimgt by wso2.

the class EndpointConfigContextTest method testEndpointConfigContext.

@Test(expected = APITemplateException.class)
public void testEndpointConfigContext() throws Exception {
    API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0"));
    api.setStatus(APIConstants.CREATED);
    api.setContextTemplate("/");
    String url = "http://maps.googleapis.com/maps/api/geocode/json?address=Colombo";
    String endpointConfig = "{\"production_endpoints\":{\"url\":\"" + url + "\", \"config\":null}," + "\"sandbox_endpoint\":{\"url\":\"" + url + "\",\"config\":null},\"endpoint_type\":\"http\"}";
    api.setEndpointConfig(endpointConfig);
    api.setUrl(url);
    api.setSandboxUrl(url);
    ConfigContext configcontext = new APIConfigContext(api);
    EndpointConfigContext endpointConfigContext = new EndpointConfigContext(configcontext, api);
    endpointConfigContext.validate();
    Assert.assertNotNull(endpointConfigContext.getContext().get("endpoint_config"));
    // set an empty string and check the validation
    endpointConfig = "";
    api.setEndpointConfig(endpointConfig);
    endpointConfigContext = new EndpointConfigContext(configcontext, api);
    endpointConfigContext.validate();
    // set a null value and check the validation
    endpointConfig = null;
    api.setEndpointConfig(endpointConfig);
    endpointConfigContext = new EndpointConfigContext(configcontext, api);
    endpointConfigContext.validate();
    // set invalid value and check the validation
    String invalidEndpointConfig = "\"production_endpoints\"{\"url\":\"" + url + "\", \"config\":null}," + "\"sandbox_endpoint\":{\"url\":\"" + url + "\",\"config\":null},\"endpoint_type\":\"http\"";
    api.setEndpointConfig(invalidEndpointConfig);
    endpointConfigContext = new EndpointConfigContext(configcontext, api);
    endpointConfigContext.validate();
}
Also used : EndpointConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EndpointConfigContext) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) EndpointConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EndpointConfigContext) ConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.ConfigContext) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) Test(org.junit.Test)

Example 32 with APIConfigContext

use of org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext in project carbon-apimgt by wso2.

the class HandlerConfigContextTest method testHandlerConfigContex.

@Test
public void testHandlerConfigContex() throws Exception {
    API api = new API(new APIIdentifier("admin", "TestAPI", "1.0.0"));
    api.setStatus(APIConstants.CREATED);
    api.setContextTemplate("/");
    ConfigContext configcontext = new APIConfigContext(api);
    List<HandlerConfig> handlers = new ArrayList<HandlerConfig>();
    HandlerConfigContex handlerConfigContex = new HandlerConfigContex(configcontext, handlers);
    Assert.assertNotNull(handlerConfigContex.getContext().get("handlers"));
}
Also used : HandlerConfigContex(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfigContex) HandlerConfig(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.HandlerConfig) ArrayList(java.util.ArrayList) API(org.wso2.carbon.apimgt.api.model.API) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) ConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.ConfigContext) APIConfigContext(org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 APIConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.APIConfigContext)17 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)16 ConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.ConfigContext)16 API (org.wso2.carbon.apimgt.api.model.API)14 VelocityContext (org.apache.velocity.VelocityContext)12 HashMap (java.util.HashMap)9 API (org.wso2.carbon.apimgt.core.models.API)8 Map (java.util.Map)7 APIConfigContext (org.wso2.carbon.apimgt.core.template.APIConfigContext)7 ArrayList (java.util.ArrayList)6 GatewaySourceGenerator (org.wso2.carbon.apimgt.core.api.GatewaySourceGenerator)6 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)6 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)6 EndpointSecurityModel (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.EndpointSecurityModel)6 SecurityConfigContext (org.wso2.carbon.apimgt.rest.api.publisher.v1.common.template.SecurityConfigContext)6 StringWriter (java.io.StringWriter)5 Template (org.apache.velocity.Template)5 VelocityEngine (org.apache.velocity.app.VelocityEngine)5 APITemplateException (org.wso2.carbon.apimgt.core.template.APITemplateException)4