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.mdsal.binding.generator.impl;
10 import static org.junit.Assert.assertTrue;
12 import java.util.List;
13 import org.junit.Test;
14 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
15 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
16 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
17 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
19 public class GenerateInnerClassForBitsAndUnionInLeavesTest {
21 public void testInnerClassCreationForBitsAndUnionsInLeafes() {
22 final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
23 "/bit_and_union_in_leaf.yang"));
24 assertTrue(genTypes != null);
26 boolean parentContainerFound = false;
27 boolean bitLeafTOFound = false;
28 boolean unionLeafTOFound = false;
30 boolean firstBitPropertyFound = false;
31 boolean secondBitPropertyFound = false;
32 boolean thirdBitPropertyFound = false;
34 boolean firstBitPropertyTypeOK = false;
35 boolean secondBitPropertyTypeOK = false;
36 boolean thirdBitPropertyTypeOK = false;
38 boolean int32UnionPropertyFound = false;
39 boolean int32UnionPropertyTypeOK = false;
40 boolean stringUnionPropertyFound = false;
41 boolean stringUnionPropertyTypeOK = false;
42 boolean uint8UnionPropertyFound = false;
43 boolean uint8UnionPropertyTypeOK = false;
45 for (GeneratedType type : genTypes) {
46 if (!(type instanceof GeneratedTransferObject)) {
47 if (type.getName().equals("ParentContainer")) {
48 parentContainerFound = true;
49 GeneratedType parentContainer = type;
50 List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
51 for (GeneratedType genType : enclosedTypes) {
52 if (genType instanceof GeneratedTransferObject) {
53 if (genType.getName().equals("BitLeaf")) {
54 bitLeafTOFound = true;
55 GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType;
57 List<GeneratedProperty> bitLeafProperties = bitLeafTO.getProperties();
58 for (GeneratedProperty bitLeafProperty : bitLeafProperties) {
59 String bitLeafPropertyType = bitLeafProperty.getReturnType().getName();
60 if (bitLeafProperty.getName().equals("firstBit")) {
61 firstBitPropertyFound = true;
62 if (bitLeafPropertyType.equals("Boolean")) {
63 firstBitPropertyTypeOK = true;
65 } else if (bitLeafProperty.getName().equals("secondBit")) {
66 secondBitPropertyFound = true;
67 if (bitLeafPropertyType.equals("Boolean")) {
68 secondBitPropertyTypeOK = true;
70 } else if (bitLeafProperty.getName().equals("thirdBit")) {
71 thirdBitPropertyFound = true;
72 if (bitLeafPropertyType.equals("Boolean")) {
73 thirdBitPropertyTypeOK = true;
79 } else if (genType.getName().equals("UnionLeaf")) {
80 unionLeafTOFound = true;
81 GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;
83 List<GeneratedProperty> unionLeafProperties = unionLeafTO.getProperties();
84 for (GeneratedProperty unionLeafProperty : unionLeafProperties) {
85 String unionLeafPropertyType = unionLeafProperty.getReturnType().getName();
86 if (unionLeafProperty.getName().equals("int32")) {
87 int32UnionPropertyFound = true;
88 if (unionLeafPropertyType.equals("Integer")) {
89 int32UnionPropertyTypeOK = true;
91 } else if (unionLeafProperty.getName().equals("string")) {
92 stringUnionPropertyFound = true;
93 if (unionLeafPropertyType.equals("String")) {
94 stringUnionPropertyTypeOK = true;
96 } else if (unionLeafProperty.getName().equals("uint8")) {
97 uint8UnionPropertyFound = true;
98 if (unionLeafPropertyType.equals("Uint8")) {
99 uint8UnionPropertyTypeOK = true;
111 assertTrue(parentContainerFound);
113 assertTrue(bitLeafTOFound);
114 assertTrue(firstBitPropertyFound);
115 assertTrue(secondBitPropertyFound);
116 assertTrue(thirdBitPropertyFound);
118 assertTrue(firstBitPropertyTypeOK);
119 assertTrue(secondBitPropertyTypeOK);
120 assertTrue(thirdBitPropertyTypeOK);
122 assertTrue(unionLeafTOFound);
123 assertTrue(int32UnionPropertyFound);
124 assertTrue(int32UnionPropertyTypeOK);
125 assertTrue(stringUnionPropertyFound);
126 assertTrue(stringUnionPropertyTypeOK);
127 assertTrue(uint8UnionPropertyFound);
128 assertTrue(uint8UnionPropertyTypeOK);