From c00753629e6f7b55d4e47f50d12d6eec47adc4fe Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Sat, 16 Oct 2021 16:52:56 +0200 Subject: [PATCH] Remove mdsal.binding.yang.types This package is not exported by us and therefore not accessible by anyone. We have just ditched its last user, ditch the package as well, along with its test suite. Change-Id: Ida72524105d0134395c06c48a994fc86893567d0 Signed-off-by: Robert Varga --- .../GroupingDefinitionDependencySort.java | 146 ------------------ .../binding/yang/types/NodeWrappedType.java | 57 ------- .../binding/yang/types/package-info.java | 9 -- .../binding/generator/impl/Mdsal448Test.java | 51 ------ .../GroupingDefinitionDependencySortTest.java | 93 ----------- .../yang/types/NodeWrappedTypeTest.java | 33 ---- .../src/test/resources/mdsal448.yang | 35 ----- 7 files changed, 424 deletions(-) delete mode 100644 binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySort.java delete mode 100644 binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedType.java delete mode 100644 binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/package-info.java delete mode 100644 binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal448Test.java delete mode 100644 binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySortTest.java delete mode 100644 binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedTypeTest.java delete mode 100644 binding/mdsal-binding-generator/src/test/resources/mdsal448.yang diff --git a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySort.java b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySort.java deleted file mode 100644 index 0d98d1271f..0000000000 --- a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySort.java +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Copyright (c) 2013 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.mdsal.binding.yang.types; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; -import org.opendaylight.yangtools.util.TopologicalSort; -import org.opendaylight.yangtools.util.TopologicalSort.Node; -import org.opendaylight.yangtools.yang.model.api.ActionDefinition; -import org.opendaylight.yangtools.yang.model.api.ActionNodeContainer; -import org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode; -import org.opendaylight.yangtools.yang.model.api.CaseSchemaNode; -import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode; -import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; -import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -import org.opendaylight.yangtools.yang.model.api.NotificationDefinition; -import org.opendaylight.yangtools.yang.model.api.NotificationNodeContainer; -import org.opendaylight.yangtools.yang.model.api.UsesNode; - -public final class GroupingDefinitionDependencySort { - private GroupingDefinitionDependencySort() { - // Hidden on purpose - } - - /** - * Sorts a set of {@code groupings} according to the mutual dependencies. Elements of {@code groupings} are first - * transformed to {@link Node} interfaces and then are sorted by {@link TopologicalSort#sort(Set) sort()} method of - * {@code TopologicalSort}.
- * - * Definition of dependency relation:
- * The first {@code GroupingDefinition} object (in this context) depends on second {@code GroupingDefinition} object - * if the first one contains in its set of {@code UsesNode} (obtained through {@link DataNodeContainer#getUses()}) - * a reference to the second one. - *
- * - * @param groupings set of grouping definition which should be sorted according to mutual dependencies - * @return list of grouping definitions which are sorted by mutual dependencies - * @throws IllegalArgumentException if {@code groupingDefinitions} - * - */ - public static List sort(final Collection groupings) { - if (groupings == null) { - throw new IllegalArgumentException("Set of Type Definitions cannot be NULL!"); - } - - final List sortedNodes = TopologicalSort.sort(groupingDefinitionsToNodes(groupings)); - final List resultGroupingDefinitions = new ArrayList<>(sortedNodes.size()); - for (Node node : sortedNodes) { - NodeWrappedType nodeWrappedType = (NodeWrappedType) node; - resultGroupingDefinitions.add((GroupingDefinition) nodeWrappedType.getWrappedType()); - } - return resultGroupingDefinitions; - } - - /** - * Wraps every grouping definition to node type and adds to every node information about dependencies. The map - * with mapping from schema path (represents grouping definition) to node is created. For every created node - * (next nodeFrom) is for its wrapped grouping definition passed the set of its uses nodes through. - * For every uses node is found its wrapping node (next as nodeTo). This dependency relationship between - * nodeFrom and all found nodesTo is modeled with creating of one edge from nodeFrom to nodeTo. - * - * @param groupings set of grouping definitions which will be wrapped to nodes - * @return set of nodes where every one contains wrapped grouping definition - */ - private static Set groupingDefinitionsToNodes(final Collection groupings) { - final Map nodeMap = new HashMap<>(); - final Set resultNodes = new HashSet<>(); - - for (final GroupingDefinition grouping : groupings) { - final Node node = new NodeWrappedType(grouping); - nodeMap.put(grouping, node); - resultNodes.add(node); - } - - for (final Node node : resultNodes) { - final NodeWrappedType nodeWrappedType = (NodeWrappedType) node; - final GroupingDefinition grouping = (GroupingDefinition) nodeWrappedType.getWrappedType(); - - Set usesNodes = getAllUsesNodes(grouping); - - for (UsesNode usesNode : usesNodes) { - Node nodeTo = nodeMap.get(usesNode.getSourceGrouping()); - if (nodeTo != null) { - nodeWrappedType.addEdge(nodeTo); - } - } - } - - return resultNodes; - } - - /** - * Returns the set of the uses nodes which are get from uses in container, from uses in groupings - * inside container and from uses inside child nodes of the container. - * - * @param container data node container which can contain some uses of grouping - * @return set of uses nodes which were find in container. - */ - private static Set getAllUsesNodes(final DataNodeContainer container) { - Set ret = new HashSet<>(); - Collection usesNodes = container.getUses(); - ret.addAll(usesNodes); - - for (UsesNode usesNode : usesNodes) { - for (AugmentationSchemaNode augment : usesNode.getAugmentations()) { - ret.addAll(getAllUsesNodes(augment)); - } - } - for (GroupingDefinition groupingDefinition : container.getGroupings()) { - ret.addAll(getAllUsesNodes(groupingDefinition)); - } - for (DataSchemaNode childNode : container.getChildNodes()) { - if (childNode instanceof DataNodeContainer) { - ret.addAll(getAllUsesNodes((DataNodeContainer) childNode)); - } else if (childNode instanceof ChoiceSchemaNode) { - for (CaseSchemaNode choiceCaseNode : ((ChoiceSchemaNode) childNode).getCases()) { - ret.addAll(getAllUsesNodes(choiceCaseNode)); - } - } - } - if (container instanceof ActionNodeContainer) { - for (ActionDefinition action : ((ActionNodeContainer) container).getActions()) { - ret.addAll(getAllUsesNodes(action.getInput())); - ret.addAll(getAllUsesNodes(action.getOutput())); - } - } - if (container instanceof NotificationNodeContainer) { - for (NotificationDefinition notification : ((NotificationNodeContainer) container).getNotifications()) { - ret.addAll(getAllUsesNodes(notification)); - } - } - - return ret; - } -} diff --git a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedType.java b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedType.java deleted file mode 100644 index 6ba79eb61f..0000000000 --- a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedType.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright (c) 2014 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.mdsal.binding.yang.types; - -import org.opendaylight.yangtools.util.TopologicalSort.NodeImpl; - -final class NodeWrappedType extends NodeImpl { - /** - * The payload which is saved inside Node. - */ - private final Object wrappedType; - - /** - * Create new instance of class NodeWrappedType. - * - * @param wrappedType object with payload data - */ - NodeWrappedType(final Object wrappedType) { - this.wrappedType = wrappedType; - } - - /** - * Gets payload from class. - * - * @return object with wrappedType - */ - Object getWrappedType() { - return wrappedType; - } - - @Override - public boolean equals(final Object obj) { - if (this == obj) { - return true; - } - if (!(obj instanceof NodeWrappedType)) { - return false; - } - NodeWrappedType nodeWrappedType = (NodeWrappedType) obj; - return wrappedType.equals(nodeWrappedType.wrappedType); - } - - @Override - public int hashCode() { - return wrappedType.hashCode(); - } - - @Override - public String toString() { - return "NodeWrappedType{" + "wrappedType=" + wrappedType + '}'; - } -} diff --git a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/package-info.java b/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/package-info.java deleted file mode 100644 index 90db40d2f9..0000000000 --- a/binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/yang/types/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (c) 2013 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.mdsal.binding.yang.types; \ No newline at end of file diff --git a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal448Test.java b/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal448Test.java deleted file mode 100644 index 056b350c87..0000000000 --- a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/generator/impl/Mdsal448Test.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.mdsal.binding.generator.impl; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import com.google.common.collect.Iterables; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import org.junit.Test; -import org.opendaylight.mdsal.binding.model.api.GeneratedType; -import org.opendaylight.mdsal.binding.yang.types.GroupingDefinitionDependencySort; -import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils; - -public class Mdsal448Test { - @Test - public void groupingSortIncludesActions() { - final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/mdsal448.yang"); - final Collection groupings = context.findModule("mdsal448").get().getGroupings(); - assertEquals(2, groupings.size()); - - final List ordered = sortGroupings(Iterables.get(groupings, 0), - Iterables.get(groupings, 1)); - assertEquals(2, ordered.size()); - // "the-grouping" needs to be first - assertEquals("the-grouping", ordered.get(0).getQName().getLocalName()); - assertEquals("action-grouping", ordered.get(1).getQName().getLocalName()); - - // Sort needs to be stable - final List reverse = sortGroupings(Iterables.get(groupings, 1), - Iterables.get(groupings, 0)); - assertEquals(ordered, reverse); - - final List types = DefaultBindingGenerator.generateFor(context); - assertNotNull(types); - assertEquals(9, types.size()); - } - - private static List sortGroupings(final GroupingDefinition... groupings) { - return GroupingDefinitionDependencySort.sort(Arrays.asList(groupings)); - } -} diff --git a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySortTest.java b/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySortTest.java deleted file mode 100644 index b6b21933fc..0000000000 --- a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/GroupingDefinitionDependencySortTest.java +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (c) 2014 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.mdsal.binding.yang.types; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThrows; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.GroupingDefinition; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; - -public class GroupingDefinitionDependencySortTest { - @Test - public void testSortMethod() { - - final List unsortedGroupingDefs = new ArrayList<>(); - - GroupingDefinition grp1 = mock(GroupingDefinition.class); - doReturn(SchemaPath.create(false, QName.create("", "Cont1"), QName.create("", "Cont2"))).when(grp1).getPath(); - doReturn(QName.create("", "leaf1")).when(grp1).getQName(); - doReturn(Collections.emptySet()).when(grp1).getUses(); - doReturn(Collections.emptySet()).when(grp1).getGroupings(); - doReturn(Collections.emptySet()).when(grp1).getChildNodes(); - doReturn(Collections.emptySet()).when(grp1).getActions(); - doReturn(Collections.emptySet()).when(grp1).getNotifications(); - - GroupingDefinition grp2 = mock(GroupingDefinition.class); - doReturn(SchemaPath.create(false, QName.create("", "Cont1"))).when(grp2).getPath(); - doReturn(QName.create("", "leaf2")).when(grp2).getQName(); - doReturn(Collections.emptySet()).when(grp2).getUses(); - doReturn(Collections.emptySet()).when(grp2).getGroupings(); - doReturn(Collections.emptySet()).when(grp2).getChildNodes(); - doReturn(Collections.emptySet()).when(grp2).getActions(); - doReturn(Collections.emptySet()).when(grp2).getNotifications(); - - GroupingDefinition grp3 = mock(GroupingDefinition.class); - doReturn(SchemaPath.create(false, QName.create("", "Cont1"), QName.create("", "Cont2"))).when(grp3).getPath(); - doReturn(QName.create("", "leaf3")).when(grp3).getQName(); - doReturn(Collections.emptySet()).when(grp3).getUses(); - doReturn(Collections.emptySet()).when(grp3).getGroupings(); - doReturn(Collections.emptySet()).when(grp3).getChildNodes(); - doReturn(Collections.emptySet()).when(grp3).getActions(); - doReturn(Collections.emptySet()).when(grp3).getNotifications(); - - GroupingDefinition grp4 = mock(GroupingDefinition.class); - doReturn(SchemaPath.create(false, QName.create("", "Cont1"), QName.create("", "Cont2"), - QName.create("", "List1"))).when(grp4).getPath(); - doReturn(QName.create("", "leaf4")).when(grp4).getQName(); - doReturn(Collections.emptySet()).when(grp4).getUses(); - doReturn(Collections.emptySet()).when(grp4).getGroupings(); - doReturn(Collections.emptySet()).when(grp4).getChildNodes(); - doReturn(Collections.emptySet()).when(grp4).getActions(); - doReturn(Collections.emptySet()).when(grp4).getNotifications(); - - GroupingDefinition grp5 = mock(GroupingDefinition.class); - doReturn(SchemaPath.create(false, QName.create("", "Cont1"))).when(grp5).getPath(); - doReturn(QName.create("", "leaf5")).when(grp5).getQName(); - doReturn(Collections.emptySet()).when(grp5).getUses(); - doReturn(Collections.emptySet()).when(grp5).getGroupings(); - doReturn(Collections.emptySet()).when(grp5).getChildNodes(); - doReturn(Collections.emptySet()).when(grp5).getActions(); - doReturn(Collections.emptySet()).when(grp5).getNotifications(); - - unsortedGroupingDefs.add(grp1); - unsortedGroupingDefs.add(grp1); - unsortedGroupingDefs.add(grp2); - unsortedGroupingDefs.add(grp3); - unsortedGroupingDefs.add(grp4); - unsortedGroupingDefs.add(grp5); - - List sortedGroupingDefs = GroupingDefinitionDependencySort.sort(unsortedGroupingDefs); - assertNotNull(sortedGroupingDefs); - } - - @Test - public void testNullSort() { - final IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, - () -> GroupingDefinitionDependencySort.sort(null)); - assertEquals("Set of Type Definitions cannot be NULL!", ex.getMessage()); - } -} diff --git a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedTypeTest.java b/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedTypeTest.java deleted file mode 100644 index 4dca2438c3..0000000000 --- a/binding/mdsal-binding-generator/src/test/java/org/opendaylight/mdsal/binding/yang/types/NodeWrappedTypeTest.java +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (c) 2014 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.mdsal.binding.yang.types; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import org.junit.Test; - -public class NodeWrappedTypeTest { - - @Test - public void test() { - final NodeWrappedType nwt1 = new NodeWrappedType("obj1"); - final NodeWrappedType nwt2 = new NodeWrappedType("obj2"); - final NodeWrappedType nwt3 = new NodeWrappedType("obj1"); - final String str = "obj3"; - - assertTrue("Node nwt1 should equal to itself.", nwt1.equals(nwt1)); - assertFalse("It can't be possible to compare nwt with string.", nwt1.equals(str)); - assertFalse("nwt1 shouldn't equal to nwt2.", nwt1.equals(nwt2)); - assertTrue("Node nwt1 should equal to nwt3.", nwt1.equals(nwt3)); - - assertEquals("toString method is returning incorrect value.", "NodeWrappedType{wrappedType=obj1}", - nwt1.toString()); - } -} diff --git a/binding/mdsal-binding-generator/src/test/resources/mdsal448.yang b/binding/mdsal-binding-generator/src/test/resources/mdsal448.yang deleted file mode 100644 index d2d1fc4870..0000000000 --- a/binding/mdsal-binding-generator/src/test/resources/mdsal448.yang +++ /dev/null @@ -1,35 +0,0 @@ -module mdsal448 { - yang-version "1.1"; - namespace "urn:example:test"; - prefix "test"; - - grouping the-grouping { - leaf the-leaf { - type string; - } - } - - grouping action-grouping { - action action-with-grouping { - input { - leaf leaf1 { - type string; - } - - uses the-grouping; - } - } - } - - container network { - list node { - key "id"; - - leaf id { - type string; - } - - uses action-grouping; - } - } -} -- 2.36.6