2 * Copyright (c) 2016 Cisco and/or its affiliates.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at:
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601;
18 import javax.annotation.Nonnull;
19 import org.hamcrest.CoreMatchers;
20 import org.junit.Assert;
21 import org.junit.Test;
22 import org.opendaylight.controller.md.sal.dom.api.DOMNotification;
23 import org.opendaylight.netconf.notifications.NetconfNotification;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.*;
25 import org.opendaylight.yangtools.sal.binding.generator.impl.ModuleInfoBackedContext;
26 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
27 import org.opendaylight.yangtools.yang.common.QName;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
30 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
31 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
32 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
34 public class NoetificationToNetconfModuleTest {
36 private final DOMNotification notification = new DOMNotification() {
38 private QName qname = NetconfSessionStart.QNAME;
39 private YangInstanceIdentifier.NodeIdentifier nodeIdentifier =
40 new YangInstanceIdentifier.NodeIdentifier(NetconfSessionStart.QNAME);
44 public SchemaPath getType() {
45 return SchemaPath.create(true, qname);
50 public ContainerNode getBody() {
51 return Builders.containerBuilder()
52 .withNodeIdentifier(nodeIdentifier)
53 .withChild(ImmutableNodes.leafNode(QName.create(qname, "username"), "user"))
54 .withChild(ImmutableNodes.leafNode(QName.create(qname, "session-id"), 1))
55 .withChild(ImmutableNodes.leafNode(QName.create(qname, "source-host"), "127.0.0.1"))
61 public void notificationToXml() throws Exception {
62 final ModuleInfoBackedContext moduleInfoBackedContext = getModuleInfoBackedCOntext();
64 final NetconfNotification netconfNotification = HoneycombNotificationToNetconfTranslatorModule
65 .notificationToXml(notification, moduleInfoBackedContext.getSchemaContext());
67 final String notificationString = netconfNotification.toString();
68 Assert.assertThat(notificationString, CoreMatchers.containsString("<netconf-session-start"));
69 Assert.assertThat(notificationString, CoreMatchers.containsString("<username>user</username>"));
70 Assert.assertThat(notificationString, CoreMatchers.containsString("eventTime"));
73 private static ModuleInfoBackedContext getModuleInfoBackedCOntext() {
74 final ModuleInfoBackedContext moduleInfoBackedContext = ModuleInfoBackedContext.create();
75 final YangModuleInfo ietfNetconfNotifModuleInfo =
76 org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.netconf.notifications.rev120206.$YangModuleInfoImpl
78 moduleInfoBackedContext.registerModuleInfo(ietfNetconfNotifModuleInfo);
79 return moduleInfoBackedContext;