Issue #4334 - Enhancing JSON Test
Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>
This commit is contained in:
parent
ba1fe2826d
commit
217602e97f
|
@ -19,7 +19,9 @@
|
||||||
package org.eclipse.jetty.server;
|
package org.eclipse.jetty.server;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import javax.servlet.DispatcherType;
|
import javax.servlet.DispatcherType;
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
|
@ -42,10 +44,12 @@ import static org.hamcrest.MatcherAssert.assertThat;
|
||||||
import static org.hamcrest.Matchers.anyOf;
|
import static org.hamcrest.Matchers.anyOf;
|
||||||
import static org.hamcrest.Matchers.containsString;
|
import static org.hamcrest.Matchers.containsString;
|
||||||
import static org.hamcrest.Matchers.greaterThan;
|
import static org.hamcrest.Matchers.greaterThan;
|
||||||
|
import static org.hamcrest.Matchers.instanceOf;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.Matchers.is;
|
||||||
import static org.hamcrest.Matchers.not;
|
import static org.hamcrest.Matchers.not;
|
||||||
import static org.hamcrest.Matchers.notNullValue;
|
import static org.hamcrest.Matchers.notNullValue;
|
||||||
import static org.hamcrest.Matchers.nullValue;
|
import static org.hamcrest.Matchers.nullValue;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||||
|
|
||||||
public class ErrorHandlerTest
|
public class ErrorHandlerTest
|
||||||
{
|
{
|
||||||
|
@ -91,7 +95,7 @@ public class ErrorHandlerTest
|
||||||
// produce an exception with an JSON formatted cause message
|
// produce an exception with an JSON formatted cause message
|
||||||
if (target.startsWith("/jsonmessage/"))
|
if (target.startsWith("/jsonmessage/"))
|
||||||
{
|
{
|
||||||
String message = "{\n \"glossary\": {\n \"title\": \"example\"\n }\n }";
|
String message = "\"}, \"glossary\": {\n \"title\": \"example\"\n }\n {\"";
|
||||||
throw new ServletException(new RuntimeException(message));
|
throw new ServletException(new RuntimeException(message));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,6 +477,25 @@ public class ErrorHandlerTest
|
||||||
{
|
{
|
||||||
Map jo = (Map)JSON.parse(response.getContent());
|
Map jo = (Map)JSON.parse(response.getContent());
|
||||||
|
|
||||||
|
Set<String> acceptableKeyNames = new HashSet<>();
|
||||||
|
acceptableKeyNames.add("url");
|
||||||
|
acceptableKeyNames.add("status");
|
||||||
|
acceptableKeyNames.add("message");
|
||||||
|
acceptableKeyNames.add("servlet");
|
||||||
|
acceptableKeyNames.add("cause0");
|
||||||
|
acceptableKeyNames.add("cause1");
|
||||||
|
acceptableKeyNames.add("cause2");
|
||||||
|
|
||||||
|
for (Object key : jo.keySet())
|
||||||
|
{
|
||||||
|
String keyStr = (String)key;
|
||||||
|
assertTrue(acceptableKeyNames.contains(keyStr), "Unexpected Key [" + keyStr + "]");
|
||||||
|
|
||||||
|
Object value = jo.get(key);
|
||||||
|
assertThat("Unexpected value type (" + value.getClass().getName() + ")",
|
||||||
|
value, instanceOf(String.class));
|
||||||
|
}
|
||||||
|
|
||||||
assertThat("url field", jo.get("url"), is(notNullValue()));
|
assertThat("url field", jo.get("url"), is(notNullValue()));
|
||||||
String expectedStatus = String.valueOf(response.getStatus());
|
String expectedStatus = String.valueOf(response.getStatus());
|
||||||
assertThat("status field", jo.get("status"), is(expectedStatus));
|
assertThat("status field", jo.get("status"), is(expectedStatus));
|
||||||
|
|
Loading…
Reference in New Issue