import static java.util.Objects.requireNonNull;
+import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.Maps;
import java.util.Collection;
-import java.util.Collections;
import java.util.Map;
import java.util.Optional;
+import java.util.Set;
import org.eclipse.jdt.annotation.NonNull;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ActionDefinition;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
import org.opendaylight.yangtools.yang.model.api.MustDefinition;
import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
*/
@Deprecated(since = "2.0.0", forRemoval = true)
public final class NodeContainerProxy implements ContainerSchemaNode {
-
- private final Map<QName, ? extends DataSchemaNode> childNodes;
- private final QName qualifiedName;
private final Collection<? extends AugmentationSchemaNode> availableAugmentations;
-
- public NodeContainerProxy(final QName qualifiedName, final Map<QName, ? extends DataSchemaNode> childNodes,
- final Collection<? extends AugmentationSchemaNode> availableAugmentations) {
+ private final @NonNull Map<QName, ? extends DataSchemaNode> childNodes;
+ private final @NonNull SchemaPath path;
+ private final @NonNull QName qname;
+
+ @VisibleForTesting
+ NodeContainerProxy(final QName qname, final SchemaPath path, final Map<QName, ? extends DataSchemaNode> childNodes,
+ final Collection<? extends AugmentationSchemaNode> availableAugmentations) {
+ this.qname = requireNonNull(qname);
+ this.path = requireNonNull(path);
+ this.childNodes = requireNonNull(childNodes);
this.availableAugmentations = availableAugmentations;
- this.childNodes = requireNonNull(childNodes, "childNodes");
- this.qualifiedName = qualifiedName;
}
- public NodeContainerProxy(final QName qualifiedName, final Collection<? extends DataSchemaNode> childNodes) {
- this(qualifiedName, asMap(childNodes), Collections.emptySet());
+ public static @NonNull NodeContainerProxy ofModelContext(final QName qname, final EffectiveModelContext context) {
+ return new NodeContainerProxy(qname, SchemaPath.ROOT, asMap(context.getChildNodes()), Set.of());
}
- public NodeContainerProxy(final QName qualifiedName, final Collection<? extends DataSchemaNode> childNodes,
- final Collection<? extends AugmentationSchemaNode> availableAugmentations) {
- this(qualifiedName, asMap(childNodes), availableAugmentations);
+ public static @NonNull NodeContainerProxy ofNotification(final NotificationDefinition notification) {
+ return new NodeContainerProxy(notification.getQName(), notification.getPath(),
+ asMap(notification.getChildNodes()), notification.getAvailableAugmentations());
}
private static Map<QName, ? extends DataSchemaNode> asMap(final Collection<? extends DataSchemaNode> childNodes) {
@Override
public Collection<? extends TypeDefinition<?>> getTypeDefinitions() {
- return Collections.emptySet();
+ return Set.of();
}
@Override
@Override
public Collection<? extends GroupingDefinition> getGroupings() {
- return Collections.emptySet();
+ return Set.of();
}
@Override
@Override
public Collection<? extends UsesNode> getUses() {
- return Collections.emptySet();
+ return Set.of();
}
@Override
@Override
public QName getQName() {
- return qualifiedName;
+ return qname;
}
@Override
@Deprecated
public SchemaPath getPath() {
- throw new UnsupportedOperationException();
+ return path;
}
@Override
@Override
public Collection<? extends NotificationDefinition> getNotifications() {
- return Collections.emptySet();
+ return Set.of();
}
@Override
public Collection<? extends ActionDefinition> getActions() {
- return Collections.emptySet();
+ return Set.of();
}
@Override
@Override
public Collection<? extends @NonNull MustDefinition> getMustConstraints() {
- return Collections.emptySet();
+ return Set.of();
}
@Override
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.netconf.util;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.containsInAnyOrder;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.junit.MockitoJUnitRunner;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
+public class NodeContainerProxyTest {
+ private static final QName QNAME = QName.create("ns", "2016-10-19", "name");
+ private static final QName NODE_1_QNAME = QName.create(QNAME, "node-1");
+ private static final QName NODE_2_QNAME = QName.create(QNAME, "node-2");
+
+ @Mock
+ private AugmentationSchemaNode augSchema1;
+ @Mock
+ private AugmentationSchemaNode augSchema2;
+ @Mock
+ private DataSchemaNode schemaNode1;
+ @Mock
+ private DataSchemaNode schemaNode2;
+ private NodeContainerProxy proxy;
+
+ @Before
+ public void setUp() {
+ proxy = new NodeContainerProxy(QNAME, SchemaPath.SAME,
+ Map.of(NODE_1_QNAME, schemaNode1, NODE_2_QNAME, schemaNode2), Set.of(augSchema1, augSchema2));
+ }
+
+ @Test
+ public void testGetQName() {
+ assertSame(QNAME, proxy.getQName());
+ }
+
+ @Test
+ @Deprecated
+ public void testGetPath() {
+ assertSame(SchemaPath.SAME, proxy.getPath());
+ }
+
+ @Test
+ public void testGetChildNodes() {
+ final var children = proxy.getChildNodes();
+ assertEquals(2, children.size());
+ assertThat(children, containsInAnyOrder(schemaNode1, schemaNode2));
+ }
+
+ @Test
+ public void testGetAvailableAugmentations() {
+ final var augmentations = proxy.getAvailableAugmentations();
+ assertEquals(2, augmentations.size());
+ assertThat(augmentations, containsInAnyOrder(augSchema1, augSchema2));
+ }
+
+ @Test
+ public void testFindDataChildByName() {
+ assertEquals(Optional.of(schemaNode1), proxy.findDataChildByName(NODE_1_QNAME));
+ }
+
+ @Test
+ public void testGetTypeDefinitions() {
+ assertEmpty(proxy.getTypeDefinitions());
+ }
+
+ @Test
+ public void testGetGroupings() {
+ assertEmpty(proxy.getGroupings());
+ }
+
+ @Test
+ public void testGetUses() {
+ assertEmpty(proxy.getUses());
+ }
+
+ @Test
+ public void testGetUnknownSchemaNodes() {
+ assertEmpty(proxy.getUnknownSchemaNodes());
+ }
+
+ @Test
+ public void testIsPresenceContainer() {
+ assertThrows(UnsupportedOperationException.class, () -> proxy.isPresenceContainer());
+ }
+
+ @Test
+ @Deprecated
+ public void testIsAugmenting() {
+ assertThrows(UnsupportedOperationException.class, () -> proxy.isAugmenting());
+ }
+
+ @Test
+ @Deprecated
+ public void testIsAddedByUses() {
+ assertThrows(UnsupportedOperationException.class, () -> proxy.isAddedByUses());
+ }
+
+ @Test
+ public void testIsConfiguration() {
+ assertThrows(UnsupportedOperationException.class, () -> proxy.isConfiguration());
+ }
+
+ @Test
+ public void testGetDescription() {
+ assertThrows(UnsupportedOperationException.class, () -> proxy.getDescription());
+ }
+
+ @Test
+ public void testGetReference() {
+ assertThrows(UnsupportedOperationException.class, () -> proxy.getReference());
+ }
+
+ @Test
+ public void testGetStatus() {
+ assertThrows(UnsupportedOperationException.class, () -> proxy.getStatus());
+ }
+
+ static void assertEmpty(final Collection<?> coll) {
+ assertEquals(List.of(), List.copyOf(coll));
+ }
+}
+++ /dev/null
-/*
- * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.netconf.sal.connect.netconf.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Optional;
-import java.util.Set;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
-import org.opendaylight.netconf.util.NodeContainerProxy;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class NodeContainerProxyTest {
-
- private static final QName QNAME = QName.create("ns", "2016-10-19", "name");
- private static final QName NODE_1_QNAME = QName.create(QNAME, "node-1");
- private static final QName NODE_2_QNAME = QName.create(QNAME, "node-2");
- @Mock
- private AugmentationSchemaNode augSchema1;
- @Mock
- private AugmentationSchemaNode augSchema2;
- @Mock
- private DataSchemaNode schemaNode1;
- @Mock
- private DataSchemaNode schemaNode2;
- private NodeContainerProxy proxy;
-
- @Before
- public void setUp() throws Exception {
- final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
- childNodes.put(NODE_1_QNAME, schemaNode1);
- childNodes.put(NODE_2_QNAME, schemaNode2);
- final Set<AugmentationSchemaNode> augmentations = new HashSet<>();
- augmentations.add(augSchema1);
- augmentations.add(augSchema2);
- proxy = new NodeContainerProxy(QNAME, childNodes, augmentations);
- }
-
- @Test
- public void testGetQName() throws Exception {
- assertEquals(QNAME, proxy.getQName());
- }
-
- @Test
- public void testGetChildNodes() throws Exception {
- assertEquals(2, proxy.getChildNodes().size());
- }
-
- @Test
- public void testGetAvailableAugmentations() throws Exception {
- final Collection<? extends AugmentationSchemaNode> augmentations = proxy.getAvailableAugmentations();
- assertEquals(2, augmentations.size());
- assertTrue(augmentations.contains(augSchema1));
- assertTrue(augmentations.contains(augSchema2));
- }
-
- @Test
- public void testFindDataChildByName() {
- assertEquals(Optional.of(schemaNode1), proxy.findDataChildByName(NODE_1_QNAME));
- }
-
- @Test
- public void testGetTypeDefinitions() throws Exception {
- assertTrue(proxy.getTypeDefinitions().isEmpty());
- }
-
- @Test
- public void testGetGroupings() throws Exception {
- assertTrue(proxy.getGroupings().isEmpty());
- }
-
- @Test
- public void testGetUses() throws Exception {
- assertTrue(proxy.getUses().isEmpty());
- }
-
- @Test
- public void testGetUnknownSchemaNodes() throws Exception {
- assertTrue(proxy.getUnknownSchemaNodes().isEmpty());
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testIsPresenceContainer() throws Exception {
- proxy.isPresenceContainer();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testIsAugmenting() throws Exception {
- proxy.isAugmenting();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testIsAddedByUses() throws Exception {
- proxy.isAddedByUses();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testIsConfiguration() throws Exception {
- proxy.isConfiguration();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetPath() throws Exception {
- proxy.getPath();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetDescription() throws Exception {
- proxy.getDescription();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetReference() throws Exception {
- proxy.getReference();
- }
-
- @Test(expected = UnsupportedOperationException.class)
- public void testGetStatus() throws Exception {
- proxy.getStatus();
- }
-
-}