本文整理了Java中com.jayway.restassured.response.Response.asInputStream
方法的一些代码示例,展示了Response.asInputStream
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Response.asInputStream
方法的具体详情如下:
包路径:com.jayway.restassured.response.Response
类名称:Response
方法名:asInputStream
暂无
代码示例来源:origin: Talend/components
private ObjectNode getResponseAsObjectNode(Response response) throws java.io.IOException {
return mapper.readerFor(ObjectNode.class).readValue(response.asInputStream());
}
代码示例来源:origin: com.jayway.restassured/rest-assured
/**
* Clone an already existing response.
*
* @return Builder.
*/
public ResponseBuilder clone(Response response) {
if (isRestAssuredResponse(response)) {
final RestAssuredResponseImpl raResponse = raResponse(response);
restAssuredResponse.setContent(raResponse.getContent());
restAssuredResponse.setHasExpectations(raResponse.getHasExpectations());
restAssuredResponse.setDefaultContentType(raResponse.getDefaultContentType());
restAssuredResponse.setDecoderConfig(raResponse.getDecoderConfig());
restAssuredResponse.setSessionIdName(raResponse.getSessionIdName());
restAssuredResponse.setConnectionManager(raResponse.getConnectionManager());
restAssuredResponse.setConfig(raResponse.getConfig());
restAssuredResponse.setRpr(raResponse.getRpr());
restAssuredResponse.setLogRepository(raResponse.getLogRepository());
restAssuredResponse.setFilterContextProperties(raResponse.getFilterContextProperties());
} else {
restAssuredResponse.setContent(response.asInputStream());
}
restAssuredResponse.setContentType(response.getContentType());
restAssuredResponse.setCookies(response.getDetailedCookies());
restAssuredResponse.setResponseHeaders(response.getHeaders());
restAssuredResponse.setStatusCode(response.getStatusCode());
restAssuredResponse.setStatusLine(response.getStatusLine());
return this;
}
代码示例来源:origin: Talend/components
@Test
public void getJdbcProperties() throws java.io.IOException {
// when
Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
.expect().statusCode(200).log().ifError() //
.get(getVersionPrefix() + "/properties/{definitionName}", DATA_STORE_DEFINITION_NAME);
// then
ObjectNode jdbcProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream());
// should resemble jdbc_data_store_form.json
assertNotNull(jdbcProperties.get("jsonSchema"));
assertNotNull(jdbcProperties.get("properties"));
assertNotNull(jdbcProperties.get("uiSchema"));
assertEquals("JDBCDatastore", jdbcProperties.get("properties").get("@definitionName").textValue());
}
代码示例来源:origin: Talend/components
private String getDataStoreDefinitionPropertiesTitle(Locale locale) throws IOException {
Response response = given().accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
.expect() //
.statusCode(200).log().ifError() //
.with().port(localServerPort) //
.param(LANGUAGE_QUERY_PARAMETER_NAME, locale.toLanguageTag())
.get(getVersionPrefix() + "/properties/{name}", DATA_STORE_DEFINITION_NAME);
JsonNode jsonNode = mapper.readTree(response.asInputStream());
return jsonNode.get("jsonSchema").get("title").asText();
}
代码示例来源:origin: Talend/components
public void shouldListDefinitions(List<String> names, //
Class clazz, //
Function<List<String>, Map<String, ? extends Definition>> provider, //
DefinitionType wantedType, //
String expectedType) throws IOException {
// given
BDDMockito.given(delegate.getDefinitionsMapByType(clazz)) //
.willReturn(provider.apply(names));
// when
final Response response = when().get(getVersionPrefix() + "/definitions/" + wantedType).andReturn();
// then
assertEquals(OK.value(), response.getStatusCode());
List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
});
assertEquals(names.size(), actual.size());
actual.forEach(d -> {
assertEquals(expectedType, d.getType());
assertTrue(names.contains(d.getName().substring("mock ".length()))); // it's expected
});
}
代码示例来源:origin: Talend/components
public void shouldFilterComponentsByTypologyAndExecutionEngine(ConnectorTypology wantedTypology,
ExecutionEngine executionEngine, int expectedResults) throws IOException {
// given
Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) //
.willReturn(definitions);
// when
final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology
+ "&executionEngine=" + executionEngine.name()).andReturn();
// then
assertEquals(OK.value(), response.getStatusCode());
List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
});
assertEquals(expectedResults, actual.size());
assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name()))
.filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count());
}
代码示例来源:origin: Talend/components
public void shouldFilterComponentsByExecutionEngine(ExecutionEngine executionEngine, int expectedResults) throws IOException {
// given
Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) //
.willReturn(definitions);
// when
final Response response = when()
.get(getVersionPrefix() + "/definitions/components?executionEngine=" + executionEngine.name()).andReturn();
// then
assertEquals(OK.value(), response.getStatusCode());
List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
});
assertEquals(expectedResults, actual.size());
assertEquals(expectedResults,
actual.stream().filter(dto -> dto.getExecutionEngines().contains(executionEngine.name())).count());
}
代码示例来源:origin: Talend/components
public void shouldFilterComponentsByTag(String tag, int expectedResults)
throws JsonParseException, JsonMappingException, IOException {
Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) //
.willReturn(definitions);
// when
final Response response = when().get(getVersionPrefix() + "/definitions/" + COMPONENT + "?tag=" + tag).andReturn();
// then
assertEquals(OK.value(), response.getStatusCode());
List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
});
assertEquals(expectedResults, actual.size());
}
代码示例来源:origin: Talend/components
public void shouldFilterComponentsByTypology(ConnectorTypology wantedTypology, int expectedResults) throws IOException {
// given
Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) //
.willReturn(definitions);
// when
final Response response = when().get(getVersionPrefix() + "/definitions/components?typology=" + wantedTypology.name())
.andReturn();
// then
assertEquals(OK.value(), response.getStatusCode());
List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
});
assertEquals(expectedResults, actual.size());
assertEquals(expectedResults, actual.stream().filter(dto -> dto.getTypologies().contains(wantedTypology.name())) // it's
// a
// source
.count());
}
代码示例来源:origin: Talend/components
@Test
public void initializeJDBCDatastoreProperties() throws java.io.IOException {
// given
SerPropertiesDto propDto = new SerPropertiesDto();
propDto.setProperties(new JDBCDatastoreProperties("").init().toSerialized());
// when
Response response = given().content(propDto).contentType(ServiceConstants.JSONIO_CONTENT_TYPE) //
.accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
.expect().statusCode(200).log().ifError() //
.post(getVersionPrefix() + "/properties/uispec");
// then
ObjectNode jdbcProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream());
// should resemble jdbc_data_store_form.json
assertNotNull(jdbcProperties.get("jsonSchema"));
assertNotNull(jdbcProperties.get("properties"));
assertNotNull(jdbcProperties.get("uiSchema"));
assertEquals("JDBCDatastore", jdbcProperties.get("properties").get("@definitionName").textValue());
}
代码示例来源:origin: org.w3/ldp-testsuite
@Test(
groups = {MUST},
description = " LDP servers must respond with a application/ld+json "
+ "representation of the requested LDP-RS when the request "
+ "includes an Accept header, unless content negotiation or "
+ "Turtle support requires a different outcome [JSON-LD].")
@SpecTest(
specRefUri = LdpTestSuite.SPEC_URI + "#ldprs-get-jsonld",
testMethod = METHOD.AUTOMATED,
approval = STATUS.WG_APPROVED)
public void testJsonLdRepresentation() throws IOException, JsonLdError {
Response response = buildBaseRequestSpecification()
.header(ACCEPT, "application/ld+json, application/json;q=0.5")
.expect()
.statusCode(isSuccessful())
.contentType(HeaderMatchers.isJsonLdCompatibleContentType())
.when()
.get(getResourceUri());
// Make sure it parses as JSON-LD.
Object json = JsonUtils.fromInputStream(response.asInputStream());
JsonLdProcessor.toRDF(json); // throws JsonLdError if not valid
}
代码示例来源:origin: Talend/components
@Test
public void getJdbcDefinition() throws java.io.IOException {
// when
Response response = given().accept(APPLICATION_JSON_UTF8_VALUE) //
.expect() //
.statusCode(200).log().ifError() //
.get(getVersionPrefix() + "/definitions/DATA_STORE");
// then
List<DefinitionDTO> definitions = mapper
.readerFor(TypeFactory.defaultInstance().constructCollectionType(List.class, DefinitionDTO.class))
.readValue(response.asInputStream());
DefinitionDTO jdbcDef = null;
for (DefinitionDTO definition : definitions) {
if (DATA_STORE_DEFINITION_NAME.equals(definition.getName())) {
jdbcDef = definition;
break;
}
}
assertNotNull(jdbcDef);
}
代码示例来源:origin: Talend/components
@Test
public void shouldNotFilterTypology() throws Exception {
// given
Map<String, ComponentDefinition> definitions = getComponentsDefinitions();
BDDMockito.given(delegate.getDefinitionsMapByType(ComponentDefinition.class)) //
.willReturn(definitions);
// when
final Response response = when().get(getVersionPrefix() + "/definitions/components").andReturn();
// then
assertEquals(OK.value(), response.getStatusCode());
List<DefinitionDTO> actual = objectMapper.readValue(response.asInputStream(), new TypeReference<List<DefinitionDTO>>() {
});
assertEquals(14, actual.size());
}
代码示例来源:origin: Talend/components
@Test
public void initializeJDBCDatasetProperties() throws java.io.IOException {
// given
SerPropertiesDto propDto = new SerPropertiesDto();
propDto.setProperties(new JDBCDatasetProperties("").init().toSerialized());
propDto.setDependencies(singletonList(new JDBCDatastoreProperties("").init().toSerialized()));
// when
Response response = given().content(propDto).contentType(ServiceConstants.JSONIO_CONTENT_TYPE) //
.accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
.expect().statusCode(200).log().ifError() //
.post(getVersionPrefix() + "/properties/uispec");
// then
ObjectNode jdbcProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream());
assertNotNull(jdbcProperties.get("jsonSchema"));
assertNotNull(jdbcProperties.get("properties"));
assertNotNull(jdbcProperties.get("uiSchema"));
assertEquals("JDBCDataset", jdbcProperties.get("properties").get("@definitionName").textValue());
}
代码示例来源:origin: Talend/components
@Test
public void getJdbcDataSetProperties() throws java.io.IOException {
// given
UiSpecsPropertiesDto properties = new UiSpecsPropertiesDto();
properties.setProperties(getJdbcDataStoreProperties());
// when
Response response = given().content(properties).contentType(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
.accept(ServiceConstants.UI_SPEC_CONTENT_TYPE) //
.expect().statusCode(200).log().ifError() //
.post(getVersionPrefix() + "/properties/dataset");
// then
ObjectNode dataSetProperties = mapper.readerFor(ObjectNode.class).readValue(response.asInputStream());
assertNotNull(dataSetProperties);
}
代码示例来源:origin: Talend/components
@Test
public void testGetDataBinary() throws java.io.IOException {
// given
UiSpecsPropertiesDto propertiesDto = new UiSpecsPropertiesDto();
propertiesDto.setProperties(getFileAsObjectNode("jdbc_data_set_properties_with_schema.json"));
propertiesDto.setDependencies(singletonList(getJdbcDataStoreProperties()));
String dataSetDefinitionName = "JDBCDataset";
// when
Response schemaResponse = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
.accept(APPLICATION_JSON_UTF8_VALUE) //
.expect().statusCode(200).log().ifError() //
.post(getVersionPrefix() + "/runtimes/schema");
Schema schema = new Schema.Parser().parse(schemaResponse.asInputStream());
Response response = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
.accept(RuntimesController.AVRO_BINARY_MIME_TYPE_OFFICIAL_INVALID) //
.expect().statusCode(200).log().ifError() //
.post(getVersionPrefix() + "/runtimes/data");
// then
GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
DecoderFactory decoderFactory = DecoderFactory.get();
Decoder decoder = decoderFactory.binaryDecoder(response.asInputStream(), null);
assertRecordsEqualsToTestValues(reader, decoder);
}
代码示例来源:origin: Talend/components
@Test
public void testGetData() throws java.io.IOException {
// given
UiSpecsPropertiesDto propertiesDto = new UiSpecsPropertiesDto();
propertiesDto.setProperties(getFileAsObjectNode("jdbc_data_set_properties_with_schema.json"));
propertiesDto.setDependencies(singletonList(getJdbcDataStoreProperties()));
String dataSetDefinitionName = "JDBCDataset";
Response schemaResponse = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
.accept(APPLICATION_JSON_UTF8_VALUE) //
.expect().statusCode(200).log().ifError() //
.post(getVersionPrefix() + "/runtimes/schema");
Schema schema = new Schema.Parser().parse(schemaResponse.asInputStream());
// when
Response response = given().content(propertiesDto).contentType(APPLICATION_JSON_UTF8_VALUE) //
.accept(RuntimesController.AVRO_JSON_MIME_TYPE_OFFICIAL_INVALID) //
.expect().statusCode(200).log().ifError() //
.post(getVersionPrefix() + "/runtimes/data");
// then
GenericDatumReader<GenericRecord> reader = new GenericDatumReader<>(schema);
DecoderFactory decoderFactory = DecoderFactory.get();
Decoder decoder = decoderFactory.jsonDecoder(schema, response.asInputStream());
assertRecordsEqualsToTestValues(reader, decoder);
}
内容来源于网络,如有侵权,请联系作者删除!