Integrate MRI projects for Neon
[netconf.git] / restconf / restconf-nb-bierman02 / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / RestconfImplTest.java
index 1401798ce07f00bd0e04df873ecd73e50f23d7fe..59474e3991e734620d0452a0ff0a3cd981d86acf 100644 (file)
@@ -9,8 +9,9 @@ package org.opendaylight.controller.sal.restconf.impl.test;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.isNull;
 import static org.mockito.Mockito.doReturn;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.times;
@@ -35,25 +36,24 @@ import javax.ws.rs.core.MultivaluedHashMap;
 import javax.ws.rs.core.MultivaluedMap;
 import javax.ws.rs.core.UriBuilder;
 import javax.ws.rs.core.UriInfo;
-import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.mockito.Mockito;
 import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcResult;
 import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
 import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
 import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag;
-import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorType;
 import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.netconf.sal.streams.listeners.Notificator;
 import org.opendaylight.restconf.common.context.InstanceIdentifierContext;
 import org.opendaylight.restconf.common.context.NormalizedNodeContext;
+import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
+import org.opendaylight.restconf.common.errors.RestconfError;
+import org.opendaylight.restconf.common.errors.RestconfError.ErrorTag;
+import org.opendaylight.restconf.common.errors.RestconfError.ErrorType;
 import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -73,24 +73,17 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
  */
 public class RestconfImplTest {
 
-    private RestconfImpl restconfImpl = null;
-    private static ControllerContext controllerContext = null;
+    private static SchemaContext schemaContext;
+
+    private final BrokerFacade brokerFacade = mock(BrokerFacade.class);
+    private final ControllerContext controllerContext = TestRestconfUtils.newControllerContext(schemaContext);
+    private final RestconfImpl restconfImpl = RestconfImpl.newInstance(brokerFacade, controllerContext);
 
     @BeforeClass
     public static void init() throws FileNotFoundException, ReactorException {
-        final SchemaContext schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
-
+        schemaContext = TestUtils.loadSchemaContext("/full-versions/yangs");
         final Set<Module> allModules = schemaContext.getModules();
         assertNotNull(allModules);
-
-        controllerContext = ControllerContext.getInstance();
-        controllerContext.setSchemas(schemaContext);
-    }
-
-    @Before
-    public void initMethod() {
-        this.restconfImpl = RestconfImpl.getInstance();
-        this.restconfImpl.setControllerContext(controllerContext);
     }
 
     @Test
@@ -102,7 +95,7 @@ public class RestconfImplTest {
 
     private void binaryKeyTest(final List<Byte> al, final List<Byte> al2) {
 
-        final QName keyDef = QName.create("test:key:binary", "2017-14-08", "b1");
+        final QName keyDef = QName.create("test:key:binary", "2017-08-14", "b1");
 
         final Map<QName, Object> uriKeyValues = new HashMap<>();
         uriKeyValues.put(keyDef, al.toArray());
@@ -136,8 +129,7 @@ public class RestconfImplTest {
     public void testExample() throws FileNotFoundException, ParseException {
         @SuppressWarnings("rawtypes")
         final NormalizedNode normalizedNodeData = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData();
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-        when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(normalizedNodeData);
+        when(brokerFacade.readOperationalData(isNull())).thenReturn(normalizedNodeData);
         assertEquals(normalizedNodeData,
                 brokerFacade.readOperationalData(null));
     }
@@ -163,7 +155,7 @@ public class RestconfImplTest {
                 .invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
         this.restconfImpl.invokeRpc("randomId", ctx, uriInfo);
         this.restconfImpl.invokeRpc("ietf-netconf", ctx, uriInfo);
-        verify(rpcService, times(2)).invokeRpc(any(SchemaPath.class), any(NormalizedNode.class));
+        verify(rpcService, times(2)).invokeRpc(any(SchemaPath.class), isNull());
     }
 
     /**
@@ -214,7 +206,7 @@ public class RestconfImplTest {
         // register test notification stream
         final SchemaPath path = SchemaPath.create(
                 true, QName.create("http://netconfcentral.org/ns/toaster", "2009-11-20", "toastDone"));
-        Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML");
+        Notificator.createNotificationListener(Lists.newArrayList(path), identifier, "XML", controllerContext);
 
         final UriInfo uriInfo = mock(UriInfo.class);
         final UriBuilder uriBuilder = mock(UriBuilder.class);
@@ -228,9 +220,6 @@ public class RestconfImplTest {
         when(map.entrySet()).thenReturn(set);
         when(uriInfo.getQueryParameters()).thenReturn(map);
 
-        final BrokerFacade brokerFacade = mock(BrokerFacade.class);
-        this.restconfImpl.setBroker(brokerFacade);
-
         // subscribe to stream and verify response
         final NormalizedNodeContext response = this.restconfImpl.subscribeToStream(identifier, uriInfo);