Bump MRI upstreams
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / NetconfToNotificationTest.java
index 732f86e691001291ad80d10d1a7f1cf3db90bf53..2bf7bc4b4a73de58688a8768b208e33117c4516d 100644 (file)
@@ -5,45 +5,38 @@
  * 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.netconf.sal.connect.netconf;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertThrows;
 import static org.junit.Assert.assertTrue;
 
-import com.google.common.collect.Iterables;
 import java.io.InputStream;
-import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Set;
-import javax.xml.parsers.DocumentBuilderFactory;
+import java.util.Collection;
 import org.junit.Before;
 import org.junit.Test;
-import org.opendaylight.controller.config.util.xml.XmlUtil;
-import org.opendaylight.controller.md.sal.dom.api.DOMEvent;
-import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
+import org.opendaylight.mdsal.dom.api.DOMEvent;
+import org.opendaylight.mdsal.dom.api.DOMNotification;
 import org.opendaylight.netconf.api.NetconfMessage;
+import org.opendaylight.netconf.api.xml.XmlUtil;
 import org.opendaylight.netconf.notifications.NetconfNotification;
 import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessageTransformer;
+import org.opendaylight.yangtools.rfc8528.data.util.EmptyMountPointContext;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
 import org.opendaylight.yangtools.yang.model.api.Module;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.w3c.dom.Document;
 
-public class NetconfToNotificationTest {
+public class NetconfToNotificationTest extends AbstractBaseSchemasTest {
 
     NetconfMessageTransformer messageTransformer;
 
     NetconfMessage userNotification;
 
-    @SuppressWarnings("deprecation")
     @Before
     public void setup() throws Exception {
-        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-        factory.setNamespaceAware(true);
         InputStream notifyPayloadStream = getClass().getResourceAsStream("/notification-payload.xml");
         assertNotNull(notifyPayloadStream);
 
@@ -52,41 +45,42 @@ public class NetconfToNotificationTest {
         userNotification = new NetconfMessage(doc);
     }
 
-    static SchemaContext getNotificationSchemaContext(Class<?> loadClass, boolean getExceptionTest) throws Exception {
-        final List<InputStream> modelsToParse = new ArrayList<>();
-
+    static EffectiveModelContext getNotificationSchemaContext(final Class<?> loadClass,
+            final boolean getExceptionTest) {
+        final EffectiveModelContext context;
         if (getExceptionTest) {
-            modelsToParse.add(loadClass.getResourceAsStream("/schemas/user-notification4.yang"));
-            modelsToParse.add(loadClass.getResourceAsStream("/schemas/user-notification3.yang"));
+            context = YangParserTestUtils.parseYangResources(loadClass, "/schemas/user-notification4.yang",
+                    "/schemas/user-notification3.yang");
         } else {
-            modelsToParse.add(loadClass.getResourceAsStream("/schemas/user-notification.yang"));
-            modelsToParse.add(loadClass.getResourceAsStream("/schemas/user-notification2.yang"));
+            context = YangParserTestUtils.parseYangResources(loadClass, "/schemas/user-notification.yang",
+                "/schemas/user-notification2.yang");
         }
 
-        final SchemaContext context = YangParserTestUtils.parseYangStreams(modelsToParse);
-        final Set<Module> modules = context.getModules();
+        final Collection<? extends Module> modules = context.getModules();
         assertTrue(!modules.isEmpty());
         assertNotNull(context);
         return context;
     }
 
-    @Test(expected =  IllegalStateException.class)
+    @Test
     public void testMostRecentWrongYangModel() throws Exception {
-        final SchemaContext schemaContext = getNotificationSchemaContext(getClass(), true);
-        messageTransformer = new NetconfMessageTransformer(schemaContext, true);
-        messageTransformer.toNotification(userNotification);
+        final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), true);
+        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true,
+            BASE_SCHEMAS.getBaseSchema());
+        assertThrows(IllegalArgumentException.class, () -> messageTransformer.toNotification(userNotification));
     }
 
     @Test
     public void testToNotificationFunction() throws Exception {
-        final SchemaContext schemaContext = getNotificationSchemaContext(getClass(), false);
-        messageTransformer = new NetconfMessageTransformer(schemaContext, true);
+        final EffectiveModelContext schemaContext = getNotificationSchemaContext(getClass(), false);
+        messageTransformer = new NetconfMessageTransformer(new EmptyMountPointContext(schemaContext), true,
+            BASE_SCHEMAS.getBaseSchema());
         final DOMNotification domNotification = messageTransformer.toNotification(userNotification);
         final ContainerNode root = domNotification.getBody();
         assertNotNull(root);
-        assertEquals(6, Iterables.size(root.getValue()));
-        assertEquals("user-visited-page", root.getNodeType().getLocalName());
-        assertEquals(new SimpleDateFormat(NetconfNotification.RFC3339_DATE_FORMAT_WITH_MILLIS_BLUEPRINT).parse("2015-10-23T09:42:27.67175+00:00"),
-                ((DOMEvent) domNotification).getEventTime());
+        assertEquals(6, root.body().size());
+        assertEquals("user-visited-page", root.getIdentifier().getNodeType().getLocalName());
+        assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2015-10-23T09:42:27.67175+00:00").toInstant(),
+                ((DOMEvent) domNotification).getEventInstant());
     }
 }