Before you can simulate data that is transmitted through an endpoint, learn which data is transmitted through the endpoint. For additional information, see Learning which Data is Transmitted Through an Endpoint.
To add service virtualization functionality to an existing Silk4J script:
private static Desktop desktop = new Desktop();
private static SvClient sv;
import org.junit.BeforeClass; import com.microfocus.silktest.jtf.sv.SvLabIntegration; import org.microfocus.sv.api.SvClient; import org.microfocus.sv.model.project.Module;
@BeforeClass
public static void startSVLabSimulation() {
String scenarioName = "PopularProducts";
SvLabIntegration svLabIntegration = desktop.getSvLabIntegration();
String endpoint = svLabIntegration.getServerEndpoint();
sv = SvClient.newInstance(endpoint);
Module module = sv.compileModuleFromSources("classpath:/" + scenarioName + "/*");
sv.loadActiveVirtualLab("classpath:/" + scenarioName + "/sv-lab.json", module, true);
sv.startActiveVirtualLab();
sv.runSimulation(scenarioName);
}
import org.junit.AfterClass;
@AfterClass
public static void stopSVLab() {
if (sv != null) {
sv.close();
}
}
import org.junit.AfterClass;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.microfocus.sv.api.SvClient;
import org.microfocus.sv.model.project.Module;
import com.borland.silktest.jtf.BrowserBaseState;
import com.borland.silktest.jtf.Desktop;
import com.borland.silktest.jtf.xbrowser.DomElement;
import com.microfocus.silktest.jtf.sv.SvLabIntegration;
public class MyTest {
private static Desktop desktop = new Desktop();
private static SvClient sv;
@BeforeClass
public static void startSVLabSimulation() {
String scenarioName = "PopularProducts";
SvLabIntegration svLabIntegration = desktop.getSvLabIntegration();
String endpoint = svLabIntegration.getServerEndpoint();
sv = SvClient.newInstance(endpoint);
Module module = sv.compileModuleFromSources("classpath:/" + scenarioName + "/*");
sv.loadActiveVirtualLab("classpath:/" + scenarioName + "/sv-lab.json", module, true);
sv.startActiveVirtualLab();
sv.runSimulation(scenarioName);
}
@Before
public void baseState() {
// Go to web page 'http://advantageonlineshopping.com'
BrowserBaseState baseState = new BrowserBaseState();
baseState.execute(desktop);
}
@Test
public void testSimulatedProduct() {
DomElement firstPopularItem = desktop.<DomElement> find("//BrowserApplication//BrowserWindow//P[@name='popular_item_16_name']");
Assert.assertEquals("SIMULATED: HP ELITEPAD 1000 G2 TABLET", firstPopularItem.getText());
}
@AfterClass
public static void stopSVLab() {
if (sv != null) {
sv.close();
}
}
}