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.test.util.YangParserTestUtils;
22 public class BindingGeneratorImplTest {
25 public void isisTotpologyStatementParserTest() {
26 List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResources(
27 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 assertFalse(generateTypes.isEmpty());
34 public void choiceNodeGenerationTest() {
35 List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
36 "/binding-generator-impl-test/choice-test.yang"));
38 GeneratedType choiceTestData = null;
39 GeneratedType myRootContainer = null;
40 GeneratedType myList = null;
41 GeneratedType myContainer = null;
42 GeneratedType myList2 = null;
43 GeneratedType myContainer2 = null;
45 for (Type type : generateTypes) {
46 switch (type.getName()) {
47 case "ChoiceTestData":
48 choiceTestData = (GeneratedType) type;
50 case "Myrootcontainer":
51 myRootContainer = (GeneratedType) type;
54 myList = (GeneratedType) type;
57 myList2 = (GeneratedType) type;
60 myContainer = (GeneratedType) type;
63 myContainer2 = (GeneratedType) type;
70 assertNotNull(choiceTestData);
71 assertNotNull(myRootContainer);
72 assertNotNull(myList);
73 assertNotNull(myContainer);
74 assertNotNull(myList2);
75 assertNotNull(myContainer2);
77 List<Type> implements1 = myContainer.getImplements();
78 Type childOfParamType = null;
79 for (Type type : implements1) {
80 if (type.getName().equals("ChildOf")) {
81 childOfParamType = ((ParameterizedType) type)
82 .getActualTypeArguments()[0];
86 assertNotNull(childOfParamType);
87 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
89 implements1 = myList.getImplements();
90 childOfParamType = null;
91 for (Type type : implements1) {
92 if (type.getName().equals("ChildOf")) {
93 childOfParamType = ((ParameterizedType) type)
94 .getActualTypeArguments()[0];
98 assertNotNull(childOfParamType);
99 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
101 implements1 = myContainer2.getImplements();
102 childOfParamType = null;
103 for (Type type : implements1) {
104 if (type.getName().equals("ChildOf")) {
105 childOfParamType = ((ParameterizedType) type)
106 .getActualTypeArguments()[0];
110 assertNotNull(childOfParamType);
111 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
113 implements1 = myList2.getImplements();
114 childOfParamType = null;
115 for (Type type : implements1) {
116 if (type.getName().equals("ChildOf")) {
117 childOfParamType = ((ParameterizedType) type)
118 .getActualTypeArguments()[0];
122 assertNotNull(childOfParamType);
123 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
128 public void notificationGenerationTest() {
129 List<Type> generateTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
130 "/binding-generator-impl-test/notification-test.yang"));
132 GeneratedType foo = null;
133 for (Type type : generateTypes) {
134 if (type.getName().equals("Foo")) {
135 foo = (GeneratedType) type;
141 Type dataObject = null;
142 List<Type> impl = foo.getImplements();
143 for (Type type : impl) {
144 switch (type.getName()) {
157 assertNotNull(dataObject);