BUG-2310 - widen yang model for netconf-node.
[controller.git] / opendaylight / md-sal / sal-netconf-connector / src / test / java / org / opendaylight / controller / sal / connect / netconf / listener / NetconfSessionPreferencesTest.java
1 package org.opendaylight.controller.sal.connect.netconf.listener;
2
3 import static org.hamcrest.CoreMatchers.hasItem;
4 import static org.junit.Assert.assertEquals;
5 import static org.junit.Assert.assertThat;
6
7 import com.google.common.collect.Lists;
8 import java.util.List;
9 import org.junit.Test;
10 import org.opendaylight.controller.sal.connect.netconf.util.NetconfMessageTransformUtil;
11 import org.opendaylight.yangtools.yang.common.QName;
12
13 public class NetconfSessionPreferencesTest {
14
15     @Test
16     public void testMerge() throws Exception {
17         final List<String> caps1 = Lists.newArrayList(
18                 "namespace:1?module=module1&revision=2012-12-12",
19                 "namespace:2?module=module2&amp;revision=2012-12-12",
20                 "urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring?module=ietf-netconf-monitoring&amp;revision=2010-10-04",
21                 "urn:ietf:params:netconf:base:1.0",
22                 "urn:ietf:params:netconf:capability:rollback-on-error:1.0"
23         );
24         final NetconfSessionPreferences sessionCaps1 = NetconfSessionPreferences.fromStrings(caps1);
25         assertCaps(sessionCaps1, 2, 3);
26
27         final List<String> caps2 = Lists.newArrayList(
28                 "namespace:3?module=module3&revision=2012-12-12",
29                 "namespace:4?module=module4&revision=2012-12-12",
30                 "randomNonModuleCap"
31         );
32         final NetconfSessionPreferences sessionCaps2 = NetconfSessionPreferences.fromStrings(caps2);
33         assertCaps(sessionCaps2, 1, 2);
34
35         final NetconfSessionPreferences merged = sessionCaps1.replaceModuleCaps(sessionCaps2);
36         assertCaps(merged, 2, 2 + 1 /*Preserved monitoring*/);
37         for (final QName qName : sessionCaps2.getModuleBasedCaps()) {
38             assertThat(merged.getModuleBasedCaps(), hasItem(qName));
39         }
40         assertThat(merged.getModuleBasedCaps(), hasItem(NetconfMessageTransformUtil.IETF_NETCONF_MONITORING));
41
42         assertThat(merged.getNonModuleCaps(), hasItem("urn:ietf:params:netconf:base:1.0"));
43         assertThat(merged.getNonModuleCaps(), hasItem("urn:ietf:params:netconf:capability:rollback-on-error:1.0"));
44     }
45
46     @Test
47     public void testCapabilityNoRevision() throws Exception {
48         final List<String> caps1 = Lists.newArrayList(
49                 "namespace:2?module=module2",
50                 "namespace:2?module=module2&amp;revision=2012-12-12",
51                 "namespace:2?module=module1&amp;RANDOMSTRING;revision=2013-12-12",
52                 "namespace:2?module=module2&amp;RANDOMSTRING;revision=2013-12-12" // This one should be ignored(same as first), since revision is in wrong format
53         );
54
55         final NetconfSessionPreferences sessionCaps1 = NetconfSessionPreferences.fromStrings(caps1);
56         assertCaps(sessionCaps1, 0, 3);
57     }
58
59     private void assertCaps(final NetconfSessionPreferences sessionCaps1, final int nonModuleCaps, final int moduleCaps) {
60         assertEquals(nonModuleCaps, sessionCaps1.getNonModuleCaps().size());
61         assertEquals(moduleCaps, sessionCaps1.getModuleBasedCaps().size());
62     }
63 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.