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.mdsal.binding.generator.impl;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
14 import java.util.List;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
17 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
21 public class BindingGeneratorImplTest {
23 public void isisTotpologyStatementParserTest() {
24 List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
25 BindingGeneratorImplTest.class,
26 "/isis-topology/network-topology@2013-10-21.yang", "/isis-topology/isis-topology@2013-10-21.yang",
27 "/isis-topology/l3-unicast-igp-topology@2013-10-21.yang"));
28 assertEquals(9, generateTypes.size());
32 public void choiceNodeGenerationTest() {
33 List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
34 "/binding-generator-impl-test/choice-test.yang"));
36 GeneratedType choiceTestData = null;
37 GeneratedType myRootContainer = null;
38 GeneratedType myList = null;
39 GeneratedType myContainer = null;
40 GeneratedType myList2 = null;
41 GeneratedType myContainer2 = null;
43 for (GeneratedType type : generateTypes) {
44 switch (type.getName()) {
45 case "ChoiceTestData":
46 choiceTestData = type;
48 case "Myrootcontainer":
49 myRootContainer = type;
68 assertNotNull(choiceTestData);
69 assertNotNull(myRootContainer);
70 assertNotNull(myList);
71 assertNotNull(myContainer);
72 assertNotNull(myList2);
73 assertNotNull(myContainer2);
75 Type childOfParamType = null;
76 for (Type type : myContainer.getImplements()) {
77 if (type.getName().equals("ChildOf")) {
78 childOfParamType = ((ParameterizedType) type).getActualTypeArguments()[0];
82 assertNotNull(childOfParamType);
83 assertEquals("ChoiceTestData", childOfParamType.getName());
85 childOfParamType = null;
86 for (Type type : myList.getImplements()) {
87 if (type.getName().equals("ChildOf")) {
88 childOfParamType = ((ParameterizedType) type).getActualTypeArguments()[0];
92 assertNotNull(childOfParamType);
93 assertEquals("ChoiceTestData", childOfParamType.getName());
95 childOfParamType = null;
96 for (Type type : myContainer2.getImplements()) {
97 if (type.getName().equals("ChildOf")) {
98 childOfParamType = ((ParameterizedType) type).getActualTypeArguments()[0];
102 assertNotNull(childOfParamType);
103 assertEquals("Myrootcontainer", childOfParamType.getName());
105 childOfParamType = null;
106 for (Type type : myList2.getImplements()) {
107 if (type.getName().equals("ChildOf")) {
108 childOfParamType = ((ParameterizedType) type).getActualTypeArguments()[0];
112 assertNotNull(childOfParamType);
113 assertEquals("Myrootcontainer", childOfParamType.getName());
117 public void notificationGenerationTest() {
118 List<GeneratedType> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
119 "/binding-generator-impl-test/notification-test.yang"));
121 GeneratedType foo = null;
122 for (GeneratedType type : generateTypes) {
123 if (type.getName().equals("Foo")) {
130 Type dataObject = null;
131 for (Type type : foo.getImplements()) {
132 switch (type.getName()) {
145 assertNotNull(dataObject);
149 public void testBaseYangTypes() {
150 final List<GeneratedType> types = DefaultBindingGenerator.generateFor(
151 YangParserTestUtils.parseYangResource("/base-yang-types.yang"));
152 assertEquals(19, types.size());