- static class ComplexErrorInfoVerifier implements ErrorInfoVerifier {
-
- Map<String, String> expErrorInfo;
-
- public ComplexErrorInfoVerifier(final Map<String, String> expErrorInfo) {
- this.expErrorInfo = expErrorInfo;
- }
-
- @Override
- public void verifyXML(final Node errorInfoNode) {
-
- final Map<String, String> mutableExpMap = Maps.newHashMap(expErrorInfo);
- final NodeList childNodes = errorInfoNode.getChildNodes();
- for (int i = 0; i < childNodes.getLength(); i++) {
- final Node child = childNodes.item(i);
- if (child instanceof Element) {
- final String expValue = mutableExpMap.remove(child.getNodeName());
- assertNotNull("Found unexpected \"error-info\" child node: " + child.getNodeName(), expValue);
- assertEquals("Text content for \"error-info\" child node " + child.getNodeName(), expValue,
- child.getTextContent());
- }
- }
-
- if (!mutableExpMap.isEmpty()) {
- fail("Missing \"error-info\" child nodes: " + mutableExpMap);
- }
- }
-
- @Override
- public void verifyJson(final JsonElement errorInfoElement) {
-
- assertTrue("\"error-info\" Json element is not an Object", errorInfoElement.isJsonObject());
-
- final Map<String, String> actualErrorInfo = Maps.newHashMap();
- for (final Entry<String, JsonElement> entry : errorInfoElement.getAsJsonObject().entrySet()) {
- final String leafName = entry.getKey();
- final JsonElement leafElement = entry.getValue();
- actualErrorInfo.put(leafName, leafElement.getAsString());
- }
-
- final Map<String, String> mutableExpMap = Maps.newHashMap(expErrorInfo);
- for (final Entry<String, String> actual : actualErrorInfo.entrySet()) {
- final String expValue = mutableExpMap.remove(actual.getKey());
- assertNotNull("Found unexpected \"error-info\" child node: " + actual.getKey(), expValue);
- assertEquals("Text content for \"error-info\" child node " + actual.getKey(), expValue,
- actual.getValue());
- }
-
- if (!mutableExpMap.isEmpty()) {
- fail("Missing \"error-info\" child nodes: " + mutableExpMap);
- }
- }
- }
-