本文整理汇总了Java中com.github.tomakehurst.wiremock.http.ResponseDefinition类的典型用法代码示例。如果您正苦于以下问题:Java ResponseDefinition类的具体用法?Java ResponseDefinition怎么用?Java ResponseDefinition使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ResponseDefinition类属于com.github.tomakehurst.wiremock.http包,在下文中一共展示了ResponseDefinition类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: transform
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的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.http.ResponseDefinition; //导入依赖的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.http.ResponseDefinition; //导入依赖的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.http.ResponseDefinition; //导入依赖的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.http.ResponseDefinition; //导入依赖的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.http.ResponseDefinition; //导入依赖的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: createResponse
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的package包/类
private ResponseDefinition createResponse(MockResponse response) {
if (response.getBinaryBody() != null) {
return new ResponseDefinitionBuilder().withBody(response.getBinaryBody())
.withStatus(response.getStatus())
.withHeader("Content-Length", Integer.toString(response.getBinaryBody().length)).build();
}
return new ResponseDefinitionBuilder().withBody(response.getBody())
.withStatus(response.getStatus()).build();
}
开发者ID:daflockinger,项目名称:unitstack,代码行数:10,代码来源:S3RequestTransformer.java
示例8: run
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的package包/类
public void run(ResponseDefinition responseDefinition, Map scope) throws URISyntaxException, NoSuchMethodException, IOException, ScriptException {
Parameters transformers = responseDefinition.getTransformerParameters();
if(transformers != null && transformers.get("before") != null){
String[] beforeBlock = ((List<String>) responseDefinition.getTransformerParameters().get("before")).toArray(new String[0]);
expressions.eval(beforeBlock, scope);
}
}
开发者ID:nishants,项目名称:wirestub,代码行数:8,代码来源:BeforeBlock.java
示例9: transform
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的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
示例10: getResponseBody
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的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: build
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的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;
}
开发者ID:OfficeDev,项目名称:orc-for-android,代码行数:8,代码来源:RequestResponseMappingBuilder.java
示例12: transform
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的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
示例13: getRenderedBody
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的package包/类
/**
* Renders the velocity template.
* @param response
*/
private String getRenderedBody(final ResponseDefinition response) {
final String templatePath = fileSource.getPath().concat("/" + response.getBodyFileName());
final Template template = Velocity.getTemplate(templatePath);
StringWriter writer = new StringWriter();
template.merge(context, writer);
final String rendered = String.valueOf(writer.getBuffer());
return rendered;
}
开发者ID:adamyork,项目名称:wiremock-velocity-transformer,代码行数:13,代码来源:VelocityResponseTransformer.java
示例14: hasEmptyResponseBody
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的package包/类
private boolean hasEmptyResponseBody(ResponseDefinition responseDefinition) {
return responseDefinition.getBody() == null && responseDefinition.getBodyFileName() == null;
}
开发者ID:opentable,项目名称:wiremock-body-transformer,代码行数:4,代码来源:BodyTransformer.java
示例15: templateDeclared
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的package包/类
/**
* @param response
* @return Boolean If the filesource is a template.
*/
private Boolean templateDeclared(final ResponseDefinition response) {
Pattern extension = Pattern.compile(".vm$");
Matcher matcher = extension.matcher(response.getBodyFileName());
return matcher.find();
}
开发者ID:adamyork,项目名称:wiremock-velocity-transformer,代码行数:10,代码来源:VelocityResponseTransformer.java
注:本文中的com.github.tomakehurst.wiremock.http.ResponseDefinition类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论