Example usage for org.springframework.mock.http MockHttpInputMessage MockHttpInputMessage

List of usage examples for org.springframework.mock.http MockHttpInputMessage MockHttpInputMessage

Introduction

In this page you can find the example usage for org.springframework.mock.http MockHttpInputMessage MockHttpInputMessage.

Prototype

public MockHttpInputMessage(InputStream body) 

Source Link

Usage

From source file:net.eusashead.hateoas.hal.http.converter.module.HalHttpMessageConverterModuleTest.java

@Test
public void testReadWithModule() throws IOException {

    // Should be unable to read without module
    Assert.assertFalse(converter.canRead(Foo.class, HalHttpMessageConverter.HAL_JSON));

    // Add the module
    addModule();/*from  ww  w  .  ja  v  a  2  s .c o  m*/

    // Should be able to read
    Assert.assertTrue(converter.canRead(Foo.class, HalHttpMessageConverter.HAL_JSON));

    // Create a test message and read it
    InputStream is = new FileInputStream(new File("src/test/resources/foo.json"));
    HttpInputMessage inputMessage = new MockHttpInputMessage(is);
    Object obj = converter.read(Foo.class, inputMessage);
    Assert.assertNotNull(obj);
    Assert.assertEquals(Foo.class, obj.getClass());

}

From source file:net.eusashead.hateoas.hal.http.converter.HalHttpMessageConverterTest.java

@Test
public void testReadRepresentationJson() throws HttpMessageNotWritableException, IOException {

    // Create a test input message
    InputStream is = new FileInputStream(new File(BASKET_JSON));
    HttpInputMessage message = new MockHttpInputMessage(is);
    Object object = converter.read(Representation.class, message);

    // Compare converted with expected
    ReadableRepresentation rep = HalTestUtils.halFromFile(BASKET_JSON);
    Assert.assertEquals(rep, object);/*from   w ww . ja  va2  s.  co  m*/
}

From source file:net.eusashead.hateoas.hal.http.converter.HalHttpMessageConverterTest.java

@Test
public void testReadRepresentationXml() throws HttpMessageNotWritableException, IOException {

    // Create a test input message
    InputStream is = new FileInputStream(new File(BASKET_XML));
    HttpInputMessage message = new MockHttpInputMessage(is);
    Object object = converter.read(Representation.class, message);

    // Compare converted with expected
    ReadableRepresentation rep = HalTestUtils.halFromFile(BASKET_XML);
    Assert.assertEquals(rep, object);/*w  ww  . j  a  v a2  s  .co m*/
}

From source file:org.hobsoft.symmetry.spring.SymmetryHttpMessageConverterTest.java

@Test
public void readWithComponentThrowsException() throws IOException {
    Reflector<DummyComponent> reflector = mockReflector(DummyComponent.class, someContentType());
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(new byte[0]);

    thrown.expect(HttpMessageNotReadableException.class);
    thrown.expectMessage("SymmetryHttpMessageConverter cannot read components");

    newConverter(reflector).read(DummyComponent.class, inputMessage);
}

From source file:net.eusashead.hateoas.hal.http.converter.HalHttpMessageConverterTest.java

@Test(expected = IllegalArgumentException.class)
public void testReadOtherJson() throws HttpMessageNotWritableException, IOException {
    InputStream is = new FileInputStream(new File(BASKET_JSON));
    HttpInputMessage message = new MockHttpInputMessage(is);
    converter.read(Object.class, message);
}

From source file:net.eusashead.hateoas.hal.http.converter.HalHttpMessageConverterTest.java

@Test(expected = IllegalArgumentException.class)
public void testReadOtherXml() throws HttpMessageNotWritableException, IOException {
    InputStream is = new FileInputStream(new File(BASKET_XML));
    HttpInputMessage message = new MockHttpInputMessage(is);
    converter.read(Object.class, message);
}

From source file:org.thingsboard.server.controller.AbstractControllerTest.java

@SuppressWarnings("unchecked")
protected <T> T readResponse(ResultActions result, Class<T> responseClass) throws Exception {
    byte[] content = result.andReturn().getResponse().getContentAsByteArray();
    MockHttpInputMessage mockHttpInputMessage = new MockHttpInputMessage(content);
    HttpMessageConverter converter = responseClass.equals(String.class) ? stringHttpMessageConverter
            : mappingJackson2HttpMessageConverter;
    return (T) converter.read(responseClass, mockHttpInputMessage);
}