Add DatabindContext and its wiring
[netconf.git] / restconf / restconf-nb / src / test / java / org / opendaylight / restconf / nb / rfc8040 / rests / services / impl / RestconfStreamsSubscriptionServiceImplTest.java
index d7d85aed16ae6a55c093ba044959e1117f265521..6f52bdbdf8729433e0236397667efd3f8d410105 100644 (file)
@@ -32,10 +32,10 @@ import org.opendaylight.mdsal.dom.api.DOMDataBroker;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeChangeService;
 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteTransaction;
 import org.opendaylight.mdsal.dom.api.DOMNotificationService;
-import org.opendaylight.mdsal.dom.api.DOMSchemaService;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
-import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindContext;
+import org.opendaylight.restconf.nb.rfc8040.databind.DatabindProvider;
 import org.opendaylight.restconf.nb.rfc8040.legacy.NormalizedNodePayload;
 import org.opendaylight.restconf.nb.rfc8040.streams.Configuration;
 import org.opendaylight.restconf.nb.rfc8040.streams.listeners.ListenerAdapter;
@@ -49,6 +49,7 @@ import org.opendaylight.yangtools.yang.common.ErrorType;
 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.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 
 @RunWith(MockitoJUnitRunner.StrictStubs.class)
@@ -67,7 +68,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     private Configuration configurationWs;
     private Configuration configurationSse;
 
-    private SchemaContextHandler schemaHandler;
+    private EffectiveModelContext modelContext;
+    private DatabindProvider databindProvider;
 
     @Before
     public void setUp() throws FileNotFoundException, URISyntaxException {
@@ -75,8 +77,6 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         doReturn(wTx).when(dataBroker).newWriteOnlyTransaction();
         doReturn(CommitInfo.emptyFluentFuture()).when(wTx).commit();
 
-        schemaHandler = new SchemaContextHandler(dataBroker, mock(DOMSchemaService.class));
-
         DOMDataTreeChangeService dataTreeChangeService = mock(DOMDataTreeChangeService.class);
         doReturn(mock(ListenerRegistration.class)).when(dataTreeChangeService)
                 .registerDataTreeChangeListener(any(), any());
@@ -88,8 +88,9 @@ public class RestconfStreamsSubscriptionServiceImplTest {
         // FIXME: just mock UriInfo here
         doReturn(new LocalUriInfo().getBaseUriBuilder()).when(uriInfo).getBaseUriBuilder();
         doReturn(new URI("http://127.0.0.1/" + URI)).when(uriInfo).getAbsolutePath();
-        schemaHandler.onModelContextUpdated(
-            YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications")));
+
+        modelContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/notifications"));
+        databindProvider = () -> DatabindContext.ofModel(modelContext);
         configurationWs = new Configuration(0, 100, 10, false);
         configurationSse = new Configuration(0, 100, 10, true);
     }
@@ -112,12 +113,12 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamSSE() {
         ListenersBroker.getInstance().registerDataChangeListener(
-                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()),
+                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", modelContext),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationSse);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationSse);
         final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
             "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
         assertEquals("http://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
@@ -129,12 +130,12 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamWS() {
         ListenersBroker.getInstance().registerDataChangeListener(
-                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", schemaHandler.get()),
+                IdentifierCodec.deserialize("toaster:toaster/toasterStatus", modelContext),
                 "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE",
                 NotificationOutputType.XML);
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationWs);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationWs);
         final NormalizedNodePayload response = streamsSubscriptionService.subscribeToStream(
             "data-change-event-subscription/toaster:toaster/toasterStatus/datastore=OPERATIONAL/scope=ONE", uriInfo);
         assertEquals("ws://localhost:8181/" + RestconfConstants.BASE_URI_PATTERN
@@ -145,8 +146,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamMissingDatastoreInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationWs);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationWs);
         final var errors = assertThrows(RestconfDocumentedException.class,
             () -> streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/scope=ONE", uriInfo))
             .getErrors();
@@ -160,8 +161,8 @@ public class RestconfStreamsSubscriptionServiceImplTest {
     @Test
     public void testSubscribeToStreamMissingScopeInPath() {
         final RestconfStreamsSubscriptionServiceImpl streamsSubscriptionService =
-                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService,
-                        schemaHandler, configurationWs);
+                new RestconfStreamsSubscriptionServiceImpl(dataBroker, notificationService, databindProvider,
+                        configurationWs);
         final var errors = assertThrows(RestconfDocumentedException.class,
             () -> streamsSubscriptionService.subscribeToStream("toaster:toaster/toasterStatus/datastore=OPERATIONAL",
                 uriInfo)).getErrors();