Bug 6848 - repackage providers for jersey+create xml
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / rest / impl / test / providers / AbstractBodyReaderTest.java
index 6a728dc40c3055ceac51328eb4d40a68a886f54f..22c667b35e450753289ec52c255d607da0a921e0 100644 (file)
@@ -11,16 +11,14 @@ package org.opendaylight.controller.sal.rest.impl.test.providers;
 import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
-
 import java.lang.reflect.Field;
+import java.net.URI;
 import java.util.Collections;
-
 import javax.ws.rs.core.MediaType;
 import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.Request;
 import javax.ws.rs.core.UriInfo;
-
 import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.rest.api.RestconfConstants;
 import org.opendaylight.netconf.sal.rest.impl.AbstractIdentifierAwareJaxRsProvider;
@@ -29,19 +27,9 @@ import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
 import org.opendaylight.netconf.sal.restconf.impl.PATCHContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
-/**
- * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
- *
- *
- *
- * @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
- *
- *         Created: Mar 7, 2015
- */
 public abstract class AbstractBodyReaderTest {
 
-    protected final static ControllerContext controllerContext = ControllerContext
-            .getInstance();
+    protected final static ControllerContext controllerContext = ControllerContext.getInstance();
     protected final MediaType mediaType;
     private static Field uriField;
     private static Field requestField;
@@ -54,7 +42,7 @@ public abstract class AbstractBodyReaderTest {
         requestField = AbstractIdentifierAwareJaxRsProvider.class
                 .getDeclaredField("request");
         requestField.setAccessible(true);
-        mediaType = getMediaType();
+        this.mediaType = getMediaType();
     }
 
     protected abstract MediaType getMediaType();
@@ -64,25 +52,28 @@ public abstract class AbstractBodyReaderTest {
         return TestRestconfUtils.loadSchemaContext(yangPath, schemaContext);
     }
 
-    protected static <T extends AbstractIdentifierAwareJaxRsProvider> void mockBodyReader(
-            final String identifier, final T normalizedNodeProvider,
-            final boolean isPost) throws NoSuchFieldException,
-            SecurityException, IllegalArgumentException, IllegalAccessException {
+    protected static <T extends AbstractIdentifierAwareJaxRsProvider> void mockBodyReader(final String identifier,
+            final T normalizedNodeProvider, final boolean isPost) throws Exception {
         final UriInfo uriInfoMock = mock(UriInfo.class);
-        final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(
-                1);
-        pathParm.put(RestconfConstants.IDENTIFIER,
-                Collections.singletonList(identifier));
+        final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(1);
+
+        if (!identifier.isEmpty()) {
+            pathParm.put(RestconfConstants.IDENTIFIER, Collections.singletonList(identifier));
+        }
+
         when(uriInfoMock.getPathParameters()).thenReturn(pathParm);
         when(uriInfoMock.getPathParameters(false)).thenReturn(pathParm);
         when(uriInfoMock.getPathParameters(true)).thenReturn(pathParm);
+        when(uriInfoMock.getAbsolutePath()).thenReturn(new URI("restconf"));
         uriField.set(normalizedNodeProvider, uriInfoMock);
+
         final Request request = mock(Request.class);
         if (isPost) {
             when(request.getMethod()).thenReturn("POST");
         } else {
             when(request.getMethod()).thenReturn("PUT");
         }
+
         requestField.set(normalizedNodeProvider, request);
     }
 
@@ -108,4 +99,10 @@ public abstract class AbstractBodyReaderTest {
         assertNotNull(patchContext.getInstanceIdentifierContext().getSchemaContext());
         assertNotNull(patchContext.getInstanceIdentifierContext().getSchemaNode());
     }
+
+    protected static void checkPATCHContextMountPoint(final PATCHContext patchContext) {
+        checkPATCHContext(patchContext);
+        assertNotNull(patchContext.getInstanceIdentifierContext().getMountPoint());
+        assertNotNull(patchContext.getInstanceIdentifierContext().getMountPoint().getSchemaContext());
+    }
 }