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;
10 import static org.junit.Assert.assertNotNull;
11 import static org.junit.Assert.assertNull;
12 import static org.junit.Assert.assertTrue;
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
19 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
20 import org.opendaylight.yangtools.sal.binding.model.api.Type;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
23 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
25 public class BindingGeneratorImplTest {
28 public void choiceNodeGenerationTest() throws IOException,
29 YangSyntaxErrorException, URISyntaxException {
30 File resourceFile = new File(getClass().getResource(
31 "/binding-generator-impl-test/choice-test.yang").toURI());
32 File resourceDir = resourceFile.getParentFile();
34 YangParserImpl parser = YangParserImpl.getInstance();
35 SchemaContext context = parser.parseFile(resourceFile, resourceDir);
37 List<Type> generateTypes = new BindingGeneratorImpl(false)
38 .generateTypes(context);
40 GeneratedType choiceTestData = null;
41 GeneratedType myRootContainer = null;
42 GeneratedType myList = null;
43 GeneratedType myContainer = null;
44 GeneratedType myList2 = null;
45 GeneratedType myContainer2 = null;
47 for (Type type : generateTypes) {
48 switch (type.getName()) {
49 case "ChoiceTestData":
50 choiceTestData = (GeneratedType) type;
52 case "Myrootcontainer":
53 myRootContainer = (GeneratedType) type;
56 myList = (GeneratedType) type;
59 myList2 = (GeneratedType) type;
62 myContainer = (GeneratedType) type;
65 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() throws IOException, YangSyntaxErrorException, URISyntaxException {
129 File resourceFile = new File(getClass().getResource("/binding-generator-impl-test/notification-test.yang")
131 File resourceDir = resourceFile.getParentFile();
133 YangParserImpl parser = YangParserImpl.getInstance();
134 SchemaContext context = parser.parseFile(resourceFile, resourceDir);
136 List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(context);
138 GeneratedType foo = null;
139 for (Type type : generateTypes) {
140 if (type.getName().equals("Foo")) {
141 foo = (GeneratedType) type;
147 Type dataObject = null;
148 List<Type> impl = foo.getImplements();
149 for (Type type : impl) {
150 switch (type.getName()) {
161 assertNotNull(dataObject);