本文整理汇总了Java中com.github.tomakehurst.wiremock.common.FileSource类的典型用法代码示例。如果您正苦于以下问题:Java FileSource类的具体用法?Java FileSource怎么用?Java FileSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FileSource类属于com.github.tomakehurst.wiremock.common包,在下文中一共展示了FileSource类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition,
FileSource files, Parameters parameters) {
MockParameters params = (MockParameters) parameters.get(UnitStackTest.MOCK_PARAMS);
Map<String, String> body = new HashMap<>();
String method = request.getMethod().getName();
byte[] fileContent = null;
body.put(PARAMETER_URL_NAME, request.getAbsoluteUrl());
body.put(PARAMETER_METHOD, method);
if (method.equals("GET")) {
body.put(ACTION, StringUtils.substringAfter(request.getAbsoluteUrl(), "?"));
} else {
body.put(PARAMETER_RESPONSE_XML, request.getBodyAsString());
fileContent = request.getBody();
}
body.putAll(getHeaders(request));
MockResponse response = s3Responder.createResponse(
new MockRequest(body, params, utils).withBuckets(buckets).withFileContent(fileContent));
return createResponse(response);
}
开发者ID:daflockinger,项目名称:unitstack,代码行数:23,代码来源:S3RequestTransformer.java
示例2: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request,
ResponseDefinition responseDefinition,
FileSource files,
Parameters parameters) {
ResponseDefinitionBuilder builder = new ResponseDefinitionBuilder().like(responseDefinition);
String templatePath = responseDefinition.getBodyFileName();
if (templatePath != null && templatePath.contains(".template")) {
try {
Map scope = new ResponseScope(session, new HashMap(this.config), RequestReader.read(request));
responseWriter = responseWriter == null ? new ResponseWriter(files.getPath()) : responseWriter;
new BeforeBlock().run(responseDefinition, scope);
responseWriter.writeTo(builder, scope, templatePath);
} catch (Exception e) {
String errorMessage = "************* Jeyson Error *******************" + System.getProperty("line.separator");
errorMessage += e.getMessage() + System.getProperty("line.separator");
System.err.println(errorMessage);
e.printStackTrace();
}
}
return builder.build();
}
开发者ID:nishants,项目名称:wirestub,代码行数:27,代码来源:JeysonWiremock.java
示例3: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request,
ResponseDefinition responseDefinition,
FileSource files,
Parameters parameters) {
ResponseDefinitionBuilder builder = new ResponseDefinitionBuilder().like(responseDefinition);
String templatePath = responseDefinition.getBodyFileName();
if (templatePath != null) {
try {
Map scope = new ResponseScope(session, new HashMap(this.config), RequestReader.read(request));
responseWriter = responseWriter == null ? new ResponseWriter(files.getPath()) : responseWriter;
new BeforeBlock().run(responseDefinition, scope);
responseWriter.writeTo(builder, scope, templatePath);
} catch (Exception e) {
String errorMessage = "************* Jeyson Error *******************" + System.getProperty("line.separator");
errorMessage += e.getMessage() + System.getProperty("line.separator");
System.err.println(errorMessage);
e.printStackTrace();
}
}
return builder.build();
}
开发者ID:nishants,项目名称:wirestub,代码行数:27,代码来源:JeysoneWiremockException.java
示例4: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(final Request request,
final ResponseDefinition responseDefinition, final FileSource files,
final Parameters parameters) {
if (responseDefinition.specifiesBodyFile() && templateDeclared(responseDefinition)) {
this.fileSource = files;
final VelocityEngine velocityEngine = new VelocityEngine();
velocityEngine.init();
final ToolManager toolManager = new ToolManager();
toolManager.setVelocityEngine(velocityEngine);
context = toolManager.createContext();
addBodyToContext(request.getBodyAsString());
addHeadersToContext(request.getHeaders());
context.put("requestAbsoluteUrl", request.getAbsoluteUrl());
context.put("requestUrl", request.getUrl());
context.put("requestMethod", request.getMethod());
final String body = getRenderedBody(responseDefinition);
return ResponseDefinitionBuilder.like(responseDefinition).but()
.withBody(body)
.build();
} else {
return responseDefinition;
}
}
开发者ID:adamyork,项目名称:wiremock-velocity-transformer,代码行数:25,代码来源:VelocityResponseTransformer.java
示例5: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition,
FileSource files, Parameters parameters) {
MockParameters params = (MockParameters) parameters.get(UnitStackTest.MOCK_PARAMS);
Map<String, String> body = utils.queryStringToMap(request.getBodyAsString());
MockResponse response =
snsResponder.createResponse(new MockRequest(body, params, utils).withTopics(topics));
return new ResponseDefinitionBuilder().withBody(response.getBody())
.withStatus(response.getStatus()).build();
}
开发者ID:daflockinger,项目名称:unitstack,代码行数:12,代码来源:SnsRequestTransformer.java
示例6: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition,
FileSource files, Parameters parameters) {
MockParameters params = (MockParameters) parameters.get(UnitStackTest.MOCK_PARAMS);
Map<String, String> body = new HashMap<>(utils.queryStringToMap(request.getBodyAsString()));
body.put(PARAMETER_URL_NAME, request.getUrl());
MockResponse response =
sqsResponder.createResponse(new MockRequest(body, params, utils).withQueues(queues));
return new ResponseDefinitionBuilder().withBody(response.getBody())
.withStatus(response.getStatus()).build();
}
开发者ID:daflockinger,项目名称:unitstack,代码行数:14,代码来源:SqsRequestTransformer.java
示例7: main
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
public static void main(String[] args){
try {
int port = 8099;
WireMockServer server = new WireMockServer(
wireMockConfig().port(port).notifier(new ConsoleNotifier(true))
);
Path m = Paths.get("target/wiremock/mappings");
Path f = Paths.get("target/wiremock/files");
Files.createDirectories(m);
Files.createDirectories(f);
FileSource mappings = new SingleRootFileSource(m.toFile().getAbsolutePath());
FileSource files = new SingleRootFileSource(m.toFile().getAbsolutePath());
server.enableRecordMappings(mappings,files);
server.start();
NASDAQQuotesSoap soap = WsProvider.getNASDAQQuotesSoap("localhost:" + port);
server.stubFor(post(urlMatching(".*")).
willReturn(aResponse().proxiedFrom("http://" + WsProvider.NASDAQ_ADDRESS)));
for (MarketCenter mc : soap.listMarketCenters().getMarketCenter()) {
System.out.println(mc.getName());
}
server.stop();
} catch (Exception e){
e.printStackTrace();
} finally {
System.exit(0);
}
}
开发者ID:arcuri82,项目名称:pg6100,代码行数:34,代码来源:WsRecorder.java
示例8: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(final Request request, final ResponseDefinition responseDefinition, final FileSource files) {
String patientHashedId = request.getUrl().replace("/patients/", "");
final Patient patientEntity = createPatient(patientHashedId);
try {
responseDefinition.setBody(mapper.writeValueAsString(patientEntity));
} catch (JsonProcessingException jpe) {
LOGGER.error("Unable to convert patient to JSON string", jpe);
}
return responseDefinition;
}
开发者ID:webdizz,项目名称:web-scale-perf-testing,代码行数:12,代码来源:PatientResponseTransformer.java
示例9: run
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的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);
}
}
开发者ID:webdizz,项目名称:web-scale-perf-testing,代码行数:41,代码来源:PatientApiServer.java
示例10: getResponseBody
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
private String getResponseBody(ResponseDefinition responseDefinition, FileSource fileSource) {
String body;
if (responseDefinition.getBody() != null) {
body = responseDefinition.getBody();
} else {
BinaryFile binaryFile = fileSource.getBinaryFileNamed(responseDefinition.getBodyFileName());
body = new String(binaryFile.readContents(), StandardCharsets.UTF_8);
}
return body;
}
开发者ID:opentable,项目名称:wiremock-body-transformer,代码行数:11,代码来源:BodyTransformer.java
示例11: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public ResponseDefinition transform(Request request, ResponseDefinition responseDefinition, FileSource files) {
System.out.println("Transforming placeholders in " + request.getUrl());
String responseBody = responseDefinition.getBody();
if (responseDefinition.getBodyFileName() != null) {
responseBody = new String(files.getBinaryFileNamed(responseDefinition.getBodyFileName()).readContents(),
Charset.defaultCharset());
}
return ResponseDefinitionBuilder.like(responseDefinition).but().withBody(this.transformResponse(request, responseBody)).build();
}
开发者ID:jberrueta,项目名称:wiremock-extensions,代码行数:11,代码来源:PlaceholderTransformer.java
示例12: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public Response transform(final Request request, final Response response, final FileSource files,
final Parameters parameters) {
try {
final Map<String, Object> queries = this.getQueriesConfig(parameters);
final RequestConfigHandler requestConfig = this.config.getRequestConfigHandler(request, parameters);
final Object structure = queries.get("structure");
String jsonStructure;
if (structure == null) {
jsonStructure = "${WireMockCsv}";
} else {
jsonStructure = structure instanceof String ? (String) structure : this.jsonConverter.convertObjectToJson(structure);
}
final QueryResults qr = this.executeQueries(requestConfig, queries);
final Builder builder = Response.Builder.like(response).but();
String body = jsonStructure
.replace("\"${WireMockCsv}\"", "${WireMockCsv}")
.replace("${WireMockCsv}", this.jsonConverter.convertToJson(qr));
if (qr.getLines().isEmpty() && queries.containsKey("noLines")) {
@SuppressWarnings("unchecked")
final
Map<String, Object> noLines = (Map<String, Object>) queries.get("noLines");
if (noLines.containsKey("status")) {
builder.status((Integer) noLines.get("status"));
}
if (noLines.containsKey("statusMessage")) {
builder.statusMessage((String) noLines.get("statusMessage"));
}
if (noLines.containsKey("response")) {
final Object responseNotFound = noLines.get("response");
body = responseNotFound instanceof String ? (String) responseNotFound : this.jsonConverter.convertObjectToJson(responseNotFound);
}
}
builder.body(this.jsonConverter.formatJson(body));
return builder.build();
} catch (final WireMockCsvException e) {
WireMockConfiguration.wireMockConfig().notifier().error(e.getMessage(), e);
throw new RuntimeException(e);
}
}
开发者ID:massamany,项目名称:WireMockCsv,代码行数:43,代码来源:WireMockCsv.java
示例13: transform
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public Response transform(Request request, Response response, FileSource files, Parameters parameters) {
return Response.Builder.like(response).but()
.body("wiremock-maven-plugin-transformed-response-body")
.build();
}
开发者ID:deliverymind,项目名称:wiremock-maven-plugin,代码行数:7,代码来源:SampleResponseTransformer.java
示例14: child
import com.github.tomakehurst.wiremock.common.FileSource; //导入依赖的package包/类
@Override
public FileSource child(String name) {
return new AndroidAssetsReadOnlyFileSource(assetManager, name);
}
开发者ID:handstandsam,项目名称:AndroidHttpMockingExamples,代码行数:5,代码来源:AndroidAssetsReadOnlyFileSource.java
注:本文中的com.github.tomakehurst.wiremock.common.FileSource类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论