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;
72 assertNotNull(choiceTestData);
73 assertNotNull(myRootContainer);
74 assertNotNull(myList);
75 assertNotNull(myContainer);
76 assertNotNull(myList2);
77 assertNotNull(myContainer2);
79 List<Type> implements1 = myContainer.getImplements();
80 Type childOfParamType = null;
81 for (Type type : implements1) {
82 if (type.getName().equals("ChildOf")) {
83 childOfParamType = ((ParameterizedType) type)
84 .getActualTypeArguments()[0];
88 assertNotNull(childOfParamType);
89 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
91 implements1 = myList.getImplements();
92 childOfParamType = null;
93 for (Type type : implements1) {
94 if (type.getName().equals("ChildOf")) {
95 childOfParamType = ((ParameterizedType) type)
96 .getActualTypeArguments()[0];
100 assertNotNull(childOfParamType);
101 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
103 implements1 = myContainer2.getImplements();
104 childOfParamType = null;
105 for (Type type : implements1) {
106 if (type.getName().equals("ChildOf")) {
107 childOfParamType = ((ParameterizedType) type)
108 .getActualTypeArguments()[0];
112 assertNotNull(childOfParamType);
113 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
115 implements1 = myList2.getImplements();
116 childOfParamType = null;
117 for (Type type : implements1) {
118 if (type.getName().equals("ChildOf")) {
119 childOfParamType = ((ParameterizedType) type)
120 .getActualTypeArguments()[0];
124 assertNotNull(childOfParamType);
125 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
130 public void notificationGenerationTest() {
131 SchemaContext context = YangParserTestUtils.parseYangResource(
132 "/binding-generator-impl-test/notification-test.yang");
134 List<Type> generateTypes = new BindingGeneratorImpl().generateTypes(context);
136 GeneratedType foo = null;
137 for (Type type : generateTypes) {
138 if (type.getName().equals("Foo")) {
139 foo = (GeneratedType) type;
145 Type dataObject = null;
146 List<Type> impl = foo.getImplements();
147 for (Type type : impl) {
148 switch (type.getName()) {
159 assertNotNull(dataObject);