Search in sources :

Example 1 with Emulator

use of org.apache.synapse.commons.emulator.core.Emulator in project wso2-synapse by wso2.

the class MockServiceCreator method startMockServiceServer.

/**
 * Start service for given parameters using emulator.
 *
 * @param mockServiceName endpoint name given in descriptor data
 * @param host            domain of the url
 * @param context         path of the url
 * @param resources       resources of the service
 */
static void startMockServiceServer(String mockServiceName, String host, int port, String context, List<ServiceResource> resources) {
    try {
        HTTPProtocolEmulator httpEmulator = new Emulator().getHttpProtocolEmulator();
        emulatorServiceList.add(httpEmulator);
        HttpConsumerContext emulator = httpEmulator.consumer().host(host).port(port).context(context);
        for (ServiceResource resource : resources) {
            routeThroughResourceMethod(resource, emulator);
        }
        emulator.operations().start();
        log.info("Mock service started for " + mockServiceName + " in - http://" + host + ":" + port + context);
    } catch (Exception e) {
        log.error("Error in initiating mock service named " + mockServiceName, e);
    }
}
Also used : HttpConsumerContext(org.apache.synapse.commons.emulator.http.dsl.HttpConsumerContext) HTTPProtocolEmulator(org.apache.synapse.commons.emulator.http.HTTPProtocolEmulator) Emulator(org.apache.synapse.commons.emulator.core.Emulator) HTTPProtocolEmulator(org.apache.synapse.commons.emulator.http.HTTPProtocolEmulator) ServiceResource(org.apache.synapse.unittest.testcase.data.classes.ServiceResource) MalformedURLException(java.net.MalformedURLException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 MalformedURLException (java.net.MalformedURLException)1 Emulator (org.apache.synapse.commons.emulator.core.Emulator)1 HTTPProtocolEmulator (org.apache.synapse.commons.emulator.http.HTTPProtocolEmulator)1 HttpConsumerContext (org.apache.synapse.commons.emulator.http.dsl.HttpConsumerContext)1 ServiceResource (org.apache.synapse.unittest.testcase.data.classes.ServiceResource)1