当前位置: 首页>>代码示例>>Java>>正文


Java MockHttpOutputMessage类代码示例

本文整理汇总了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"));
}
 
开发者ID:oncoblocks,项目名称:centromere,代码行数:21,代码来源:HttpMessageConverterTests.java

示例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);
}
 
开发者ID:oncoblocks,项目名称:centromere,代码行数:21,代码来源:HttpMessageConverterTests.java

示例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();
   }
 
开发者ID:daflockinger,项目名称:poppynotes,代码行数:8,代码来源:BaseControllerTest.java

示例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();
}
 
开发者ID:resourcepool,项目名称:dashboard,代码行数:14,代码来源:AbstractControllerTest.java

示例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();
   }
 
开发者ID:simbest,项目名称:simbest-cores,代码行数:8,代码来源:AbstractControllerTester.java

示例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();
}
 
开发者ID:bulktrade,项目名称:SMSC,代码行数:8,代码来源:AbstractSpringMVCTest.java

示例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();
}
 
开发者ID:thingsboard,项目名称:thingsboard,代码行数:9,代码来源:AbstractControllerTest.java

示例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);
}
 
开发者ID:oncoblocks,项目名称:centromere,代码行数:15,代码来源:HttpMessageConverterTests.java

示例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
}
 
开发者ID:oncoblocks,项目名称:centromere,代码行数:13,代码来源:HttpMessageConverterTests.java

示例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();
}
 
开发者ID:ProjectIndoor,项目名称:projectindoorweb,代码行数:7,代码来源:ProjectControllerTest.java

示例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();
}
 
开发者ID:sbouclier,项目名称:java-rest-books,代码行数:7,代码来源:BookControllerTest.java

示例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();
}
 
开发者ID:gazbert,项目名称:bxbot-ui-server,代码行数:7,代码来源:AbstractControllerTest.java

示例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();
}
 
开发者ID:tsypuk,项目名称:springrestdoc,代码行数:7,代码来源:TestDataGenerator.java

示例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();
}
 
开发者ID:Orange-OpenSource,项目名称:fiware-ngsi2-api,代码行数:6,代码来源:Utils.java

示例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();
   }
 
开发者ID:Apress,项目名称:pro-spring-boot,代码行数:7,代码来源:SprintBootWebApplicationTests.java


注:本文中的org.springframework.mock.http.MockHttpOutputMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。