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.yangtools.sal.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.yangtools.sal.binding.model.api.GeneratedType;
23 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
24 import org.opendaylight.yangtools.sal.binding.model.api.Type;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
29 public class BindingGeneratorImplTest {
32 public void isisTotpologyStatementParserTest() throws IOException,
33 URISyntaxException, ReactorException {
34 final InputStream topo = getClass().getResourceAsStream("/isis-topology/network-topology@2013-10-21.yang");
35 final InputStream isis = getClass().getResourceAsStream("/isis-topology/isis-topology@2013-10-21.yang");
36 final InputStream l3 = getClass().getResourceAsStream("/isis-topology/l3-unicast-igp-topology@2013-10-21.yang");
38 SchemaContext context = YangParserTestUtils.parseYangStreams(ImmutableList.of(isis, l3, topo));
39 assertNotNull(context);
41 List<Type> generateTypes = new BindingGeneratorImpl(false)
42 .generateTypes(context);
44 assertFalse(generateTypes.isEmpty());
48 public void choiceNodeGenerationTest() throws IOException,
49 URISyntaxException, ReactorException {
50 File resourceFile = new File(getClass().getResource(
51 "/binding-generator-impl-test/choice-test.yang").toURI());
53 SchemaContext context = YangParserTestUtils.parseYangSources(resourceFile);
55 List<Type> generateTypes = new BindingGeneratorImpl(false)
56 .generateTypes(context);
58 GeneratedType choiceTestData = null;
59 GeneratedType myRootContainer = null;
60 GeneratedType myList = null;
61 GeneratedType myContainer = null;
62 GeneratedType myList2 = null;
63 GeneratedType myContainer2 = null;
65 for (Type type : generateTypes) {
66 switch (type.getName()) {
67 case "ChoiceTestData":
68 choiceTestData = (GeneratedType) type;
70 case "Myrootcontainer":
71 myRootContainer = (GeneratedType) type;
74 myList = (GeneratedType) type;
77 myList2 = (GeneratedType) type;
80 myContainer = (GeneratedType) type;
83 myContainer2 = (GeneratedType) type;
88 assertNotNull(choiceTestData);
89 assertNotNull(myRootContainer);
90 assertNotNull(myList);
91 assertNotNull(myContainer);
92 assertNotNull(myList2);
93 assertNotNull(myContainer2);
95 List<Type> implements1 = myContainer.getImplements();
96 Type childOfParamType = null;
97 for (Type type : implements1) {
98 if (type.getName().equals("ChildOf")) {
99 childOfParamType = ((ParameterizedType) type)
100 .getActualTypeArguments()[0];
104 assertNotNull(childOfParamType);
105 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
107 implements1 = myList.getImplements();
108 childOfParamType = null;
109 for (Type type : implements1) {
110 if (type.getName().equals("ChildOf")) {
111 childOfParamType = ((ParameterizedType) type)
112 .getActualTypeArguments()[0];
116 assertNotNull(childOfParamType);
117 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
119 implements1 = myContainer2.getImplements();
120 childOfParamType = null;
121 for (Type type : implements1) {
122 if (type.getName().equals("ChildOf")) {
123 childOfParamType = ((ParameterizedType) type)
124 .getActualTypeArguments()[0];
128 assertNotNull(childOfParamType);
129 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
131 implements1 = myList2.getImplements();
132 childOfParamType = null;
133 for (Type type : implements1) {
134 if (type.getName().equals("ChildOf")) {
135 childOfParamType = ((ParameterizedType) type)
136 .getActualTypeArguments()[0];
140 assertNotNull(childOfParamType);
141 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
146 public void notificationGenerationTest() throws IOException, URISyntaxException, ReactorException {
147 File resourceFile = new File(getClass().getResource(
148 "/binding-generator-impl-test/notification-test.yang").toURI());
150 SchemaContext context = YangParserTestUtils.parseYangSources(resourceFile);
152 List<Type> generateTypes = new BindingGeneratorImpl(false)
153 .generateTypes(context);
155 GeneratedType foo = null;
156 for (Type type : generateTypes) {
157 if (type.getName().equals("Foo")) {
158 foo = (GeneratedType) type;
164 Type dataObject = null;
165 List<Type> impl = foo.getImplements();
166 for (Type type : impl) {
167 switch (type.getName()) {
178 assertNotNull(dataObject);