Bug 8153: Enforce check-style rules for netconf - sal-netconf-connector
[netconf.git] / netconf / sal-netconf-connector / src / test / java / org / opendaylight / netconf / sal / connect / netconf / NetconfToNotificationTest.java
index 1b4c19098d3b6f15d6df8da3cf2167387a52bdec..20502f45e982088b2f74d0cb588c5273ee204e64 100644 (file)
@@ -14,11 +14,9 @@ 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 org.junit.Before;
 import org.junit.Test;
 import org.opendaylight.controller.config.util.xml.XmlUtil;
@@ -30,8 +28,7 @@ import org.opendaylight.netconf.sal.connect.netconf.schema.mapping.NetconfMessag
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
-import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
 import org.w3c.dom.Document;
 
 public class NetconfToNotificationTest {
@@ -40,11 +37,8 @@ public class NetconfToNotificationTest {
 
     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);
 
@@ -53,7 +47,8 @@ public class NetconfToNotificationTest {
         userNotification = new NetconfMessage(doc);
     }
 
-    static SchemaContext getNotificationSchemaContext(Class<?> loadClass, boolean getExceptionTest) {
+    static SchemaContext getNotificationSchemaContext(final Class<?> loadClass,
+                                                      final boolean getExceptionTest) throws Exception {
         final List<InputStream> modelsToParse = new ArrayList<>();
 
         if (getExceptionTest) {
@@ -64,12 +59,11 @@ public class NetconfToNotificationTest {
             modelsToParse.add(loadClass.getResourceAsStream("/schemas/user-notification2.yang"));
         }
 
-        final YangContextParser parser = new YangParserImpl();
-        final Set<Module> modules = parser.parseYangModelsFromStreams(modelsToParse);
+        final SchemaContext context = YangParserTestUtils.parseYangStreams(modelsToParse);
+        final Set<Module> modules = context.getModules();
         assertTrue(!modules.isEmpty());
-        final SchemaContext schemaContext = parser.resolveSchemaContext(modules);
-        assertNotNull(schemaContext);
-        return schemaContext;
+        assertNotNull(context);
+        return context;
     }
 
     @Test(expected =  IllegalStateException.class)
@@ -88,7 +82,7 @@ public class NetconfToNotificationTest {
         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"),
+        assertEquals(NetconfNotification.RFC3339_DATE_PARSER.apply("2015-10-23T09:42:27.67175+00:00"),
                 ((DOMEvent) domNotification).getEventTime());
     }
 }