2 * Copyright (c) 2014 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.assertTrue;
12 import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl;
16 import java.util.List;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
19 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
20 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
21 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
22 import org.opendaylight.yangtools.sal.binding.model.api.Type;
23 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 public class GenerateInnerClassForBitsAndUnionInLeavesTest {
28 public void testInnerClassCreationForBitsAndUnionsInLeafes() throws Exception {
29 final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI();
31 final SchemaContext context = RetestUtils.parseYangSources(new File(yangTypesPath));
32 assertTrue(context != null);
34 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
35 final List<Type> genTypes = bindingGen.generateTypes(context);
36 assertTrue(genTypes != null);
38 boolean parentContainerFound = false;
39 boolean bitLeafTOFound = false;
40 boolean unionLeafTOFound = false;
42 boolean firstBitPropertyFound = false;
43 boolean secondBitPropertyFound = false;
44 boolean thirdBitPropertyFound = false;
46 boolean firstBitPropertyTypeOK = false;
47 boolean secondBitPropertyTypeOK = false;
48 boolean thirdBitPropertyTypeOK = false;
50 boolean int32UnionPropertyFound = false;
51 boolean int32UnionPropertyTypeOK = false;
52 boolean stringUnionPropertyFound = false;
53 boolean stringUnionPropertyTypeOK = false;
54 boolean uint8UnionPropertyFound = false;
55 boolean uint8UnionPropertyTypeOK = false;
57 for (Type type : genTypes) {
58 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
59 if (type.getName().equals("ParentContainer")) {
60 parentContainerFound = true;
61 GeneratedType parentContainer = (GeneratedType) type;
62 List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
63 for (GeneratedType genType : enclosedTypes) {
64 if (genType instanceof GeneratedTransferObject) {
65 if (genType.getName().equals("BitLeaf")) {
66 bitLeafTOFound = true;
67 GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType;
69 List<GeneratedProperty> bitLeafProperties = bitLeafTO.getProperties();
70 for (GeneratedProperty bitLeafProperty : bitLeafProperties) {
71 String bitLeafPropertyType = bitLeafProperty.getReturnType().getName();
72 if (bitLeafProperty.getName().equals("firstBit")) {
73 firstBitPropertyFound = true;
74 if (bitLeafPropertyType.equals("Boolean")) {
75 firstBitPropertyTypeOK = true;
77 } else if (bitLeafProperty.getName().equals("secondBit")) {
78 secondBitPropertyFound = true;
79 if (bitLeafPropertyType.equals("Boolean")) {
80 secondBitPropertyTypeOK = true;
82 } else if (bitLeafProperty.getName().equals("thirdBit")) {
83 thirdBitPropertyFound = true;
84 if (bitLeafPropertyType.equals("Boolean")) {
85 thirdBitPropertyTypeOK = true;
91 } else if (genType.getName().equals("UnionLeaf")) {
92 unionLeafTOFound = true;
93 GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;
95 List<GeneratedProperty> unionLeafProperties = unionLeafTO.getProperties();
96 for (GeneratedProperty unionLeafProperty : unionLeafProperties) {
97 String unionLeafPropertyType = unionLeafProperty.getReturnType().getName();
98 if (unionLeafProperty.getName().equals("int32")) {
99 int32UnionPropertyFound = true;
100 if (unionLeafPropertyType.equals("Integer")) {
101 int32UnionPropertyTypeOK = true;
103 } else if (unionLeafProperty.getName().equals("string")) {
104 stringUnionPropertyFound = true;
105 if (unionLeafPropertyType.equals("String")) {
106 stringUnionPropertyTypeOK = true;
108 } else if (unionLeafProperty.getName().equals("uint8")) {
109 uint8UnionPropertyFound = true;
110 if (unionLeafPropertyType.equals("Short")) {
111 uint8UnionPropertyTypeOK = true;
123 assertTrue(parentContainerFound);
125 assertTrue(bitLeafTOFound);
126 assertTrue(firstBitPropertyFound);
127 assertTrue(secondBitPropertyFound);
128 assertTrue(thirdBitPropertyFound);
130 assertTrue(firstBitPropertyTypeOK);
131 assertTrue(secondBitPropertyTypeOK);
132 assertTrue(thirdBitPropertyTypeOK);
134 assertTrue(unionLeafTOFound);
135 assertTrue(int32UnionPropertyFound);
136 assertTrue(int32UnionPropertyTypeOK);
137 assertTrue(stringUnionPropertyFound);
138 assertTrue(stringUnionPropertyTypeOK);
139 assertTrue(uint8UnionPropertyFound);
140 assertTrue(uint8UnionPropertyTypeOK);