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.test;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
13 import com.google.common.collect.ImmutableMap;
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.Notification;
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.impl.schema.Builders;
28 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
30 public class NotificationProcessingTest extends AbstractBindingCodecTest {
31 private static final QName NAME = QName.create(TopLevelList.QNAME, "name");
33 private static TwoLevelListChanged createTestBindingData() {
34 final TopLevelListKey key = new TopLevelListKey("test");
35 return new TwoLevelListChangedBuilder()
36 .setTopLevelList(ImmutableMap.of(key, new TopLevelListBuilder().withKey(key).build()))
40 private static ContainerNode createTestDomData() {
41 return Builders.containerBuilder()
42 .withNodeIdentifier(NodeIdentifier.create(TwoLevelListChanged.QNAME))
43 .withChild(Builders.mapBuilder()
44 .withNodeIdentifier(NodeIdentifier.create(TopLevelList.QNAME))
45 .withChild(Builders.mapEntryBuilder()
46 .withNodeIdentifier(NodeIdentifierWithPredicates.of(TopLevelList.QNAME, NAME, "test"))
54 public void testNotificationToNormalized() {
55 final ContainerNode dom = registry.toNormalizedNodeNotification(createTestBindingData());
56 assertEquals(createTestDomData(), dom);
60 public void testNormalizedToNotification() {
61 final Notification bindingDeserialized = registry.fromNormalizedNodeNotification(SchemaPath.ROOT.createChild(
62 TwoLevelListChanged.QNAME), createTestDomData());
63 assertTrue(bindingDeserialized instanceof TwoLevelListChanged);
64 assertEquals(createTestBindingData(), bindingDeserialized);
68 public void testNormalizedToNotificationWithInstant() {
69 final Instant instant = Instant.now();
70 final Notification bindingDeserialized = registry.fromNormalizedNodeNotification(SchemaPath.ROOT.createChild(
71 TwoLevelListChanged.QNAME), createTestDomData(), instant);
72 assertTrue(bindingDeserialized instanceof TwoLevelListChanged);
73 assertEquals(createTestBindingData(), bindingDeserialized);
74 assertTrue(bindingDeserialized instanceof EventInstantAware);
75 assertEquals(instant, ((EventInstantAware) bindingDeserialized).eventInstant());
79 public void testNormalizedToNotificationWithNull() {
80 final Notification bindingDeserialized = registry.fromNormalizedNodeNotification(SchemaPath.ROOT.createChild(
81 TwoLevelListChanged.QNAME), createTestDomData(), null);
82 assertTrue(bindingDeserialized instanceof TwoLevelListChanged);
83 assertEquals(createTestBindingData(), bindingDeserialized);