本文整理匯總了Java中com.github.tomakehurst.wiremock.junit.WireMockRule類的典型用法代碼示例。如果您正苦於以下問題:Java WireMockRule類的具體用法?Java WireMockRule怎麽用?Java WireMockRule使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
WireMockRule類屬於com.github.tomakehurst.wiremock.junit包,在下文中一共展示了WireMockRule類的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: MockPersistenceProvider
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
/**
* Create a mock persistence using a wire mock rule.
* Recommended: Use {@link #DEFAULT_MOCK_PERSISTENCE_PORT} as port.
* @param rule The wire mock rule to create the mocking stubs for.
*/
public MockPersistenceProvider(WireMockRule rule) {
this.port = rule.port();
rule.stubFor(WireMock.get(WireMock.urlEqualTo(
"/" + Service.PERSISTENCE.getServiceName() + "/rest/orders"))
.willReturn(WireMock.okJson(getOrders())));
rule.stubFor(WireMock.get(WireMock.urlEqualTo(
"/" + Service.PERSISTENCE.getServiceName() + "/rest/orderitems"))
.willReturn(WireMock.okJson(getOrderItems())));
rule.stubFor(WireMock.get(WireMock.urlEqualTo(
"/" + Service.PERSISTENCE.getServiceName() + "/rest/generatedb/finished"))
.willReturn(WireMock.ok("true")));
}
示例2: initializeServiceQueryStubs
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
private void initializeServiceQueryStubs(WireMockRule rule,
List<Integer> persistencePorts, List<Integer> recommenderPorts)
throws JsonProcessingException {
List<String> persistences = new LinkedList<String>();
for (int persistencePort: persistencePorts) {
persistences.add("localhost:" + persistencePort);
}
String json = new ObjectMapper().writeValueAsString(persistences);
rule.stubFor(WireMock.get(WireMock.urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.PERSISTENCE.getServiceName() + "/"))
.willReturn(WireMock.okJson(json)));
List<String> recommenders = new LinkedList<String>();
for (int recommenderPort: recommenderPorts) {
recommenders.add("localhost:" + recommenderPort);
}
json = new ObjectMapper().writeValueAsString(recommenders);
rule.stubFor(WireMock.get(WireMock.urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.RECOMMENDER.getServiceName() + "/"))
.willReturn(WireMock.okJson(json)));
}
示例3: initializeUpdateAndHeartbeatStubs
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
private void initializeUpdateAndHeartbeatStubs(WireMockRule rule) {
rule.stubFor(WireMock.put(WireMock.urlMatching(
"/tools.descartes.petsupplystore.registry/rest/services/.*"))
.willReturn(WireMock.ok()));
rule.stubFor(WireMock.delete(WireMock.urlMatching(
"/tools.descartes.petsupplystore.registry/rest/services/.*"))
.willReturn(WireMock.ok()));
}
示例4: initializeMockRegistry
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
private void initializeMockRegistry(WireMockRule wireMockRule, int count, int startport)
throws JsonProcessingException {
List<String> strings = new LinkedList<String>();
for (int i = 0; i < count; i++) {
strings.add("localhost:" + (startport + i));
}
String json = new ObjectMapper().writeValueAsString(strings);
wireMockRule.stubFor(WireMock.get(WireMock.urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/" + Service.PERSISTENCE.getServiceName()))
.willReturn(WireMock.okJson(json)));
wireMockRule.stubFor(WireMock.post(WireMock.urlEqualTo(
"/tools.descartes.petsupplystore.registry/rest/services/"
+ Service.PERSISTENCE.getServiceName() + "/*"))
.willReturn(WireMock.ok()));
}
示例5: addMockRequestListener
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
public static void addMockRequestListener(final WireMockRule rule, final List<Request> wiremockRequests) {
//Handy WireMock listener that stores each request received
rule.addMockServiceRequestListener(new RequestListener() {
@Override
public void requestReceived(Request request, Response response) {
wiremockRequests.add(LoggedRequest.createFrom(request));
}
});
}
示例6: TomcatTestHandler
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
/**
* Create a Tomcat test handler for persistence testing.
* @param count Number of testing tomcats.
* @param startPort Port to start with (do not use 0 for auto-assigning).
* @param wireMockRule Wire mock rule for mocking the registry.The test handler will
* add all services with respective stubs to the rule.
* @param endpoints Class objects for the endpoints.
* @throws ServletException Exception on failure.
* @throws LifecycleException Exception on failure.
* @throws JsonProcessingException Exception on failure.
*/
public TomcatTestHandler(int count, int startPort, WireMockRule wireMockRule, Class<?>... endpoints)
throws ServletException, LifecycleException, JsonProcessingException {
tomcats = new Tomcat[count];
EMFManagerInitializer.initializeEMF();
for (int i = 0; i < count; i++) {
tomcats[i] = new Tomcat();
tomcats[i].setPort(startPort + i);
tomcats[i].setBaseDir(testWorkingDir);
Context context = tomcats[i].addWebapp(CONTEXT, testWorkingDir);
//Registry
if (wireMockRule != null) {
ContextEnvironment registryURL = new ContextEnvironment();
registryURL.setDescription("");
registryURL.setOverride(false);
registryURL.setType("java.lang.String");
registryURL.setName("registryURL");
registryURL.setValue("http://localhost:" + wireMockRule.port()
+ "/tools.descartes.petsupplystore.registry/rest/services/");
context.getNamingResources().addEnvironment(registryURL);
ContextEnvironment servicePort = new ContextEnvironment();
servicePort.setDescription("");
servicePort.setOverride(false);
servicePort.setType("java.lang.String");
servicePort.setName("servicePort");
servicePort.setValue("" + startPort + i);
context.getNamingResources().addEnvironment(servicePort);
context.addApplicationListener(RegistrationDaemon.class.getName());
}
//REST endpoints
ResourceConfig restServletConfig = new ResourceConfig();
for (Class<?> endpoint: endpoints) {
restServletConfig.register(endpoint);
}
ServletContainer restServlet = new ServletContainer(restServletConfig);
tomcats[i].addServlet(CONTEXT, "restServlet", restServlet);
context.addServletMappingDecoded("/rest/*", "restServlet");
tomcats[i].start();
}
if (wireMockRule != null) {
initializeMockRegistry(wireMockRule, count, startPort);
}
System.out.println("Initializing Database with size " + CategoryRepository.REPOSITORY.getAllEntities().size());
}
示例7: HttpClientFactoryTest
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
public HttpClientFactoryTest() throws UnknownHostException {
hostName = InetAddress.getLocalHost().getHostName();
server = new WireMockRule(options().port(9999).bindAddress(hostName));
proxy = new WireMockRule(options().port(8888).bindAddress(hostName));
}
示例8: GHMockRule
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
public GHMockRule(WireMockRule mocked) {
this.service = mocked;
}
示例9: service
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
/**
* @return wiremock rule
*/
public WireMockRule service() {
return service;
}
示例10: MockRegistry
import com.github.tomakehurst.wiremock.junit.WireMockRule; //導入依賴的package包/類
/**
* Create a mock registry using a wiremock rule.
* Recommended: Use {@link #DEFAULT_MOCK_REGISTRY_PORT} as port for your rule.
* @param rule The wiremock rule to generate the mock stubs for.
* @param persistencePorts Ports of the (mock) persistence providers.
* @param recommenderPorts Ports of the recommenders.
* @throws JsonProcessingException Exception on failure.
*/
public MockRegistry(WireMockRule rule, List<Integer> persistencePorts, List<Integer> recommenderPorts)
throws JsonProcessingException {
port = rule.port();
initializeServiceQueryStubs(rule, persistencePorts, recommenderPorts);
initializeUpdateAndHeartbeatStubs(rule);
}