Fix various warnings
[netconf.git] / restconf / sal-rest-connector / src / test / java / org / opendaylight / restconf / utils / mapping / RestconfMappingNodeUtilTest.java
index 599184bdcd047a7888fd2d17946d2d5530f2f17f..8abf3581c82b1a93b7ea2911b49b3f0223235729 100644 (file)
@@ -12,10 +12,12 @@ import static org.junit.Assert.assertNotNull;
 import static org.mockito.Mockito.when;
 
 import java.net.URI;
-import java.text.SimpleDateFormat;
+import java.time.Instant;
+import java.time.OffsetDateTime;
+import java.time.ZoneId;
+import java.time.format.DateTimeFormatter;
 import java.util.ArrayList;
 import java.util.Collection;
-import java.util.Date;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -52,11 +54,16 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
 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.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 /**
- * Unit tests for {@link RestconfMappingNodeUtil}
+ * Unit tests for {@link RestconfMappingNodeUtil}.
  */
 public class RestconfMappingNodeUtilTest {
+
+    private static final Logger LOG = LoggerFactory.getLogger(RestconfMappingNodeUtilTest.class);
+
     @Rule
     public ExpectedException thrown = ExpectedException.none();
 
@@ -125,8 +132,8 @@ public class RestconfMappingNodeUtilTest {
             if (child.getNodeType().equals(MonitoringModule.CONT_CAPABILITES_QNAME)) {
                 for (final DataContainerChild<? extends PathArgument, ?> dataContainerChild : ((ContainerNode) child)
                         .getValue()) {
-                    for (final Object entry : ((LeafSetNode) dataContainerChild).getValue()) {
-                        listOfValues.add(((LeafSetEntryNode) entry).getValue());
+                    for (final Object entry : ((LeafSetNode<?>) dataContainerChild).getValue()) {
+                        listOfValues.add(((LeafSetEntryNode<?>) entry).getValue());
                     }
                 }
             }
@@ -140,9 +147,9 @@ public class RestconfMappingNodeUtilTest {
 
     @Test
     public void toStreamEntryNodeTest() throws Exception {
-        final YangInstanceIdentifier path =
-                ParserIdentifier.toInstanceIdentifier("nested-module:depth1-cont/depth2-leaf1", schemaContextMonitoring, null).getInstanceIdentifier();
-        final Date start = new Date();
+        final YangInstanceIdentifier path = ParserIdentifier.toInstanceIdentifier(
+                "nested-module:depth1-cont/depth2-leaf1", schemaContextMonitoring, null).getInstanceIdentifier();
+        final Instant start = Instant.now();
         final String outputType = "XML";
         final URI uri = new URI("uri");
         final Module monitoringModule = schemaContextMonitoring
@@ -152,15 +159,16 @@ public class RestconfMappingNodeUtilTest {
         final Map<QName, Object> map =
                 prepareMap(path.getLastPathArgument().getNodeType().getLocalName(), uri, start, outputType);
 
-        final NormalizedNode mappedData = RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring(path, start, outputType, uri,
-                monitoringModule, exist, schemaContextMonitoring);
+        final NormalizedNode<?, ?> mappedData =
+                RestconfMappingNodeUtil.mapDataChangeNotificationStreamByIetfRestconfMonitoring(
+                        path, start, outputType, uri, monitoringModule, exist, schemaContextMonitoring);
         assertNotNull(mappedData);
         testData(map, mappedData);
     }
 
     @Test
     public void toStreamEntryNodeNotifiTest() throws Exception {
-        final Date start = new Date();
+        final Instant start = Instant.now();
         final String outputType = "JSON";
         final URI uri = new URI("uri");
         final Module monitoringModule = schemaContextMonitoring
@@ -171,29 +179,29 @@ public class RestconfMappingNodeUtilTest {
         map.put(MonitoringModule.LEAF_DESCR_STREAM_QNAME, "Notifi");
 
         final QName notifiQName = QName.create("urn:nested:module", "2014-06-3", "notifi");
-        final NormalizedNode mappedData =
-                RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(notifiQName, schemaContextMonitoring.getNotifications(), start,
-                        outputType, uri, monitoringModule, exist);
+        final NormalizedNode<?, ?> mappedData =
+                RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(notifiQName,
+                    schemaContextMonitoring.getNotifications(), start, outputType, uri, monitoringModule, exist);
         assertNotNull(mappedData);
         testData(map, mappedData);
     }
 
-    private static Map<QName, Object> prepareMap(final String name, final URI uri, final Date start,
+    private static Map<QName, Object> prepareMap(final String name, final URI uri, final Instant start,
             final String outputType) {
         final Map<QName, Object> map = new HashMap<>();
         map.put(MonitoringModule.LEAF_NAME_STREAM_QNAME, name);
         map.put(MonitoringModule.LEAF_LOCATION_ACCESS_QNAME, uri.toString());
-        map.put(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME, true);
-        map.put(MonitoringModule.LEAF_START_TIME_STREAM_QNAME,
-                new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'XXX").format(start));
+        map.put(MonitoringModule.LEAF_REPLAY_SUPP_STREAM_QNAME, Boolean.TRUE);
+        map.put(MonitoringModule.LEAF_START_TIME_STREAM_QNAME, DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(
+            OffsetDateTime.ofInstant(start, ZoneId.systemDefault())));
         map.put(MonitoringModule.LEAF_ENCODING_ACCESS_QNAME, outputType);
         return map;
     }
 
-    private static void testData(final Map<QName, Object> map, final NormalizedNode mappedData) {
+    private static void testData(final Map<QName, Object> map, final NormalizedNode<?, ?> mappedData) {
         for (final DataContainerChild<? extends PathArgument, ?> child : ((MapEntryNode) mappedData).getValue()) {
             if (child instanceof LeafNode) {
-                final LeafNode leaf = ((LeafNode) child);
+                final LeafNode<?> leaf = (LeafNode<?>) child;
                 Assert.assertTrue(map.containsKey(leaf.getNodeType()));
                 Assert.assertEquals(map.get(leaf.getNodeType()), leaf.getValue());
             }
@@ -201,10 +209,10 @@ public class RestconfMappingNodeUtilTest {
     }
 
     /**
-     * Verify loaded modules
+     * Verify loaded modules.
      *
      * @param containerNode
-     *            - modules
+     *             modules
      */
     private static void verifyLoadedModules(final ContainerNode containerNode) {
 
@@ -212,7 +220,7 @@ public class RestconfMappingNodeUtilTest {
 
         for (final DataContainerChild<? extends PathArgument, ?> child : containerNode.getValue()) {
             if (child instanceof LeafNode) {
-                assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, ((LeafNode) child).getNodeType());
+                assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, ((LeafNode<?>) child).getNodeType());
             }
             if (child instanceof MapNode) {
                 assertEquals(IetfYangLibrary.MODULE_QNAME_LIST, ((MapNode) child).getNodeType());
@@ -223,10 +231,14 @@ public class RestconfMappingNodeUtilTest {
                             .getValue()) {
                         switch (dataContainerChild.getNodeType().getLocalName()) {
                             case IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF:
-                                name = String.valueOf(((LeafNode) dataContainerChild).getValue());
+                                name = String.valueOf(((LeafNode<?>) dataContainerChild).getValue());
                                 break;
                             case IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF:
-                                revision = String.valueOf(((LeafNode) dataContainerChild).getValue());
+                                revision = String.valueOf(((LeafNode<?>) dataContainerChild).getValue());
+                                break;
+                            default :
+                                LOG.info("Unknown local name '{}' of node.",
+                                        dataContainerChild.getNodeType().getLocalName());
                                 break;
                         }
                     }