Implement NodeContainerProxy.getPath()
[netconf.git] / netconf / netconf-util / src / test / java / org / opendaylight / netconf / util / NodeContainerProxyTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.netconf.util;
9
10 import static org.hamcrest.MatcherAssert.assertThat;
11 import static org.hamcrest.Matchers.containsInAnyOrder;
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertSame;
14 import static org.junit.Assert.assertThrows;
15
16 import java.util.Collection;
17 import java.util.List;
18 import java.util.Map;
19 import java.util.Optional;
20 import java.util.Set;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.mockito.Mock;
25 import org.mockito.junit.MockitoJUnitRunner;
26 import org.opendaylight.yangtools.yang.common.QName;
27 import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
28 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
29 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
30
31 @RunWith(MockitoJUnitRunner.StrictStubs.class)
32 public class NodeContainerProxyTest {
33     private static final QName QNAME = QName.create("ns", "2016-10-19", "name");
34     private static final QName NODE_1_QNAME = QName.create(QNAME, "node-1");
35     private static final QName NODE_2_QNAME = QName.create(QNAME, "node-2");
36
37     @Mock
38     private AugmentationSchemaNode augSchema1;
39     @Mock
40     private AugmentationSchemaNode augSchema2;
41     @Mock
42     private DataSchemaNode schemaNode1;
43     @Mock
44     private DataSchemaNode schemaNode2;
45     private NodeContainerProxy proxy;
46
47     @Before
48     public void setUp() {
49         proxy = new NodeContainerProxy(QNAME, SchemaPath.SAME,
50             Map.of(NODE_1_QNAME, schemaNode1, NODE_2_QNAME, schemaNode2), Set.of(augSchema1, augSchema2));
51     }
52
53     @Test
54     public void testGetQName() {
55         assertSame(QNAME, proxy.getQName());
56     }
57
58     @Test
59     @Deprecated
60     public void testGetPath() {
61         assertSame(SchemaPath.SAME, proxy.getPath());
62     }
63
64     @Test
65     public void testGetChildNodes() {
66         final var children = proxy.getChildNodes();
67         assertEquals(2, children.size());
68         assertThat(children, containsInAnyOrder(schemaNode1, schemaNode2));
69     }
70
71     @Test
72     public void testGetAvailableAugmentations() {
73         final var augmentations = proxy.getAvailableAugmentations();
74         assertEquals(2, augmentations.size());
75         assertThat(augmentations, containsInAnyOrder(augSchema1, augSchema2));
76     }
77
78     @Test
79     public void testFindDataChildByName() {
80         assertEquals(Optional.of(schemaNode1), proxy.findDataChildByName(NODE_1_QNAME));
81     }
82
83     @Test
84     public void testGetTypeDefinitions() {
85         assertEmpty(proxy.getTypeDefinitions());
86     }
87
88     @Test
89     public void testGetGroupings() {
90         assertEmpty(proxy.getGroupings());
91     }
92
93     @Test
94     public void testGetUses() {
95         assertEmpty(proxy.getUses());
96     }
97
98     @Test
99     public void testGetUnknownSchemaNodes() {
100         assertEmpty(proxy.getUnknownSchemaNodes());
101     }
102
103     @Test
104     public void testIsPresenceContainer() {
105         assertThrows(UnsupportedOperationException.class, () -> proxy.isPresenceContainer());
106     }
107
108     @Test
109     @Deprecated
110     public void testIsAugmenting() {
111         assertThrows(UnsupportedOperationException.class, () -> proxy.isAugmenting());
112     }
113
114     @Test
115     @Deprecated
116     public void testIsAddedByUses() {
117         assertThrows(UnsupportedOperationException.class, () -> proxy.isAddedByUses());
118     }
119
120     @Test
121     public void testIsConfiguration() {
122         assertThrows(UnsupportedOperationException.class, () -> proxy.isConfiguration());
123     }
124
125     @Test
126     public void testGetDescription() {
127         assertThrows(UnsupportedOperationException.class, () -> proxy.getDescription());
128     }
129
130     @Test
131     public void testGetReference() {
132         assertThrows(UnsupportedOperationException.class, () -> proxy.getReference());
133     }
134
135     @Test
136     public void testGetStatus() {
137         assertThrows(UnsupportedOperationException.class, () -> proxy.getStatus());
138     }
139
140     static void assertEmpty(final Collection<?> coll) {
141         assertEquals(List.of(), List.copyOf(coll));
142     }
143 }