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;
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();
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());
}
}
}
@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
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
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());
}
}
/**
- * Verify loaded modules
+ * Verify loaded modules.
*
* @param containerNode
- * - modules
+ * modules
*/
private static void verifyLoadedModules(final ContainerNode containerNode) {
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());
.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;
}
}