ccfb4bb9d53f87938ce6c2eb717efb21a31daee5
[hc2vpp.git] /
1 /*
2  * Copyright (c) 2016 Cisco and/or its affiliates.
3  *
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:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.opendaylight.yang.gen.v1.urn.honeycomb.params.xml.ns.yang.notification.impl.rev160601;
17
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;
33
34 public class NoetificationToNetconfModuleTest {
35
36     private final DOMNotification notification =  new DOMNotification() {
37
38         private QName qname = NetconfSessionStart.QNAME;
39         private YangInstanceIdentifier.NodeIdentifier nodeIdentifier =
40             new YangInstanceIdentifier.NodeIdentifier(NetconfSessionStart.QNAME);
41
42         @Nonnull
43         @Override
44         public SchemaPath getType() {
45             return SchemaPath.create(true, qname);
46         }
47
48         @Nonnull
49         @Override
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"))
56                 .build();
57         }
58     };
59
60     @Test
61     public void notificationToXml() throws Exception {
62         final ModuleInfoBackedContext moduleInfoBackedContext = getModuleInfoBackedCOntext();
63
64         final NetconfNotification netconfNotification = HoneycombNotificationToNetconfTranslatorModule
65             .notificationToXml(notification, moduleInfoBackedContext.getSchemaContext());
66
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"));
71     }
72
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
77                 .getInstance();
78         moduleInfoBackedContext.registerModuleInfo(ietfNetconfNotifModuleInfo);
79         return moduleInfoBackedContext;
80     }
81 }