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.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertNull;
13 import static org.junit.Assert.assertTrue;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
18 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
19 import org.opendaylight.mdsal.binding.model.api.Type;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class BindingGeneratorImplTest {
26 public void isisTotpologyStatementParserTest() {
27 SchemaContext context = YangParserTestUtils.parseYangResources(BindingGeneratorImplTest.class,
28 "/isis-topology/network-topology@2013-10-21.yang", "/isis-topology/isis-topology@2013-10-21.yang",
29 "/isis-topology/l3-unicast-igp-topology@2013-10-21.yang");
30 assertNotNull(context);
32 List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
33 assertFalse(generateTypes.isEmpty());
37 public void choiceNodeGenerationTest() {
38 SchemaContext context = YangParserTestUtils.parseYangResource("/binding-generator-impl-test/choice-test.yang");
40 List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
42 GeneratedType choiceTestData = null;
43 GeneratedType myRootContainer = null;
44 GeneratedType myList = null;
45 GeneratedType myContainer = null;
46 GeneratedType myList2 = null;
47 GeneratedType myContainer2 = null;
49 for (Type type : generateTypes) {
50 switch (type.getName()) {
51 case "ChoiceTestData":
52 choiceTestData = (GeneratedType) type;
54 case "Myrootcontainer":
55 myRootContainer = (GeneratedType) type;
58 myList = (GeneratedType) type;
61 myList2 = (GeneratedType) type;
64 myContainer = (GeneratedType) type;
67 myContainer2 = (GeneratedType) type;
74 assertNotNull(choiceTestData);
75 assertNotNull(myRootContainer);
76 assertNotNull(myList);
77 assertNotNull(myContainer);
78 assertNotNull(myList2);
79 assertNotNull(myContainer2);
81 List<Type> implements1 = myContainer.getImplements();
82 Type childOfParamType = null;
83 for (Type type : implements1) {
84 if (type.getName().equals("ChildOf")) {
85 childOfParamType = ((ParameterizedType) type)
86 .getActualTypeArguments()[0];
90 assertNotNull(childOfParamType);
91 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
93 implements1 = myList.getImplements();
94 childOfParamType = null;
95 for (Type type : implements1) {
96 if (type.getName().equals("ChildOf")) {
97 childOfParamType = ((ParameterizedType) type)
98 .getActualTypeArguments()[0];
102 assertNotNull(childOfParamType);
103 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
105 implements1 = myContainer2.getImplements();
106 childOfParamType = null;
107 for (Type type : implements1) {
108 if (type.getName().equals("ChildOf")) {
109 childOfParamType = ((ParameterizedType) type)
110 .getActualTypeArguments()[0];
114 assertNotNull(childOfParamType);
115 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
117 implements1 = myList2.getImplements();
118 childOfParamType = null;
119 for (Type type : implements1) {
120 if (type.getName().equals("ChildOf")) {
121 childOfParamType = ((ParameterizedType) type)
122 .getActualTypeArguments()[0];
126 assertNotNull(childOfParamType);
127 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
132 public void notificationGenerationTest() {
133 SchemaContext context = YangParserTestUtils.parseYangResource(
134 "/binding-generator-impl-test/notification-test.yang");
136 List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
138 GeneratedType foo = null;
139 for (Type type : generateTypes) {
140 if (type.getName().equals("Foo")) {
141 foo = (GeneratedType) type;
147 Type dataObject = null;
148 List<Type> impl = foo.getImplements();
149 for (Type type : impl) {
150 switch (type.getName()) {
163 assertNotNull(dataObject);