2 * Copyright (c) 2016 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.netconf.util;
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;
16 import java.util.Collection;
17 import java.util.List;
19 import java.util.Optional;
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;
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");
38 private AugmentationSchemaNode augSchema1;
40 private AugmentationSchemaNode augSchema2;
42 private DataSchemaNode schemaNode1;
44 private DataSchemaNode schemaNode2;
45 private NodeContainerProxy proxy;
49 proxy = new NodeContainerProxy(QNAME, SchemaPath.SAME,
50 Map.of(NODE_1_QNAME, schemaNode1, NODE_2_QNAME, schemaNode2), Set.of(augSchema1, augSchema2));
54 public void testGetQName() {
55 assertSame(QNAME, proxy.getQName());
60 public void testGetPath() {
61 assertSame(SchemaPath.SAME, proxy.getPath());
65 public void testGetChildNodes() {
66 final var children = proxy.getChildNodes();
67 assertEquals(2, children.size());
68 assertThat(children, containsInAnyOrder(schemaNode1, schemaNode2));
72 public void testGetAvailableAugmentations() {
73 final var augmentations = proxy.getAvailableAugmentations();
74 assertEquals(2, augmentations.size());
75 assertThat(augmentations, containsInAnyOrder(augSchema1, augSchema2));
79 public void testFindDataChildByName() {
80 assertEquals(Optional.of(schemaNode1), proxy.findDataChildByName(NODE_1_QNAME));
84 public void testGetTypeDefinitions() {
85 assertEmpty(proxy.getTypeDefinitions());
89 public void testGetGroupings() {
90 assertEmpty(proxy.getGroupings());
94 public void testGetUses() {
95 assertEmpty(proxy.getUses());
99 public void testGetUnknownSchemaNodes() {
100 assertEmpty(proxy.getUnknownSchemaNodes());
104 public void testIsPresenceContainer() {
105 assertThrows(UnsupportedOperationException.class, () -> proxy.isPresenceContainer());
110 public void testIsAugmenting() {
111 assertThrows(UnsupportedOperationException.class, () -> proxy.isAugmenting());
116 public void testIsAddedByUses() {
117 assertThrows(UnsupportedOperationException.class, () -> proxy.isAddedByUses());
121 public void testIsConfiguration() {
122 assertThrows(UnsupportedOperationException.class, () -> proxy.isConfiguration());
126 public void testGetDescription() {
127 assertThrows(UnsupportedOperationException.class, () -> proxy.getDescription());
131 public void testGetReference() {
132 assertThrows(UnsupportedOperationException.class, () -> proxy.getReference());
136 public void testGetStatus() {
137 assertThrows(UnsupportedOperationException.class, () -> proxy.getStatus());
140 static void assertEmpty(final Collection<?> coll) {
141 assertEquals(List.of(), List.copyOf(coll));