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.assertTrue;
13 import java.io.IOException;
14 import java.net.URISyntaxException;
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
18 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
19 import org.opendaylight.yangtools.sal.binding.model.api.Type;
20 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
21 import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
22 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
24 public class BindingGeneratorImplTest {
27 public void choiceNodeGenerationTest() throws IOException,
28 YangSyntaxErrorException, URISyntaxException {
29 File resourceFile = new File(getClass().getResource(
30 "/binding-generator-impl-test/choice-test.yang").toURI());
31 File resourceDir = resourceFile.getParentFile();
33 YangParserImpl parser = YangParserImpl.getInstance();
34 SchemaContext context = parser.parseFile(resourceFile, resourceDir);
36 List<Type> generateTypes = new BindingGeneratorImpl(false)
37 .generateTypes(context);
39 GeneratedType choiceTestData = null;
40 GeneratedType myRootContainer = null;
41 GeneratedType myList = null;
42 GeneratedType myContainer = null;
43 GeneratedType myList2 = null;
44 GeneratedType myContainer2 = null;
46 for (Type type : generateTypes) {
47 switch (type.getName()) {
48 case "ChoiceTestData":
49 choiceTestData = (GeneratedType) type;
51 case "Myrootcontainer":
52 myRootContainer = (GeneratedType) type;
55 myList = (GeneratedType) type;
58 myList2 = (GeneratedType) type;
61 myContainer = (GeneratedType) type;
64 myContainer2 = (GeneratedType) type;
69 assertNotNull(choiceTestData);
70 assertNotNull(myRootContainer);
71 assertNotNull(myList);
72 assertNotNull(myContainer);
73 assertNotNull(myList2);
74 assertNotNull(myContainer2);
76 List<Type> implements1 = myContainer.getImplements();
77 Type childOfParamType = null;
78 for (Type type : implements1) {
79 if (type.getName().equals("ChildOf")) {
80 childOfParamType = ((ParameterizedType) type)
81 .getActualTypeArguments()[0];
85 assertNotNull(childOfParamType);
86 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
88 implements1 = myList.getImplements();
89 childOfParamType = null;
90 for (Type type : implements1) {
91 if (type.getName().equals("ChildOf")) {
92 childOfParamType = ((ParameterizedType) type)
93 .getActualTypeArguments()[0];
97 assertNotNull(childOfParamType);
98 assertTrue(childOfParamType.getName().equals("ChoiceTestData"));
100 implements1 = myContainer2.getImplements();
101 childOfParamType = null;
102 for (Type type : implements1) {
103 if (type.getName().equals("ChildOf")) {
104 childOfParamType = ((ParameterizedType) type)
105 .getActualTypeArguments()[0];
109 assertNotNull(childOfParamType);
110 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));
112 implements1 = myList2.getImplements();
113 childOfParamType = null;
114 for (Type type : implements1) {
115 if (type.getName().equals("ChildOf")) {
116 childOfParamType = ((ParameterizedType) type)
117 .getActualTypeArguments()[0];
121 assertNotNull(childOfParamType);
122 assertTrue(childOfParamType.getName().equals("Myrootcontainer"));