-
Notifications
You must be signed in to change notification settings - Fork 888
/
MessageSanitizerMediaTypeTest.java
51 lines (42 loc) · 2 KB
/
MessageSanitizerMediaTypeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package org.jboss.resteasy.test.interception;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.core.MediaType;
import org.jboss.resteasy.core.Headers;
import org.jboss.resteasy.core.interception.ContainerResponseContextImpl;
import org.jboss.resteasy.plugins.interceptors.encoding.MessageSanitizerContainerResponseFilter;
import org.jboss.resteasy.specimpl.BuiltResponse;
import org.jboss.resteasy.util.HttpResponseCodes;
import org.junit.Assert;
import org.junit.Test;
/**
* @tpSubChapter Providers - MessageSanitizerContainerResponseFilter
* @tpChapter Unit tests
* @tpTestCaseDetails Regression test for RESTEASY-2033
* @tpSince RESTEasy 4.0.0
*/
public class MessageSanitizerMediaTypeTest {
static private final String input = "<html <\"abc\" 'xyz'>/>";
static private final String output = "<html &lt;"abc" 'xyz'&gt;/>";
public static class TestContainerResponseContext extends ContainerResponseContextImpl {
public TestContainerResponseContext(BuiltResponse builtResponse) {
super(null, null, builtResponse, null, null, null, null);
}
}
@Test
public void testMessageSanitizerText() throws Exception {
doTestMessageSanitizerMediaType("text/html");
}
@Test
public void testMessageSanitizerMediaType() throws Exception {
doTestMessageSanitizerMediaType(MediaType.TEXT_HTML_TYPE);
}
void doTestMessageSanitizerMediaType(Object mediaType) throws Exception {
Headers<Object> headers = new Headers<Object>();
headers.add("Content-Type", mediaType);
BuiltResponse response = new BuiltResponse(HttpResponseCodes.SC_BAD_REQUEST, "", headers, input, null);
ContainerResponseContext responseContext = new TestContainerResponseContext(response);
MessageSanitizerContainerResponseFilter filter = new MessageSanitizerContainerResponseFilter();
filter.filter(null, responseContext);
Assert.assertEquals(output, responseContext.getEntity());
}
}