Use DOMMountPointServiceHandler non-statically
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / jersey / providers / test / AbstractBodyReaderTest.java
index a112fd00152a87710f7c079736daf0af30679995..5f876d67068545104b2b57462cdb5acc4502f06a 100644 (file)
@@ -9,44 +9,48 @@
 package org.opendaylight.restconf.nb.rfc8040.jersey.providers.test;
 
 import static org.junit.Assert.assertNotNull;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 
-import java.lang.reflect.Field;
+import com.google.common.base.Optional;
 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.dom.api.DOMMountPoint;
+import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
 import org.opendaylight.restconf.common.patch.PatchContext;
-import org.opendaylight.restconf.nb.rfc8040.RestConnectorProvider;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
 import org.opendaylight.restconf.nb.rfc8040.TestUtils;
 import org.opendaylight.restconf.nb.rfc8040.handlers.DOMMountPointServiceHandler;
 import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.jersey.providers.spi.AbstractIdentifierAwareJaxRsProvider;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 
 public abstract class AbstractBodyReaderTest {
 
-    protected static final DOMMountPointServiceHandler MOUNT_POINT_SERVICE_HANDLER =
-            mock(DOMMountPointServiceHandler.class);
-
     protected final MediaType mediaType;
     protected final SchemaContextHandler schemaContextHandler;
+    protected final DOMMountPointServiceHandler mountPointServiceHandler;
 
     protected AbstractBodyReaderTest(SchemaContext schemaContext) throws NoSuchFieldException, IllegalAccessException {
         mediaType = getMediaType();
 
-        final Field mountPointServiceHandlerField =
-                RestConnectorProvider.class.getDeclaredField("mountPointServiceHandler");
-        mountPointServiceHandlerField.setAccessible(true);
-        mountPointServiceHandlerField.set(RestConnectorProvider.class, MOUNT_POINT_SERVICE_HANDLER);
-
         schemaContextHandler = TestUtils.newSchemaContextHandler(schemaContext);
+
+        final DOMMountPointService mountPointService = mock(DOMMountPointService.class);
+        final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
+        doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
+        doReturn(schemaContext).when(mountPoint).getSchemaContext();
+
+        mountPointServiceHandler = DOMMountPointServiceHandler.newInstance(mountPointService);
     }
 
     protected abstract MediaType getMediaType();