Bug 7433 - Remove use of YangSchemaSourceImpl from restconf tests
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / controller / sal / restconf / impl / test / RestconfImplNotificationSubscribingTest.java
index 2fdb0ba7e46c174145300a5fc435ef63205ee5ff..fae6281d4a88d63152d96bd06c94d629b866ec6c 100644 (file)
@@ -5,9 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-/**
- *
- */
 package org.opendaylight.controller.sal.restconf.impl.test;
 
 import java.lang.reflect.Field;
@@ -36,8 +33,12 @@ import org.opendaylight.netconf.sal.restconf.impl.RestconfImpl;
 import org.opendaylight.netconf.sal.streams.listeners.ListenerAdapter;
 import org.opendaylight.netconf.sal.streams.listeners.Notificator;
 import org.opendaylight.yang.gen.v1.urn.sal.restconf.event.subscription.rev140708.NotificationOutputTypeGrouping.NotificationOutputType;
+import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 public class RestconfImplNotificationSubscribingTest {
 
@@ -58,9 +59,12 @@ public class RestconfImplNotificationSubscribingTest {
 
         this.broker.setDomDataBroker(this.domDataBroker);
         RestconfImpl.getInstance().setBroker(this.broker);
-        ControllerContext.getInstance().setGlobalSchema(TestRestconfUtils.loadSchemaContext("/notifications"));
+        ControllerContext.getInstance()
+                .setGlobalSchema(YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/notifications")));
 
         final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
+        final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-14-12", "localName"));
+        Mockito.when(path.getLastPathArgument()).thenReturn(pathValue);
         Notificator.createListener(path, this.identifier, NotificationOutputType.XML);
     }
 
@@ -215,6 +219,8 @@ public class RestconfImplNotificationSubscribingTest {
     @Test
     public void onNotifiTest() throws Exception {
         final YangInstanceIdentifier path = Mockito.mock(YangInstanceIdentifier.class);
+        final PathArgument pathValue = NodeIdentifier.create(QName.create("module", "2016-14-12", "localName"));
+        Mockito.when(path.getLastPathArgument()).thenReturn(pathValue);
         final ListenerAdapter listener = Notificator.createListener(path, this.identifier, NotificationOutputType.XML);
 
         final List<Entry<String, List<String>>> list = new ArrayList<>();
@@ -229,13 +235,14 @@ public class RestconfImplNotificationSubscribingTest {
 
         final AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> change =
                 Mockito.mock(AsyncDataChangeEvent.class);
-        Field start = listener.getClass().getDeclaredField("start");
+        final Class<?> superclass = listener.getClass().getSuperclass().getSuperclass();
+        Field start = superclass.getDeclaredField("start");
         start.setAccessible(true);
         Date startOrig = (Date) start.get(listener);
         Assert.assertNotNull(startOrig);
         listener.onDataChanged(change);
 
-        start = listener.getClass().getDeclaredField("start");
+        start = superclass.getDeclaredField("start");
         start.setAccessible(true);
         startOrig = (Date) start.get(listener);
         Assert.assertNull(startOrig);