List of usage examples for org.springframework.mock.http MockHttpOutputMessage MockHttpOutputMessage
MockHttpOutputMessage
From source file:com.bs.controller.BillGenerationControllerTests.java
private String convertToJson(Object o) throws IOException { MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage(); this.mappingJackson2HttpMessageConverter.write(o, MediaType.APPLICATION_JSON, mockHttpOutputMessage); String jsonString = mockHttpOutputMessage.getBodyAsString(); log.info("JSON INPUT---------------" + jsonString); return jsonString; }
From source file:com.toptal.controller.AbstractRestTest.java
/** * Converts the given object to json string. * @param obj Given object.//from w w w . j a v a2 s.c o m * @return Json string. * @throws IOException If something goes wrong. */ protected final String json(final Object obj) throws IOException { final MockHttpOutputMessage result = new MockHttpOutputMessage(); this.converter.write(obj, MediaType.APPLICATION_JSON_UTF8, result); final String json = result.getBodyAsString(); log.debug("Json of object: {}", json); return json; }
From source file:net.eusashead.hateoas.hal.http.converter.HalHttpMessageConverterTest.java
@Test public void testWriteRepresentationXml() throws HttpMessageNotWritableException, IOException { ReadableRepresentation rep = HalTestUtils.halFromFile(BASKET_XML); HttpOutputMessage message = new MockHttpOutputMessage(); converter.write(rep, HAL_XML, message); Assert.assertEquals(HalTestUtils.stringFromFile(BASKET_XML), message.getBody().toString()); }
From source file:net.eusashead.hateoas.hal.http.converter.HalHttpMessageConverterTest.java
@Test(expected = IllegalArgumentException.class) public void testWriteOtherJson() throws HttpMessageNotWritableException, IOException { converter.write(new Object(), HAL_JSON, new MockHttpOutputMessage()); }
From source file:net.eusashead.hateoas.hal.http.converter.HalHttpMessageConverterTest.java
@Test(expected = IllegalArgumentException.class) public void testWriteOtherXml() throws HttpMessageNotWritableException, IOException { converter.write(new Object(), HAL_XML, new MockHttpOutputMessage()); }
From source file:org.oncoblocks.centromere.web.test.util.HttpMessageConverterTests.java
@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); }
From source file:com.gazbert.bxbot.rest.api.AbstractConfigControllerTest.java
String jsonify(Object objectToJsonify) throws IOException { final MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage(); this.mappingJackson2HttpMessageConverter.write(objectToJsonify, MediaType.APPLICATION_JSON, mockHttpOutputMessage);// w w w .j ava 2 s . c o m return mockHttpOutputMessage.getBodyAsString(); }
From source file:io.curly.advisor.web.ReviewResourceControllerTests.java
private String entity(ReviewEntity reviewEntity) { MockHttpOutputMessage message = new MockHttpOutputMessage(); try {// w w w . j a va 2 s .c om new MappingJackson2HttpMessageConverter().write(reviewEntity, MediaType.APPLICATION_JSON, message); } catch (IOException ignore) { } return message.getBodyAsString(); }
From source file:org.oncoblocks.centromere.web.test.util.HttpMessageConverterTests.java
@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);//from w w w. ja v a 2 s. co m System.out.println(text); // TODO }
From source file:com.gazbert.bxbot.rest.api.TestMarketConfigController.java
private String jsonify(Object objectToJsonify) throws IOException { MockHttpOutputMessage mockHttpOutputMessage = new MockHttpOutputMessage(); this.mappingJackson2HttpMessageConverter.write(objectToJsonify, MediaType.APPLICATION_JSON, mockHttpOutputMessage);// ww w . jav a 2 s . c o m return mockHttpOutputMessage.getBodyAsString(); }