2 * Copyright (c) 2019 PANTHEON.tech, s.r.o. 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.mdsal.binding.generator.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
13 import com.google.common.collect.Iterables;
14 import java.util.Arrays;
15 import java.util.Collection;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.mdsal.binding.yang.types.GroupingDefinitionDependencySort;
20 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
21 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24 public class Mdsal448Test {
26 public void groupingSortIncludesActions() {
27 final EffectiveModelContext context = YangParserTestUtils.parseYangResource("/mdsal448.yang");
28 final Collection<? extends GroupingDefinition> groupings = context.findModule("mdsal448").get().getGroupings();
29 assertEquals(2, groupings.size());
31 final List<GroupingDefinition> ordered = sortGroupings(Iterables.get(groupings, 0),
32 Iterables.get(groupings, 1));
33 assertEquals(2, ordered.size());
34 // "the-grouping" needs to be first
35 assertEquals("the-grouping", ordered.get(0).getQName().getLocalName());
36 assertEquals("action-grouping", ordered.get(1).getQName().getLocalName());
38 // Sort needs to be stable
39 final List<GroupingDefinition> reverse = sortGroupings(Iterables.get(groupings, 1),
40 Iterables.get(groupings, 0));
41 assertEquals(ordered, reverse);
43 final List<Type> types = DefaultBindingGenerator.generateFor(context);
45 assertEquals(9, types.size());
48 private static List<GroupingDefinition> sortGroupings(final GroupingDefinition... groupings) {
49 return new GroupingDefinitionDependencySort().sort(Arrays.asList(groupings));