Application Models

SV Lab can simulate multiple virtual services in parallel. For example, you can test that your application turns on the light in the kitchen and checks the on/off status of the light in the living room and hallway, simultaneously.

For each test case, you declare an application scenario, which runs when the test is initiated.

Basic application scenario

In the simplest case, you can declare one sayHello application scenario using one service, for example:

@sv.applicationScenario
sayHello() {
    this.hello.simpleSayHello();
}

Then you can launch the scenario from Java:

sv.runSimulation("sayHello");

Alternatively, you can generate an application model in Service Virtualization Designer after you create a virtualization project (File > New > Lab > Application Model).

You can create different application scenarios for each test case. Each application scenario can include multiple service scenarios, which you can optionally interconnect using simulation variables.

Running an application scenario

You can run scenarios sequentially or in parallel.

The following application scenario runs two service scenarios sequentially:

@sv.applicationScenario
sayHelloTwice() {
    this.hello.simpleSayHello();
    this.hello.simpleSayHello();
}

This is actually shorthand for explicit synchronous scenario execution using the sv.callScenario() function, so the above example is equivalent to this one:

@sv.applicationScenario
sayHelloTwice() {
    sv.callScenario(() => this.hello.simpleSayHello());
    sv.callScenario(() => this.hello.simpleSayHello());
}

In the following example, which is more complex, there are two services—control and status. The application scenario runs three service scenarios in parallel using the sv.forkScenario() function:

@sv.applicationScenario
winterDay() {
    sv.forkScenario(() => this.control.controlScenario());
    sv.forkScenario(() => this.status.lobbyScenario());
    sv.forkScenario(() => this.status.poolScenario());
}

Back to top

Test-Embedded Application Model

When a test needs to have fine control over service behavior, you can embed the application scenarios in the test code using the callScenario() and forkScenario() methods using the Service Virtualization Java API, for example:

@Test
public void testHeatingSwitchingOn() {
  sv.runSimulation("heatingWitchingOnTest");    
  // tell SV that the application scenario is starting

  sv.callScenario(module.getScenarioId("warmInside"));
  ...
  // assert that the heating is off

  sv.callScenario(module.getScenarioId("coldInside"));
  ...
  // assert that the control logic has turned the heating on
}

Back to top