Configure Virtual Lab Programmatically Using Service Virtualization Java API

The basic way of configuring and initializing virtual lab in a JUnit test is calling the _SV API_ methods in some annotated @BeforeClass method to compile the module with application and service model sources:

Module module = sv.compileModuleFromSources("classpath:/demo/*");

Next, you create the virtual lab with the simulation models in it, picking one particular application model to use:

VirtualLab lab = sv.setActiveVirtualLab(labBuilder ->

Then, you create an HTTP connector to provide connectivity for the REST virtual service that you want to simulate.

Connector http = sv.addConnector(f -> f.connector(lab.getId())
    .setProperty(ConnectorProperties.BIND_PORT, ENDPOINT_PORT));

Finally, you create a service instance specifying the virtual endpoint path, including where it will be exposed, and you set the SIMULATE_SERVICE simulation mode.

sv.addVirtualServiceInstance(f -> f.virtualServiceInstance(lab.getId())
    .addEndpoint(b -> b.endpoint()
        .setProperty(HttpProtocolProperties.GATEWAY_ENDPOINT_VIRTUAL_PATH, ENDPOINT_PATH)

Back to top

See also: