本文整理汇总了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);
}
示例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();
}
示例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();
}
示例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;
}
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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;
}
示例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;
}
示例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;
}
示例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();
}
示例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;
}
示例14: hasEmptyResponseBody
import com.github.tomakehurst.wiremock.http.ResponseDefinition; //导入依赖的package包/类
private boolean hasEmptyResponseBody(ResponseDefinition responseDefinition) {
return responseDefinition.getBody() == null && responseDefinition.getBodyFileName() == null;
}
示例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();
}