本文整理汇总了Java中org.springframework.mock.http.MockHttpOutputMessage类的典型用法代码示例。如果您正苦于以下问题:Java MockHttpOutputMessage类的具体用法?Java MockHttpOutputMessage怎么用?Java MockHttpOutputMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MockHttpOutputMessage类属于org.springframework.mock.http包,在下文中一共展示了MockHttpOutputMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeToJsonWithFieldFilter
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@Test
public void writeToJsonWithFieldFilter() throws Exception {
List<EntrezGene> genes = EntrezGene.createDummyData();
Set<String> fields = new HashSet<>();
fields.add("primaryGeneSymbol");
ResponseEnvelope envelope = new ResponseEnvelope(genes, fields, new HashSet<>());
Assert.isTrue(jsonConverter.canWrite(envelope.getClass(), MediaType.APPLICATION_JSON));
MockHttpOutputMessage message = new MockHttpOutputMessage();
jsonConverter.write(envelope, MediaType.APPLICATION_JSON, message);
Object document = Configuration.defaultConfiguration()
.jsonProvider().parse(message.getBodyAsString());
Assert.isTrue(!((List<String>) JsonPath.read(document, "$")).isEmpty());
Assert.isTrue(((List<String>) JsonPath.read(document, "$")).size() == 5);
Map<String,Object> gene = JsonPath.read(document, "$[0]");
Assert.isTrue(!gene.containsKey("entrezGeneId"));
Assert.isTrue(!gene.containsKey("aliases"));
Assert.isTrue(!gene.containsKey("attributes"));
Assert.isTrue(gene.containsKey("primaryGeneSymbol"));
Assert.isTrue(gene.get("primaryGeneSymbol").equals("GeneA"));
}
示例2: writeToJsonWithExcludeFilter
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@Test
public void writeToJsonWithExcludeFilter() throws Exception {
List<EntrezGene> genes = EntrezGene.createDummyData();
Set<String> exclude = new HashSet<>();
exclude.add("primaryGeneSymbol");
ResponseEnvelope envelope = new ResponseEnvelope(genes, new HashSet<>(), exclude);
Assert.isTrue(jsonConverter.canWrite(envelope.getClass(), MediaType.APPLICATION_JSON));
MockHttpOutputMessage message = new MockHttpOutputMessage();
jsonConverter.write(envelope, MediaType.APPLICATION_JSON, message);
Object document = Configuration.defaultConfiguration()
.jsonProvider().parse(message.getBodyAsString());
Assert.isTrue(!((List<String>) JsonPath.read(document, "$")).isEmpty());
Assert.isTrue(((List<String>) JsonPath.read(document, "$")).size() == 5);
Map<String,Object> gene = JsonPath.read(document, "$[0]");
Assert.isTrue(gene.containsKey("entrezGeneId"));
Assert.isTrue(gene.containsKey("aliases"));
Assert.isTrue(gene.containsKey("attributes"));
Assert.isTrue(!gene.containsKey("primaryGeneSymbol"));
Assert.isTrue(((Integer) gene.get("entrezGeneId")) == 1);
}
示例3: json
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected <T extends Object> String json(T entity) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
jsonConverter.write(
entity, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例4: toJson
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
/**
* Map an object to JSON
*
* @param o object to map
* @return JSON result
*/
protected String toJson(Object o) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
//noinspection unchecked
mappingJackson2HttpMessageConverter.write(
o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例5: json
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected String json(Object o) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
this.mappingJackson2HttpMessageConverter.write(
o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例6: json
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
protected String json(Object o) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
this.mappingJackson2HttpMessageConverter.write(
o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例7: json
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected String json(Object o) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
HttpMessageConverter converter = o instanceof String ? stringHttpMessageConverter : mappingJackson2HttpMessageConverter;
converter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例8: writeToJsonNoFilter
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@Test
public void writeToJsonNoFilter() throws Exception {
List<EntrezGene> genes = EntrezGene.createDummyData();
ResponseEnvelope envelope = new ResponseEnvelope(genes);
Assert.isTrue(jsonConverter.canWrite(envelope.getClass(), MediaType.APPLICATION_JSON));
MockHttpOutputMessage message = new MockHttpOutputMessage();
jsonConverter.write(envelope, MediaType.APPLICATION_JSON, message);
Object document = Configuration.defaultConfiguration()
.jsonProvider().parse(message.getBodyAsString());
Assert.isTrue(!((List<String>) JsonPath.read(document, "$")).isEmpty());
Assert.isTrue(((List<String>) JsonPath.read(document, "$")).size() == 5);
Assert.notNull(JsonPath.read(document, "$[0].entrezGeneId"));
Assert.isTrue( (Integer) JsonPath.read(document, "$[0].entrezGeneId") == 1);
}
示例9: writeToTextNoFilter
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@Test
public void writeToTextNoFilter() throws Exception {
List<EntrezGene> genes = EntrezGene.createDummyData();
ResponseEnvelope envelope = new ResponseEnvelope(genes);
Assert.isTrue(textConverter.canWrite(envelope.getClass(), textMediaType));
MockHttpOutputMessage message = new MockHttpOutputMessage();
textConverter.write(envelope, textMediaType, message);
String text = message.getBodyAsString();
Assert.notNull(text);
System.out.println(text);
// TODO
}
示例10: json
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
protected String json(Object o) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
this.mappingJackson2HttpMessageConverter.write(
o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例11: json
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected String json(Object o) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
this.mappingJackson2HttpMessageConverter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例12: jsonify
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected String jsonify(Object objectToJsonify) throws IOException {
final MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
mappingJackson2HttpMessageConverter.write(objectToJsonify, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例13: asJsonString
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@SneakyThrows
public String asJsonString(Object o) {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
messageConverter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例14: json
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
static public String json(MappingJackson2HttpMessageConverter mapping, Object o) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
mapping.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}
示例15: toJsonString
import org.springframework.mock.http.MockHttpOutputMessage; //导入依赖的package包/类
@SuppressWarnings("unchecked")
protected String toJsonString(Object obj) throws IOException {
MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage();
this.mappingJackson2HttpMessageConverter.write(obj, MediaType.APPLICATION_JSON, mockHttpOutputMessage);
return mockHttpOutputMessage.getBodyAsString();
}