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 com.google.common.collect.ImmutableList;
17 import java.io.IOException;
18 import java.io.InputStream;
19 import java.net.URISyntaxException;
20 import java.util.List;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
23 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
24 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
25 import org.opendaylight.mdsal.binding.model.api.Type;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
28 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
30 public class BindingGeneratorImplTest {
33 public void isisTotpologyStatementParserTest() throws IOException,
34 URISyntaxException, ReactorException {
35 final InputStream topo = getClass().getResourceAsStream("/isis-topology/network-topology@2013-10-21.yang");
36 final InputStream isis = getClass().getResourceAsStream("/isis-topology/isis-topology@2013-10-21.yang");
37 final InputStream l3 = getClass().getResourceAsStream("/isis-topology/l3-unicast-igp-topology@2013-10-21.yang");
39 SchemaContext context = YangParserTestUtils.parseYangStreams(ImmutableList.of(isis, l3, topo));
40 assertNotNull(context);
42 List<Type> generateTypes = new BindingGeneratorImpl(false)
43 .generateTypes(context);
45 assertFalse(generateTypes.isEmpty());
49 public void choiceNodeGenerationTest() throws IOException,
50 URISyntaxException, ReactorException {
51 File resourceFile = new File(getClass().getResource(
52 "/binding-generator-impl-test/choice-test.yang").toURI());
54 SchemaContext context = YangParserTestUtils.parseYangSources(resourceFile);
56 List<Type> generateTypes = new BindingGeneratorImpl(false)
57 .generateTypes(context);
59 GeneratedType choiceTestData = null;
60 GeneratedType myRootContainer = null;
61 GeneratedType myList = null;
62 GeneratedType myContainer = null;
63 GeneratedType myList2 = null;
64 GeneratedType myContainer2 = null;
66 for (Type type : generateTypes) {
67 switch (type.getName()) {
68 case "ChoiceTestData":
69 choiceTestData = (GeneratedType) type;
71 case "Myrootcontainer":
72 myRootContainer = (GeneratedType) type;
75 myList = (GeneratedType) type;
78 myList2 = (GeneratedType) type;
81 myContainer = (GeneratedType) type;
84 myContainer2 = (GeneratedType) type;
89 assertNotNull(choiceTestData);
90 assertNotNull(myRootContainer);
91 assertNotNull(myList);
92 assertNotNull(myContainer);
93 assertNotNull(myList2);
94 assertNotNull(myContainer2);
96 List<Type> implements1 = myContainer.getImplements();
97 Type childOfParamType = null;
98 for (Type type : implements1) {
99 if (type.getName().equals("ChildOf")) {
100 childOfParamType = ((ParameterizedType) type)
101 .getActualTypeArguments()[0];
105 assertNotNull(childOfParamType);
106 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
108 implements1 = myList.getImplements();
109 childOfParamType = null;
110 for (Type type : implements1) {
111 if (type.getName().equals("ChildOf")) {
112 childOfParamType = ((ParameterizedType) type)
113 .getActualTypeArguments()[0];
117 assertNotNull(childOfParamType);
118 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
120 implements1 = myContainer2.getImplements();
121 childOfParamType = null;
122 for (Type type : implements1) {
123 if (type.getName().equals("ChildOf")) {
124 childOfParamType = ((ParameterizedType) type)
125 .getActualTypeArguments()[0];
129 assertNotNull(childOfParamType);
130 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
132 implements1 = myList2.getImplements();
133 childOfParamType = null;
134 for (Type type : implements1) {
135 if (type.getName().equals("ChildOf")) {
136 childOfParamType = ((ParameterizedType) type)
137 .getActualTypeArguments()[0];
141 assertNotNull(childOfParamType);
142 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
147 public void notificationGenerationTest() throws IOException, URISyntaxException, ReactorException {
148 File resourceFile = new File(getClass().getResource(
149 "/binding-generator-impl-test/notification-test.yang").toURI());
151 SchemaContext context = YangParserTestUtils.parseYangSources(resourceFile);
153 List<Type> generateTypes = new BindingGeneratorImpl(false)
154 .generateTypes(context);
156 GeneratedType foo = null;
157 for (Type type : generateTypes) {
158 if (type.getName().equals("Foo")) {
159 foo = (GeneratedType) type;
165 Type dataObject = null;
166 List<Type> impl = foo.getImplements();
167 for (Type type : impl) {
168 switch (type.getName()) {
179 assertNotNull(dataObject);