Here are the examples of the java api org.springframework.http.MockHttpInputMessage taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
138 Examples
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readValidXmlWithUnknownProperty() throws IOException {
String body = "<MyBean><string>string</string><unknownProperty>value</unknownProperty></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
converter.read(MyBean.clreplaced, inputMessage);
// replacedert no HttpMessageNotReadableException is thrown
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readWithXmlBomb() throws IOException {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String body = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<MyBean>&lol9;</MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> this.converter.read(MyBean.clreplaced, inputMessage));
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void read() throws IOException {
String body = "<MyBean>" + "<string>Foo</string>" + "<number>42</number>" + "<fraction>42.0</fraction>" + "<array><array>Foo</array>" + "<array>Bar</array></array>" + "<bool>true</bool>" + "<bytes>AQI=</bytes></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
MyBean result = (MyBean) converter.read(MyBean.clreplaced, inputMessage);
replacedertEquals("Foo", result.getString());
replacedertEquals(42, result.getNumber());
replacedertEquals(42F, result.getFraction(), 0F);
replacedertArrayEquals(new String[] { "Foo", "Bar" }, result.getArray());
replacedertTrue(result.isBool());
replacedertArrayEquals(new byte[] { 0x1, 0x2 }, result.getBytes());
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readInvalidXml() throws IOException {
String body = "FooBar";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> converter.read(MyBean.clreplaced, inputMessage));
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readWithExternalReference() throws IOException {
String body = "<!DOCTYPE MyBean SYSTEM \"https://192.168.28.42/1.jsp\" [" + " <!ELEMENT root ANY >\n" + " <!ENreplacedY ext SYSTEM \"" + new ClreplacedPathResource("external.txt", getClreplaced()).getURI() + "\" >]><MyBean><string>&ext;</string></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> this.converter.read(MyBean.clreplaced, inputMessage));
}
19
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testXmlBomb() throws Exception {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String content = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<list><rootElement><external>&lol9;</external></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> this.converter.read(this.rootElementListType, null, inputMessage)).withMessageContaining("\"lol9\"");
}
19
View Source File : MappingJackson2SmileHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void read() throws IOException {
MyBean body = new MyBean();
body.setString("Foo");
body.setNumber(42);
body.setFraction(42F);
body.setArray(new String[] { "Foo", "Bar" });
body.setBool(true);
body.setBytes(new byte[] { 0x1, 0x2 });
MockHttpInputMessage inputMessage = new MockHttpInputMessage(mapper.writeValueAsBytes(body));
inputMessage.getHeaders().setContentType(new MediaType("application", "x-jackson-smile"));
MyBean result = (MyBean) converter.read(MyBean.clreplaced, inputMessage);
replacedertEquals("Foo", result.getString());
replacedertEquals(42, result.getNumber());
replacedertEquals(42F, result.getFraction(), 0F);
replacedertArrayEquals(new String[] { "Foo", "Bar" }, result.getArray());
replacedertTrue(result.isBool());
replacedertArrayEquals(new byte[] { 0x1, 0x2 }, result.getBytes());
}
19
View Source File : ByteArrayHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void read() throws IOException {
byte[] body = new byte[] { 0x1, 0x2 };
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(new MediaType("application", "octet-stream"));
byte[] result = converter.read(byte[].clreplaced, inputMessage);
replacedertArrayEquals("Invalid result", body, result);
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Test
public void readInvalidXml() throws IOException {
String body = "FooBar";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
this.thrown.expect(HttpMessageNotReadableException.clreplaced);
converter.read(MyBean.clreplaced, inputMessage);
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Test
public void readWithXmlBomb() throws IOException {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String body = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<MyBean>&lol9;</MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
this.thrown.expect(HttpMessageNotReadableException.clreplaced);
this.converter.read(MyBean.clreplaced, inputMessage);
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Test
public void readWithExternalReference() throws IOException {
String body = "<!DOCTYPE MyBean SYSTEM \"http://192.168.28.42/1.jsp\" [" + " <!ELEMENT root ANY >\n" + " <!ENreplacedY ext SYSTEM \"" + new ClreplacedPathResource("external.txt", getClreplaced()).getURI() + "\" >]><MyBean><string>&ext;</string></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
this.thrown.expect(HttpMessageNotReadableException.clreplaced);
this.converter.read(MyBean.clreplaced, inputMessage);
}
19
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Test
public void testXmlBomb() throws Exception {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String content = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<list><rootElement><external>&lol9;</external></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
this.thrown.expect(HttpMessageNotReadableException.clreplaced);
this.thrown.expectMessage("\"lol9\"");
this.converter.read(this.rootElementListType, null, inputMessage);
}
19
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test(expected = HttpMessageNotReadableException.clreplaced)
public void readInvalidXml() throws IOException {
String body = "FooBar";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
converter.read(MyBean.clreplaced, inputMessage);
}
19
View Source File : StringHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void read() throws IOException {
String body = "Hello World";
Charset charset = Charset.forName("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(charset));
inputMessage.getHeaders().setContentType(new MediaType("text", "plain", charset));
String result = converter.read(String.clreplaced, inputMessage);
replacedertEquals("Invalid result", body, result);
}
18
View Source File : SourceHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readDomSourceWithXmlBomb() throws Exception {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String content = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<root>&lol9;</root>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> this.converter.read(DOMSource.clreplaced, inputMessage)).withMessageContaining("DOCTYPE");
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readXmlType() throws Exception {
byte[] body = "<foo s=\"Hello World\"/>".getBytes("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
Type result = (Type) converter.read(Type.clreplaced, inputMessage);
replacedertEquals("Invalid result", "Hello World", result.s);
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void customizeUnmarshaller() throws Exception {
byte[] body = "<myRootElement><element>a|||b</element></myRootElement>".getBytes("UTF-8");
MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter();
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
MyRootElement result = (MyRootElement) myConverter.read(MyRootElement.clreplaced, inputMessage);
replacedertEquals("a", result.getElement().getField1());
replacedertEquals("b", result.getElement().getField2());
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readXmlRootElement() throws Exception {
byte[] body = "<rootElement><type s=\"Hello World\"/></rootElement>".getBytes("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
RootElement result = (RootElement) converter.read(RootElement.clreplaced, inputMessage);
replacedertEquals("Invalid result", "Hello World", result.type.s);
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void testXmlBomb() throws Exception {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String content = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<rootElement><external>&lol9;</external></rootElement>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> this.converter.read(RootElement.clreplaced, inputMessage)).withMessageContaining("DOCTYPE");
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readXmlRootElementSubclreplaced() throws Exception {
byte[] body = "<rootElement><type s=\"Hello World\"/></rootElement>".getBytes("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
RootElementSubclreplaced result = (RootElementSubclreplaced) converter.read(RootElementSubclreplaced.clreplaced, inputMessage);
replacedertEquals("Invalid result", "Hello World", result.getType().s);
}
18
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementSet() throws Exception {
String content = "<set><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></set>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
Set<RootElement> result = (Set<RootElement>) converter.read(rootElementSetType, null, inputMessage);
replacedertEquals("Invalid result", 2, result.size());
replacedertTrue("Invalid result", result.contains(new RootElement("1")));
replacedertTrue("Invalid result", result.contains(new RootElement("2")));
}
18
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementList() throws Exception {
String content = "<list><rootElement><type s=\"1\"/></rootElement><rootElement><type s=\"2\"/></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
List<RootElement> result = (List<RootElement>) converter.read(rootElementListType, null, inputMessage);
replacedertEquals("Invalid result", 2, result.size());
replacedertEquals("Invalid result", "1", result.get(0).type.s);
replacedertEquals("Invalid result", "2", result.get(1).type.s);
}
18
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
@SuppressWarnings("unchecked")
public void readXmlTypeList() throws Exception {
String content = "<list><foo s=\"1\"/><bar s=\"2\"/></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
List<TestType> result = (List<TestType>) converter.read(typeListType, null, inputMessage);
replacedertEquals("Invalid result", 2, result.size());
replacedertEquals("Invalid result", "1", result.get(0).s);
replacedertEquals("Invalid result", "2", result.get(1).s);
}
18
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementExternalEnreplacedyEnabled() throws Exception {
Resource external = new ClreplacedPathResource("external.txt", getClreplaced());
String content = "<!DOCTYPE root [" + " <!ELEMENT external ANY >\n" + " <!ENreplacedY ext SYSTEM \"" + external.getURI() + "\" >]>" + " <list><rootElement><type s=\"1\"/><external>&ext;</external></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
Jaxb2CollectionHttpMessageConverter<?> c = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() {
@Override
protected XMLInputFactory createXmlInputFactory() {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENreplacedY_REFERENCES, true);
return inputFactory;
}
};
Collection<RootElement> result = c.read(rootElementListType, null, inputMessage);
replacedertEquals(1, result.size());
replacedertEquals("Foo Bar", result.iterator().next().external);
}
18
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementExternalEnreplacedyDisabled() throws Exception {
Resource external = new ClreplacedPathResource("external.txt", getClreplaced());
String content = "<!DOCTYPE root [" + " <!ELEMENT external ANY >\n" + " <!ENreplacedY ext SYSTEM \"" + external.getURI() + "\" >]>" + " <list><rootElement><type s=\"1\"/><external>&ext;</external></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
converter = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() {
@Override
protected XMLInputFactory createXmlInputFactory() {
XMLInputFactory inputFactory = super.createXmlInputFactory();
inputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
return inputFactory;
}
};
try {
Collection<RootElement> result = converter.read(rootElementListType, null, inputMessage);
replacedertEquals(1, result.size());
replacedertEquals("", result.iterator().next().external);
} catch (HttpMessageNotReadableException ex) {
// Some parsers raise an exception
}
}
18
View Source File : Jaxb2CollectionHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
@SuppressWarnings("unchecked")
public void readXmlTypeSet() throws Exception {
String content = "<set><foo s=\"1\"/><bar s=\"2\"/></set>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
Set<TestType> result = (Set<TestType>) converter.read(typeSetType, null, inputMessage);
replacedertEquals("Invalid result", 2, result.size());
replacedertTrue("Invalid result", result.contains(new TestType("1")));
replacedertTrue("Invalid result", result.contains(new TestType("2")));
}
18
View Source File : StringHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void read() throws IOException {
String body = "Hello World";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(TEXT_PLAIN_UTF_8);
String result = this.converter.read(String.clreplaced, inputMessage);
replacedertEquals("Invalid result", body, result);
}
18
View Source File : ResourceHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
// SPR-14882
@Test
public void shouldNotReadInputStreamResource() throws IOException {
ResourceHttpMessageConverter noStreamConverter = new ResourceHttpMessageConverter(false);
try (InputStream body = getClreplaced().getResourcereplacedtream("logo.jpg")) {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(MediaType.IMAGE_JPEG);
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> noStreamConverter.read(InputStreamResource.clreplaced, inputMessage));
}
}
18
View Source File : ResourceHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
// SPR-13443
@Test
public void shouldReadInputStreamResource() throws IOException {
try (InputStream body = getClreplaced().getResourcereplacedtream("logo.jpg")) {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(MediaType.IMAGE_JPEG);
inputMessage.getHeaders().setContentDisposition(ContentDisposition.builder("attachment").filename("yourlogo.jpg").build());
Resource actualResource = converter.read(InputStreamResource.clreplaced, inputMessage);
replacedertThat(actualResource, instanceOf(InputStreamResource.clreplaced));
replacedertThat(actualResource.getInputStream(), is(body));
replacedertEquals("yourlogo.jpg", actualResource.getFilename());
}
}
18
View Source File : ProtobufJsonFormatHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readNoContentType() throws IOException {
byte[] body = this.testMsg.toByteArray();
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
Message result = this.converter.read(Msg.clreplaced, inputMessage);
replacedertEquals(this.testMsg, result);
}
18
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void read() throws IOException {
String body = "<MyBean>" + "<string>Foo</string>" + "<number>42</number>" + "<fraction>42.0</fraction>" + "<array><array>Foo</array>" + "<array>Bar</array></array>" + "<bool>true</bool>" + "<bytes>AQI=</bytes></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
MyBean result = (MyBean) converter.read(MyBean.clreplaced, inputMessage);
replacedertThat(result.getString()).isEqualTo("Foo");
replacedertThat(result.getNumber()).isEqualTo(42);
replacedertThat(result.getFraction()).isCloseTo(42F, within(0F));
replacedertThat(result.getArray()).isEqualTo(new String[] { "Foo", "Bar" });
replacedertThat(result.isBool()).isTrue();
replacedertThat(result.getBytes()).isEqualTo(new byte[] { 0x1, 0x2 });
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readXmlType() throws Exception {
byte[] body = "<foo s=\"Hello World\"/>".getBytes("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
Type result = (Type) converter.read(Type.clreplaced, inputMessage);
replacedertThat(result.s).as("Invalid result").isEqualTo("Hello World");
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readXmlRootElement() throws Exception {
byte[] body = "<rootElement><type s=\"Hello World\"/></rootElement>".getBytes("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
RootElement result = (RootElement) converter.read(RootElement.clreplaced, inputMessage);
replacedertThat(result.type.s).as("Invalid result").isEqualTo("Hello World");
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void customizeUnmarshaller() throws Exception {
byte[] body = "<myRootElement><element>a|||b</element></myRootElement>".getBytes("UTF-8");
MyJaxb2RootElementHttpMessageConverter myConverter = new MyJaxb2RootElementHttpMessageConverter();
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
MyRootElement result = (MyRootElement) myConverter.read(MyRootElement.clreplaced, inputMessage);
replacedertThat(result.getElement().getField1()).isEqualTo("a");
replacedertThat(result.getElement().getField2()).isEqualTo("b");
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readXmlRootElementSubclreplaced() throws Exception {
byte[] body = "<rootElement><type s=\"Hello World\"/></rootElement>".getBytes("UTF-8");
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
RootElementSubclreplaced result = (RootElementSubclreplaced) converter.read(RootElementSubclreplaced.clreplaced, inputMessage);
replacedertThat(result.getType().s).as("Invalid result").isEqualTo("Hello World");
}
18
View Source File : StringHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void read() throws IOException {
String body = "Hello World";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(TEXT_PLAIN_UTF_8);
String result = this.converter.read(String.clreplaced, inputMessage);
replacedertThat(result).as("Invalid result").isEqualTo(body);
}
18
View Source File : StringHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
// gh-24123
@Test
public void readJson() throws IOException {
String body = "{\"result\":\"\u0414\u0410\"}";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.UTF_8));
inputMessage.getHeaders().setContentType(MediaType.APPLICATION_JSON);
String result = this.converter.read(String.clreplaced, inputMessage);
replacedertThat(result).as("Invalid result").isEqualTo(body);
}
18
View Source File : MappingJackson2SmileHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void read() throws IOException {
MyBean body = new MyBean();
body.setString("Foo");
body.setNumber(42);
body.setFraction(42F);
body.setArray(new String[] { "Foo", "Bar" });
body.setBool(true);
body.setBytes(new byte[] { 0x1, 0x2 });
MockHttpInputMessage inputMessage = new MockHttpInputMessage(mapper.writeValueAsBytes(body));
inputMessage.getHeaders().setContentType(new MediaType("application", "x-jackson-smile"));
MyBean result = (MyBean) converter.read(MyBean.clreplaced, inputMessage);
replacedertThat(result.getString()).isEqualTo("Foo");
replacedertThat(result.getNumber()).isEqualTo(42);
replacedertThat(result.getFraction()).isCloseTo(42F, within(0F));
replacedertThat(result.getArray()).isEqualTo(new String[] { "Foo", "Bar" });
replacedertThat(result.isBool()).isTrue();
replacedertThat(result.getBytes()).isEqualTo(new byte[] { 0x1, 0x2 });
}
18
View Source File : ProtobufJsonFormatHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readNoContentType() throws IOException {
byte[] body = this.testMsg.toByteArray();
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
Message result = this.converter.read(Msg.clreplaced, inputMessage);
replacedertThat(result).isEqualTo(this.testMsg);
}
18
View Source File : JsonbHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readTyped() throws IOException {
String body = "{\"bytes\":[1,2],\"array\":[\"Foo\",\"Bar\"]," + "\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
MyBean result = (MyBean) this.converter.read(MyBean.clreplaced, inputMessage);
replacedertThat(result.getString()).isEqualTo("Foo");
replacedertThat(result.getNumber()).isEqualTo(42);
replacedertThat(result.getFraction()).isCloseTo(42F, within(0F));
replacedertThat(result.getArray()).isEqualTo(new String[] { "Foo", "Bar" });
replacedertThat(result.isBool()).isTrue();
replacedertThat(result.getBytes()).isEqualTo(new byte[] { 0x1, 0x2 });
}
18
View Source File : JsonbHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void readInvalidJson() throws IOException {
String body = "FooBar";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
replacedertThatExceptionOfType(HttpMessageNotReadableException.clreplaced).isThrownBy(() -> this.converter.read(MyBean.clreplaced, inputMessage));
}
18
View Source File : ByteArrayHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : SourceHot
License : Apache License 2.0
Project Creator : SourceHot
@Test
public void read() throws IOException {
byte[] body = new byte[] { 0x1, 0x2 };
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(new MediaType("application", "octet-stream"));
byte[] result = converter.read(byte[].clreplaced, inputMessage);
replacedertThat(result).as("Invalid result").isEqualTo(body);
}
18
View Source File : SourceHttpMessageConverterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Test
public void readDomSourceWithXmlBomb() throws Exception {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String content = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<root>&lol9;</root>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
this.thrown.expect(HttpMessageNotReadableException.clreplaced);
this.thrown.expectMessage("DOCTYPE");
this.converter.read(DOMSource.clreplaced, inputMessage);
}
18
View Source File : Jaxb2RootElementHttpMessageConverterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
@Test
public void testXmlBomb() throws Exception {
// https://en.wikipedia.org/wiki/Billion_laughs
// https://msdn.microsoft.com/en-us/magazine/ee335713.aspx
String content = "<?xml version=\"1.0\"?>\n" + "<!DOCTYPE lolz [\n" + " <!ENreplacedY lol \"lol\">\n" + " <!ELEMENT lolz (#PCDATA)>\n" + " <!ENreplacedY lol1 \"&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;&lol;\">\n" + " <!ENreplacedY lol2 \"&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;&lol1;\">\n" + " <!ENreplacedY lol3 \"&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;&lol2;\">\n" + " <!ENreplacedY lol4 \"&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;&lol3;\">\n" + " <!ENreplacedY lol5 \"&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;&lol4;\">\n" + " <!ENreplacedY lol6 \"&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;&lol5;\">\n" + " <!ENreplacedY lol7 \"&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;&lol6;\">\n" + " <!ENreplacedY lol8 \"&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;&lol7;\">\n" + " <!ENreplacedY lol9 \"&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;&lol8;\">\n" + "]>\n" + "<rootElement><external>&lol9;</external></rootElement>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
this.thrown.expect(HttpMessageNotReadableException.clreplaced);
this.thrown.expectMessage("DOCTYPE");
this.converter.read(RootElement.clreplaced, inputMessage);
}
18
View Source File : ResourceHttpMessageConverterTests.java
License : MIT License
Project Creator : mindcarver
License : MIT License
Project Creator : mindcarver
// SPR-14882
@Test
public void shouldNotReadInputStreamResource() throws IOException {
ResourceHttpMessageConverter noStreamConverter = new ResourceHttpMessageConverter(false);
try (InputStream body = getClreplaced().getResourcereplacedtream("logo.jpg")) {
this.thrown.expect(HttpMessageNotReadableException.clreplaced);
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(MediaType.IMAGE_JPEG);
noStreamConverter.read(InputStreamResource.clreplaced, inputMessage);
}
}
18
View Source File : MappingJackson2XmlHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void read() throws IOException {
String body = "<MyBean><string>Foo</string><number>42</number><fraction>42.0</fraction><array><array>Foo</array><array>Bar</array></array><bool>true</bool><bytes>AQI=</bytes></MyBean>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
MyBean result = (MyBean) converter.read(MyBean.clreplaced, inputMessage);
replacedertEquals("Foo", result.getString());
replacedertEquals(42, result.getNumber());
replacedertEquals(42F, result.getFraction(), 0F);
replacedertArrayEquals(new String[] { "Foo", "Bar" }, result.getArray());
replacedertTrue(result.isBool());
replacedertArrayEquals(new byte[] { 0x1, 0x2 }, result.getBytes());
}
18
View Source File : ResourceHttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
// SPR-13443
@Test
public void readWithInputStreamResource() throws IOException {
try (InputStream body = getClreplaced().getResourcereplacedtream("logo.jpg")) {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body);
inputMessage.getHeaders().setContentType(MediaType.IMAGE_JPEG);
Resource actualResource = converter.read(InputStreamResource.clreplaced, inputMessage);
replacedertThat(actualResource, instanceOf(InputStreamResource.clreplaced));
replacedertThat(actualResource.getInputStream(), is(body));
}
}
18
View Source File : MappingJackson2HttpMessageConverterTests.java
License : Apache License 2.0
Project Creator : langtianya
License : Apache License 2.0
Project Creator : langtianya
@Test
public void readTyped() throws IOException {
String body = "{\"bytes\":\"AQI=\",\"array\":[\"Foo\",\"Bar\"],\"number\":42,\"string\":\"Foo\",\"bool\":true,\"fraction\":42.0}";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "json"));
MyBean result = (MyBean) converter.read(MyBean.clreplaced, inputMessage);
replacedertEquals("Foo", result.getString());
replacedertEquals(42, result.getNumber());
replacedertEquals(42F, result.getFraction(), 0F);
replacedertArrayEquals(new String[] { "Foo", "Bar" }, result.getArray());
replacedertTrue(result.isBool());
replacedertArrayEquals(new byte[] { 0x1, 0x2 }, result.getBytes());
}
17
View Source File : SourceHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void readSource() throws Exception {
MockHttpInputMessage inputMessage = new MockHttpInputMessage(BODY.getBytes("UTF-8"));
inputMessage.getHeaders().setContentType(new MediaType("application", "xml"));
converter.read(Source.clreplaced, inputMessage);
}
17
View Source File : MarshallingHttpMessageConverterTests.java
License : MIT License
Project Creator : Vip-Augus
License : MIT License
Project Creator : Vip-Augus
@Test
public void read() throws Exception {
String body = "<root>Hello World</root>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes("UTF-8"));
Unmarshaller unmarshaller = mock(Unmarshaller.clreplaced);
given(unmarshaller.unmarshal(isA(StreamSource.clreplaced))).willReturn(body);
MarshallingHttpMessageConverter converter = new MarshallingHttpMessageConverter();
converter.setUnmarshaller(unmarshaller);
String result = (String) converter.read(Object.clreplaced, inputMessage);
replacedertEquals("Invalid result", body, result);
}
See More Examples