本文整理了Java中io.restassured.response.Response.getBody
方法的一些代码示例,展示了Response.getBody
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.getBody
方法的具体详情如下:
包路径:io.restassured.response.Response
类名称:Response
方法名:getBody
暂无
代码示例来源:origin: spring-projects/spring-restdocs
private byte[] extractContent(Response response) {
return response.getBody().asByteArray();
}
代码示例来源:origin: org.bitbucket.iamkenos/cissnei-rest
public ResponseBody responseBody() {
return response.getBody();
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testBinaryDataForBinaryVariable() {
final byte[] byteContent = "some bytes".getBytes();
HistoricVariableInstance variableInstanceMock = MockProvider.mockHistoricVariableInstance()
.typedValue(Variables.byteArrayValue(byteContent))
.build();
when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);
Response response = given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
.then().expect()
.statusCode(Status.OK.getStatusCode())
.contentType(ContentType.BINARY.toString())
.when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
byte[] responseBytes = response.getBody().asByteArray();
Assert.assertEquals(new String(byteContent), new String(responseBytes));
verify(variableInstanceQueryMock, never()).disableBinaryFetching();
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testBinaryDataForBinaryVariable() {
final byte[] byteContent = "some bytes".getBytes();
MockHistoricVariableUpdateBuilder builder = MockProvider.mockHistoricVariableUpdate();
HistoricVariableUpdate detailMock = builder
.typedValue(Variables.byteArrayValue(byteContent))
.build();
when(historicDetailQueryMock.detailId(detailMock.getId())).thenReturn(historicDetailQueryMock);
when(historicDetailQueryMock.disableCustomObjectDeserialization()).thenReturn(historicDetailQueryMock);
when(historicDetailQueryMock.singleResult()).thenReturn(detailMock);
Response response = given().pathParam("id", MockProvider.EXAMPLE_HISTORIC_VAR_UPDATE_ID)
.then().expect()
.statusCode(Status.OK.getStatusCode())
.contentType(ContentType.BINARY.toString())
.when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
byte[] responseBytes = response.getBody().asByteArray();
Assert.assertEquals(new String(byteContent), new String(responseBytes));
verify(historicDetailQueryMock, never()).disableBinaryFetching();
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testBinaryDataForBinaryVariable() {
final byte[] byteContent = "some bytes".getBytes();
VariableInstance variableInstanceMock =
MockProvider.mockVariableInstance()
.typedValue(Variables.byteArrayValue(byteContent))
.build();
when(variableInstanceQueryMock.variableId(variableInstanceMock.getId())).thenReturn(variableInstanceQueryMock);
when(variableInstanceQueryMock.disableCustomObjectDeserialization()).thenReturn(variableInstanceQueryMock);
when(variableInstanceQueryMock.singleResult()).thenReturn(variableInstanceMock);
Response response = given().pathParam("id", MockProvider.EXAMPLE_VARIABLE_INSTANCE_ID)
.then().expect()
.statusCode(Status.OK.getStatusCode())
.contentType(ContentType.BINARY.toString())
.when().get(VARIABLE_INSTANCE_BINARY_DATA_URL);
byte[] responseBytes = response.getBody().asByteArray();
Assert.assertEquals(new String(byteContent), new String(responseBytes));
verify(variableInstanceQueryMock, never()).disableBinaryFetching();
verify(variableInstanceQueryMock).disableCustomObjectDeserialization();
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testDecisionDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
// setup additional mock behavior
File file = getFile("/processes/todo-process.png");
when(repositoryServiceMock.getDecisionDefinition(MockProvider.EXAMPLE_DECISION_DEFINITION_ID).getDiagramResourceName())
.thenReturn(null);
when(repositoryServiceMock.getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))
.thenReturn(new FileInputStream(file));
// call method
byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID)
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType("application/octet-stream")
.header("Content-Disposition", "attachment; filename=" + null)
.when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();
// verify service interaction
verify(repositoryServiceMock).getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);
// compare input stream with response body bytes
byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "decision diagram");
Assert.assertArrayEquals(expected, actual);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testCaseDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
// setup additional mock behavior
File file = getFile("/processes/todo-process.png");
when(repositoryServiceMock.getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID))
.thenReturn(new FileInputStream(file));
// call method
byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_CASE_DEFINITION_ID)
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType("image/png")
.header("Content-Disposition", "attachment; filename=" +
MockProvider.EXAMPLE_CASE_DEFINITION_DIAGRAM_RESOURCE_NAME)
.when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();
// verify service interaction
verify(repositoryServiceMock).getCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID);
verify(repositoryServiceMock).getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID);
// compare input stream with response body bytes
byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "case diagram");
Assert.assertArrayEquals(expected, actual);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testProcessDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
// setup additional mock behavior
File file = getFile("/processes/todo-process.png");
when(repositoryServiceMock.getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID).getDiagramResourceName())
.thenReturn(null);
when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))
.thenReturn(new FileInputStream(file));
// call method
byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType("application/octet-stream")
.header("Content-Disposition", "attachment; filename=" + null)
.when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();
// verify service interaction
verify(repositoryServiceMock).getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
// compare input stream with response body bytes
byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "process diagram");
Assert.assertArrayEquals(expected, actual);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testCaseDiagramNullFilename() throws FileNotFoundException, URISyntaxException {
// setup additional mock behavior
File file = getFile("/processes/todo-process.png");
when(repositoryServiceMock.getCaseDefinition(MockProvider.EXAMPLE_CASE_DEFINITION_ID).getDiagramResourceName())
.thenReturn(null);
when(repositoryServiceMock.getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID))
.thenReturn(new FileInputStream(file));
// call method
byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_CASE_DEFINITION_ID)
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType("application/octet-stream")
.header("Content-Disposition", "attachment; filename=" + null)
.when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();
// verify service interaction
verify(repositoryServiceMock).getCaseDiagram(MockProvider.EXAMPLE_CASE_DEFINITION_ID);
// compare input stream with response body bytes
byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "case diagram");
Assert.assertArrayEquals(expected, actual);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testProcessDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
// setup additional mock behavior
File file = getFile("/processes/todo-process.png");
when(repositoryServiceMock.getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID))
.thenReturn(new FileInputStream(file));
// call method
byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType("image/png")
.header("Content-Disposition", "attachment; filename=" +
MockProvider.EXAMPLE_PROCESS_DEFINITION_DIAGRAM_RESOURCE_NAME)
.when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();
// verify service interaction
verify(repositoryServiceMock).getProcessDefinition(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
verify(repositoryServiceMock).getProcessDiagram(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID);
// compare input stream with response body bytes
byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "process diagram");
Assert.assertArrayEquals(expected, actual);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testDecisionDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
// setup additional mock behavior
File file = getFile("/processes/todo-process.png");
when(repositoryServiceMock.getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID))
.thenReturn(new FileInputStream(file));
// call method
byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_DEFINITION_ID)
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType("image/png")
.header("Content-Disposition", "attachment; filename=" +
MockProvider.EXAMPLE_DECISION_DEFINITION_DIAGRAM_RESOURCE_NAME)
.when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();
// verify service interaction
verify(repositoryServiceMock).getDecisionDefinition(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);
verify(repositoryServiceMock).getDecisionDiagram(MockProvider.EXAMPLE_DECISION_DEFINITION_ID);
// compare input stream with response body bytes
byte[] expected = IoUtil.readInputStream(new FileInputStream(file), "decision diagram");
Assert.assertArrayEquals(expected, actual);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void decisionRequirementsDiagramRetrieval() throws FileNotFoundException, URISyntaxException {
byte[] actual = given().pathParam("id", MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID)
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType("image/png")
.header("Content-Disposition", "attachment; filename=" +
MockProvider.EXAMPLE_DECISION_DEFINITION_DIAGRAM_RESOURCE_NAME)
.when().get(DIAGRAM_DEFINITION_URL).getBody().asByteArray();
verify(repositoryServiceMock).getDecisionRequirementsDefinition(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID);
verify(repositoryServiceMock).getDecisionRequirementsDiagram(MockProvider.EXAMPLE_DECISION_REQUIREMENTS_DEFINITION_ID);
byte[] expected = IoUtil.readInputStream(new FileInputStream(getFile()), "decision requirements diagram");
Assert.assertArrayEquals(expected, actual);
}
代码示例来源:origin: nidi3/raml-tester
@Override
public byte[] getContent() {
return response.getBody().asByteArray();
}
}
代码示例来源:origin: guru.nidi.raml/raml-tester
@Override
public byte[] getContent() {
return response.getBody().asByteArray();
}
}
代码示例来源:origin: lv.ctco.cukes/cukes-http
@Override
public String getValue(Object o) {
return ((Response) o).getBody().asString();
}
代码示例来源:origin: ctco/cukes
@Override
public String getValue(Object o) {
return ((Response) o).getBody().asString();
}
代码示例来源:origin: org.bitbucket.iamkenos/cissnei-rest
private void logResponse(Response response) {
StringBuilder builder = new StringBuilder("RESPONSE:\n\n");
String body = response.getBody().prettyPrint();
createLog(builder, "STATUS", String.valueOf(response.getStatusCode()), false);
createLog(builder, "HEADERS", response.getHeaders().toString(), true);
if (body.length() > 0) createLog(builder, "BODY", response.getBody().prettyPrint(), true);
scenarioWrite(builder.toString());
}
代码示例来源:origin: org.eclipse.microprofile.openapi/microprofile-openapi-tck
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
if (ContentType.JSON.matches(requestSpec.getContentType())) {
// Conversion is not needed
return ctx.next(requestSpec, responseSpec);
}
try {
Response response = ctx.next(requestSpec, responseSpec);
ObjectMapper yamlReader = new ObjectMapper(new YAMLFactory());
Object obj = yamlReader.readValue(response.getBody().asString(), Object.class);
ObjectMapper jsonWriter = new ObjectMapper();
String json = jsonWriter.writeValueAsString(obj);
ResponseBuilder builder = new ResponseBuilder();
builder.clone(response);
builder.setBody(json);
builder.setContentType(ContentType.JSON);
return builder.build();
}
catch (Exception e) {
throw new IllegalStateException("Failed to convert the request: " + ExceptionUtils.getMessage(e), e);
}
}
代码示例来源:origin: com.atlassian.oai/swagger-request-validator-restassured
/**
* Builds a {@link Response} for the OpenAPI validator out of the
* original {@link io.restassured.response.Response}.
*
* @param originalResponse the original {@link io.restassured.response.Response}
*/
@Nonnull
public static Response of(@Nonnull final io.restassured.response.Response originalResponse) {
requireNonNull(originalResponse, "An original response is required");
final SimpleResponse.Builder builder = new SimpleResponse.Builder(originalResponse.getStatusCode())
.withBody(originalResponse.getBody().asString());
if (originalResponse.getHeaders() != null) {
originalResponse.getHeaders().forEach(header -> builder.withHeader(header.getName(), header.getValue()));
}
return builder.build();
}
}
代码示例来源:origin: alfa-laboratory/akita
/**
* Получает body из ответа и сохраняет в переменную
*
* @param variableName имя переменной, в которую будет сохранен ответ
* @param response ответ от http запроса
*/
public void getBodyAndSaveToVariable(String variableName, Response response) {
if (response.statusCode() >= 200 && response.statusCode() < 300) {
akitaScenario.setVar(variableName, response.getBody().asString());
akitaScenario.write("Тело ответа : \n" + new Prettifier().getPrettifiedBodyIfPossible(response, response));
} else {
fail("Некорректный ответ на запрос: " + new Prettifier().getPrettifiedBodyIfPossible(response, response));
}
}
内容来源于网络,如有侵权,请联系作者删除!