X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FRestconfDocumentedExceptionMapperTest.java;h=c5c459618933af91bb272654d0b40b070fb7ffd3;hp=e146cf8f4fa165a4d3234b616e3bbad1516004e1;hb=refs%2Fchanges%2F67%2F8067%2F6;hpb=2f7f65715105d3a90db953e4e4691b0817b3e085 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java index e146cf8f4f..c5c4596189 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.sal.restconf.impl.test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -18,6 +19,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; +import com.google.common.collect.ImmutableMap; +import com.google.common.collect.Maps; +import com.google.common.io.ByteStreams; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonParser; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -29,7 +36,8 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; - +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @@ -41,7 +49,6 @@ import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathExpression; import javax.xml.xpath.XPathFactory; - import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; import org.junit.Before; @@ -63,13 +70,6 @@ import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.Maps; -import com.google.common.io.ByteStreams; -import com.google.gson.JsonArray; -import com.google.gson.JsonElement; -import com.google.gson.JsonParser; - /** * Unit tests for RestconfDocumentedExceptionMapper. * @@ -842,6 +842,14 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { errorListEntrySet.iterator().next().getKey() ); assertTrue( "\"error\" Json element is not an Array", errorListElement.isJsonArray() ); + // As a final check, make sure there aren't multiple "error" array elements. Unfortunately, + // the call above to getAsJsonObject().entrySet() will out duplicate "error" elements. So + // we'll use regex on the json string to verify this. + + Matcher matcher = Pattern.compile( "\"error\"[ ]*:[ ]*\\[", Pattern.DOTALL ).matcher( bos.toString() ); + assertTrue( "Expected 1 \"error\" element", matcher.find() ); + assertFalse( "Found multiple \"error\" elements", matcher.find() ); + return errorListElement.getAsJsonArray(); } @@ -850,7 +858,6 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { final ErrorInfoVerifier errorInfoVerifier ) { JsonElement errorInfoElement = null; - Map actualErrorInfo = null; Map leafMap = Maps.newHashMap(); for( Entry entry: errorEntryElement.getAsJsonObject().entrySet() ) { String leafName = entry.getKey();