本文整理汇总了Java中com.github.tomakehurst.wiremock.stubbing.StubMapping类的典型用法代码示例。如果您正苦于以下问题:Java StubMapping类的具体用法?Java StubMapping怎么用?Java StubMapping使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
StubMapping类属于com.github.tomakehurst.wiremock.stubbing包,在下文中一共展示了StubMapping类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createObject
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
@Override
protected URL createObject(DeploymentEndpoints endpoints) {
for(DeploymentEndpoints.Endpoint endpoint : endpoints.list()) {
if(endpoint.getName().equals("wiremock-server")) {
String host = endpoint.getHost();
int port = endpoint.getPort();
WireMock wireMock = new WireMock(host,port);
wireMock.register(StubMapping.buildFrom(stubMapping));
try {
return new URL(String.format("http://%s:%s", host, port));
} catch (MalformedURLException e) {
return null;
}
}
}
return null;
}
示例2: createIndex
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
/**
* Test if the client can create an index
* @param context the test context
*/
@Test
public void createIndex(TestContext context) {
StubMapping settings = stubFor(put(urlEqualTo("/" + INDEX))
.withRequestBody(equalTo(""))
.willReturn(aResponse()
.withBody(ACKNOWLEDGED.encode())
.withStatus(200)));
Async async = context.async();
client.createIndex().subscribe(ok -> {
context.assertTrue(ok);
verify(putRequestedFor(settings.getRequest().getUrlMatcher()));
async.complete();
}, context::fail);
}
示例3: createIndexWithSettings
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
/**
* Test if the client can create an index with settings
* @param context the test context
*/
@Test
public void createIndexWithSettings(TestContext context) {
StubMapping settings = stubFor(put(urlEqualTo("/" + INDEX))
.withRequestBody(equalToJson(SETTINGS_WRAPPER.encode()))
.willReturn(aResponse()
.withBody(ACKNOWLEDGED.encode())
.withStatus(200)));
Async async = context.async();
client.createIndex(SETTINGS).subscribe(ok -> {
context.assertTrue(ok);
verify(putRequestedFor(settings.getRequest().getUrlMatcher()));
async.complete();
}, context::fail);
}
示例4: filter
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
@Override
public Response filter(FilterableRequestSpecification requestSpec,
FilterableResponseSpecification responseSpec, FilterContext context) {
Map<String, Object> configuration = getConfiguration(requestSpec, context);
configuration.put("contract.jsonPaths", this.jsonPaths.keySet());
Response response = context.next(requestSpec, responseSpec);
if (requestSpec.getBody() != null && !this.jsonPaths.isEmpty()) {
String actual = new String((byte[]) requestSpec.getBody());
for (JsonPath jsonPath : this.jsonPaths.values()) {
new JsonPathValue(jsonPath, actual).assertHasValue(Object.class,
"an object");
}
}
if (this.builder != null) {
this.builder.willReturn(getResponseDefinition(response));
StubMapping stubMapping = this.builder.build();
MatchResult match = stubMapping.getRequest()
.match(new WireMockRestAssuredRequestAdapter(requestSpec));
assertThat(match.isExactMatch()).as("wiremock did not match request")
.isTrue();
configuration.put("contract.stubMapping", stubMapping);
}
return response;
}
示例5: storeMappings
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
private void storeMappings(List<StubMapping> mappings) {
try {
File proxiedStubs = new File("target/stubs");
proxiedStubs.mkdirs();
for (StubMapping mapping : mappings) {
File stub = new File(proxiedStubs, testName.getMethodName() + ".json");
stub.createNewFile();
Files.write(stub.toPath(), configure(mapping).toString().getBytes());
}
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例6: run
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
private void run(String... args) {
String[] argsWithExtensions = applyExtensions(args);
CommandLineOptions options = new CommandLineOptions(argsWithExtensions);
if (options.help()) {
out.println(options.helpText());
return;
}
FileSource fileSource = options.filesRoot();
fileSource.createIfNecessary();
FileSource filesFileSource = fileSource.child(FILES_ROOT);
filesFileSource.createIfNecessary();
FileSource mappingsFileSource = fileSource.child(MAPPINGS_ROOT);
mappingsFileSource.createIfNecessary();
WireMockServer wireMockServer = new WireMockServer(options);
if (options.recordMappingsEnabled()) {
wireMockServer.enableRecordMappings(mappingsFileSource, filesFileSource);
}
wireMockServer.setGlobalFixedDelay(50);
try {
wireMockServer.start();
out.println(BANNER);
out.println();
out.println(options);
addMappings(wireMockServer);
out.println("Mock server contains next mappings:");
for (StubMapping mapping : wireMockServer.listAllStubMappings().getMappings()) {
out.println(mapping.toString());
}
} catch (FatalStartupException e) {
System.err.println(e.getMessage());
System.exit(1);
}
}
示例7: build
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
public StubMapping build() {
RequestPattern requestPattern = new RequestPattern(method, url);
ResponseDefinition response = new ResponseDefinition(responseStatus, responseBody);
response.setHeaders(new HttpHeaders(headers));
StubMapping mapping = new StubMapping(requestPattern, response);
return mapping;
}
示例8: ExternalServicesStub
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
ExternalServicesStub(IngredientsProperties ingredientsProperties) throws IOException {
URI uri = URI.create(ingredientsProperties.getRootUrl());
this.wireMockServer = new WireMockServer(WireMockConfiguration.wireMockConfig()
.port(uri.getPort()));
wireMockServer.addStubMapping(StubMapping.buildFrom(
IOUtils.toString(ExternalServicesStub.class.getResourceAsStream("/mappings/chmieleo.json"))));
wireMockServer.addStubMapping(StubMapping.buildFrom(
IOUtils.toString(ExternalServicesStub.class.getResourceAsStream("/mappings/drozdzeo.json"))));
wireMockServer.addStubMapping(StubMapping.buildFrom(
IOUtils.toString(ExternalServicesStub.class.getResourceAsStream("/mappings/slodeo.json"))));
wireMockServer.addStubMapping(StubMapping.buildFrom(
IOUtils.toString(ExternalServicesStub.class.getResourceAsStream("/mappings/wodeo.json"))));
}
示例9: tearDown
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
@After
public void tearDown() {
SnapshotRecordResult recording = WireMock.stopRecording();
List<StubMapping> mappings = recording.getStubMappings();
storeMappings(mappings);
}
示例10: should_print_wiremock_mappings
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
@Test
public void should_print_wiremock_mappings() {
List<StubMapping> mappings = server.listAllStubMappings().getMappings();
System.out.println("\n\nRegistered WireMock Mappings:\n" + mappings);
assertEquals(11, mappings.size());
}
示例11: configure
import com.github.tomakehurst.wiremock.stubbing.StubMapping; //导入依赖的package包/类
/**
* Perform additional customization of the stored {@link StubMapping}.
* E.g. find a timestamp field and change that into a regular expression.
*/
protected StubMapping configure(StubMapping stubMapping) {
return stubMapping;
}