2 * Copyright (c) 2015 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.stmt.parser.retest;
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;
14 import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl;
15 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
16 import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
17 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
18 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
19 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
20 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
22 import java.io.IOException;
23 import java.net.URISyntaxException;
24 import java.util.List;
25 import org.junit.Test;
26 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
27 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
28 import org.opendaylight.yangtools.sal.binding.model.api.Type;
29 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
30 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
32 public class BindingGeneratorImplTest {
34 private static final YangStatementSourceImpl NETWORK_TOPOLOGY_20131021 = new YangStatementSourceImpl(
35 "/isis-topology/network-topology@2013-10-21.yang", false);
37 private static final YangStatementSourceImpl ISIS_20131021 = new YangStatementSourceImpl(
38 "/isis-topology/isis-topology@2013-10-21.yang", false);
40 private static final YangStatementSourceImpl L3_20131021 = new YangStatementSourceImpl(
41 "/isis-topology/l3-unicast-igp-topology@2013-10-21.yang", false);
44 public void isisTotpologyStatementParserTest() throws IOException,
45 YangSyntaxErrorException, URISyntaxException, SourceException,
47 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
50 reactor.addSources(ISIS_20131021, L3_20131021,
51 NETWORK_TOPOLOGY_20131021);
53 EffectiveSchemaContext context = reactor.buildEffective();
54 assertNotNull(context);
56 List<Type> generateTypes = new BindingGeneratorImpl(false)
57 .generateTypes(context);
59 assertFalse(generateTypes.isEmpty());
63 public void choiceNodeGenerationTest() throws IOException,
64 YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException {
65 File resourceFile = new File(getClass().getResource(
66 "/binding-generator-impl-test/choice-test.yang").toURI());
68 SchemaContext context = RetestUtils.parseYangSources(resourceFile);
70 List<Type> generateTypes = new BindingGeneratorImpl(false)
71 .generateTypes(context);
73 GeneratedType choiceTestData = null;
74 GeneratedType myRootContainer = null;
75 GeneratedType myList = null;
76 GeneratedType myContainer = null;
77 GeneratedType myList2 = null;
78 GeneratedType myContainer2 = null;
80 for (Type type : generateTypes) {
81 switch (type.getName()) {
82 case "ChoiceTestData":
83 choiceTestData = (GeneratedType) type;
85 case "Myrootcontainer":
86 myRootContainer = (GeneratedType) type;
89 myList = (GeneratedType) type;
92 myList2 = (GeneratedType) type;
95 myContainer = (GeneratedType) type;
98 myContainer2 = (GeneratedType) type;
103 assertNotNull(choiceTestData);
104 assertNotNull(myRootContainer);
105 assertNotNull(myList);
106 assertNotNull(myContainer);
107 assertNotNull(myList2);
108 assertNotNull(myContainer2);
110 List<Type> implements1 = myContainer.getImplements();
111 Type childOfParamType = null;
112 for (Type type : implements1) {
113 if (type.getName().equals("ChildOf")) {
114 childOfParamType = ((ParameterizedType) type)
115 .getActualTypeArguments()[0];
119 assertNotNull(childOfParamType);
120 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
122 implements1 = myList.getImplements();
123 childOfParamType = null;
124 for (Type type : implements1) {
125 if (type.getName().equals("ChildOf")) {
126 childOfParamType = ((ParameterizedType) type)
127 .getActualTypeArguments()[0];
131 assertNotNull(childOfParamType);
132 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
134 implements1 = myContainer2.getImplements();
135 childOfParamType = null;
136 for (Type type : implements1) {
137 if (type.getName().equals("ChildOf")) {
138 childOfParamType = ((ParameterizedType) type)
139 .getActualTypeArguments()[0];
143 assertNotNull(childOfParamType);
144 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
146 implements1 = myList2.getImplements();
147 childOfParamType = null;
148 for (Type type : implements1) {
149 if (type.getName().equals("ChildOf")) {
150 childOfParamType = ((ParameterizedType) type)
151 .getActualTypeArguments()[0];
155 assertNotNull(childOfParamType);
156 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
161 public void notificationGenerationTest() throws IOException,
162 YangSyntaxErrorException, URISyntaxException, SourceException, ReactorException {
163 File resourceFile = new File(getClass().getResource(
164 "/binding-generator-impl-test/notification-test.yang").toURI());
166 SchemaContext context = RetestUtils.parseYangSources(resourceFile);
168 List<Type> generateTypes = new BindingGeneratorImpl(false)
169 .generateTypes(context);
171 GeneratedType foo = null;
172 for (Type type : generateTypes) {
173 if (type.getName().equals("Foo")) {
174 foo = (GeneratedType) type;
180 Type dataObject = null;
181 List<Type> impl = foo.getImplements();
182 for (Type type : impl) {
183 switch (type.getName()) {
194 assertNotNull(dataObject);