JSONObject fault = new JSONObject();
obj.put("Fault", fault);
JSONObject code = new JSONObject();
fault.put("Code", code);
code.put("Value", new JSONString("Sender"));
JSONObject subcode = new JSONObject();
code.put("Subcode", subcode);
subcode.put("Value", new JSONString("MessageSubcodeTest"));
JSONObject reason = new JSONObject();
fault.put("Reason", reason);
reason.put("Text", new JSONString("Test Reason"));
JSONObject detail = new JSONObject();
fault.put("Detail", detail);
detail.put("Value1", new JSONString("First Value"));
detail.put("Value2", new JSONString("Second Value"));
RESTException exception = JSONUtil.getRESTException(obj, -1, "url");
ok(null != exception, "Getting RESTException should be a value object. It was " + exception);
ok("Sender".equals(exception.getCode()), "Getting RESTException code should be Sender. It was " + exception.getCode());
ok("MessageSubcodeTest".equals(exception.getSubcode()),
"Getting RESTException subcode should be MessageSubcodeTest. It was " + exception.getSubcode());
ok("Test Reason".equals(exception.getReason()),
"Getting RESTException reason should be Test Reason. It was " + exception.getReason());
ok("First Value".equals(exception.getDetails().get("Value1")),
"Getting RESTException details first value should be First Value. It was " + exception.getDetails().get("Value1"));
ok("Second Value".equals(exception.getDetails().get("Value2")),
"Getting RESTException details first value should be Second Value. It was " + exception.getDetails().get("Value2"));
/*
Now we'll test a value that isn't an NCAC fault
*/
obj = new JSONObject();
obj.put("foo", new JSONString("foo"));
obj.put("bar", new JSONString("bar"));
ok(null == JSONUtil.getRESTException(obj, -1, "url"),
"Getting RESTException for JSON data that doesn't represent an NCAC exception should be null. It was " +
JSONUtil.getRESTException(obj, -1, "url"));
}