2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.mdsal.binding.dom.codec.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertSame;
12 import static org.junit.Assert.assertTrue;
14 import java.time.Instant;
15 import org.junit.Test;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TwoLevelListChanged;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TwoLevelListChangedBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
21 import org.opendaylight.yangtools.yang.binding.EventInstantAware;
22 import org.opendaylight.yangtools.yang.binding.util.BindingMap;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
26 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
27 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
28 import org.opendaylight.yangtools.yang.model.api.stmt.SchemaNodeIdentifier.Absolute;
30 public class NotificationProcessingTest extends AbstractBindingCodecTest {
31 private static final QName NAME = QName.create(TopLevelList.QNAME, "name");
33 private static TwoLevelListChanged createTestBindingData() {
34 return new TwoLevelListChangedBuilder()
35 .setTopLevelList(BindingMap.of(new TopLevelListBuilder().withKey(new TopLevelListKey("test")).build()))
39 private static ContainerNode createTestDomData() {
40 return ImmutableNodes.newContainerBuilder()
41 .withNodeIdentifier(NodeIdentifier.create(TwoLevelListChanged.QNAME))
42 .withChild(ImmutableNodes.newSystemMapBuilder()
43 .withNodeIdentifier(NodeIdentifier.create(TopLevelList.QNAME))
44 .withChild(ImmutableNodes.newMapEntryBuilder()
45 .withNodeIdentifier(NodeIdentifierWithPredicates.of(TopLevelList.QNAME, NAME, "test"))
53 public void testNotificationToNormalized() {
54 final var dom = codecContext.toNormalizedNodeNotification(createTestBindingData());
55 assertEquals(createTestDomData(), dom);
59 public void testNormalizedToNotification() {
60 final var bindingDeserialized = codecContext.fromNormalizedNodeNotification(
61 Absolute.of(TwoLevelListChanged.QNAME), createTestDomData());
62 assertTrue(bindingDeserialized instanceof TwoLevelListChanged);
63 assertEquals(createTestBindingData(), bindingDeserialized);
67 public void testNormalizedToNotificationWithInstant() {
68 final var instant = Instant.now();
69 final var bindingDeserialized = codecContext.fromNormalizedNodeNotification(
70 Absolute.of(TwoLevelListChanged.QNAME), createTestDomData(), instant);
71 assertTrue(bindingDeserialized instanceof TwoLevelListChanged);
72 assertEquals(createTestBindingData(), bindingDeserialized);
73 assertTrue(bindingDeserialized instanceof EventInstantAware);
74 assertSame(instant, ((EventInstantAware) bindingDeserialized).eventInstant());
78 public void testNormalizedToNotificationWithNull() {
79 final var bindingDeserialized = codecContext.fromNormalizedNodeNotification(
80 Absolute.of(TwoLevelListChanged.QNAME), createTestDomData(), null);
81 assertTrue(bindingDeserialized instanceof TwoLevelListChanged);
82 assertEquals(createTestBindingData(), bindingDeserialized);