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;
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;
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;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
import javax.xml.namespace.NamespaceContext;
import javax.xml.parsers.DocumentBuilderFactory;
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;
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.
*
void stageMockEx( final RestconfDocumentedException ex ) {
reset( mockRestConf );
- when( mockRestConf.readOperationalData( any( String.class ) ) ).thenThrow( ex );
+ when( mockRestConf.readOperationalData( any( String.class ), any( UriInfo.class ) ) ).thenThrow( ex );
}
void testJsonResponse( final RestconfDocumentedException ex, final Status expStatus, final ErrorType expErrorType,
// The StructuredDataToJsonProvider should throw a RestconfDocumentedException with no data
- when( mockRestConf.readOperationalData( any( String.class ) ) )
- .thenReturn( new StructuredData( null, null, null ) );
+ when( mockRestConf.readOperationalData( any( String.class ), any( UriInfo.class ) ) )
+ .thenReturn( new StructuredData( null, null, null ) );
Response resp = target("/operational/foo").request( MediaType.APPLICATION_JSON ).get();
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();
}
final ErrorInfoVerifier errorInfoVerifier ) {
JsonElement errorInfoElement = null;
- Map<String, String> actualErrorInfo = null;
Map<String, String> leafMap = Maps.newHashMap();
for( Entry<String, JsonElement> entry: errorEntryElement.getAsJsonObject().entrySet() ) {
String leafName = entry.getKey();