本文整理了Java中io.restassured.response.Response.asByteArray
方法的一些代码示例,展示了Response.asByteArray
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.asByteArray
方法的具体详情如下:
包路径:io.restassured.response.Response
类名称:Response
方法名:asByteArray
暂无
代码示例来源:origin: rest-assured/rest-assured
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
long start = System.currentTimeMillis();
Response response = ctx.next(requestSpec, responseSpec);
if (shouldConsumeStream && response instanceof RestAssuredResponseImpl && ((RestAssuredResponseImpl) response).isInputStream()) {
// Consume the body of the request (important if measure time also should include downloading of body)
response.asByteArray();
}
long end = System.currentTimeMillis();
long responseTime = end - start;
ctx.setValue(RESPONSE_TIME_MILLISECONDS, responseTime);
return response;
}
代码示例来源:origin: rest-assured/rest-assured
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
Response response = ctx.next(requestSpec, responseSpec);
final int statusCode = response.statusCode();
if (matcher.matches(statusCode)) {
ResponsePrinter.print(response, response, stream, logDetail, shouldPrettyPrint);
final byte[] responseBody;
if (logDetail == LogDetail.BODY || logDetail == LogDetail.ALL) {
responseBody = response.asByteArray();
} else {
responseBody = null;
}
response = cloneResponseIfNeeded(response, responseBody);
}
return response;
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testGetRenderedStartFormForDifferentPlatformEncoding() throws NoSuchFieldException, IllegalAccessException, UnsupportedEncodingException {
String expectedResult = "<formField>unicode symbol: \u2200</formField>";
when(formServiceMock.getRenderedStartForm(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)).thenReturn(expectedResult);
Response response = given()
.pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
.then()
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType(XHTML_XML_CONTENT_TYPE)
.when()
.get(RENDERED_FORM_URL);
String responseContent = new String(response.asByteArray(), EncodingUtil.DEFAULT_ENCODING);
Assertions.assertThat(responseContent).isEqualTo(expectedResult);
}
代码示例来源:origin: camunda/camunda-bpm-platform
@Test
public void testGetRenderedFormForDifferentPlatformEncoding() throws NoSuchFieldException, IllegalAccessException, UnsupportedEncodingException {
String expectedResult = "<formField>unicode symbol: \u2200</formField>";
when(formServiceMock.getRenderedTaskForm(MockProvider.EXAMPLE_TASK_ID)).thenReturn(expectedResult);
Response response = given()
.pathParam("id", EXAMPLE_TASK_ID)
.then()
.expect()
.statusCode(Status.OK.getStatusCode())
.contentType(XHTML_XML_CONTENT_TYPE)
.when()
.get(RENDERED_FORM_URL);
String responseContent = new String(response.asByteArray(), EncodingUtil.DEFAULT_ENCODING);
Assertions.assertThat(responseContent).isEqualTo(expectedResult);
}
代码示例来源:origin: Frameworkium/frameworkium-core
/**
* @param url the url to GET
* @param maxTries max number of tries to GET url
* @return the bytes from the downloaded URL
* @throws TimeoutException if download fails and max tries have been exceeded
*/
public byte[] fetchWithRetry(URL url, int maxTries) throws TimeoutException {
logger.debug("Downloading: " + url);
for (int i = 0; i < maxTries; i++) {
Response response = RestAssured.get(url);
if (response.getStatusCode() == HttpStatus.SC_OK) {
return response.asByteArray();
}
logger.debug("Retrying download: " + url);
try {
TimeUnit.SECONDS.sleep(2);
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
}
throw new TimeoutException();
}
}
代码示例来源:origin: arquillian/arquillian-cube
@Override
public Response filter(FilterableRequestSpecification requestSpec, FilterableResponseSpecification responseSpec, FilterContext ctx) {
final Response response = ctx.next(requestSpec, responseSpec);
final ByteArrayOutputStream responseLog = new ByteArrayOutputStream();
final PrintStream stream = new PrintStream(responseLog);
ResponsePrinter.print(response, response, stream, LogDetail.ALL, true);
final File logFile = new File(createLogDirectory(new File(reporterConfiguration.getRootDirectory())), "restassuredResponse.log");
writeContent(responseLog, logFile);
final Path rootDir = Paths.get(reporterConfiguration.getRootDirectory());
final Path relativePath = rootDir.relativize(logFile.toPath());
Reporter.createReport(REST_RESPONSE_LOG)
.addKeyValueEntry(LOG_PATH, new FileEntry(relativePath))
.inSection(new DockerLogSection())
.fire(reportEvent);
final byte[] responseBody = response.asByteArray();
return cloneResponseIfNeeded(response, responseBody);
}
内容来源于网络,如有侵权,请联系作者删除!