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.mdsal.binding.model.api.Type;
18 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
19 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
21 public class GenerateInnerClassForBitsAndUnionInLeavesTest {
24 public void testInnerClassCreationForBitsAndUnionsInLeafes() {
25 final SchemaContext context = YangParserTestUtils.parseYangResource("/bit_and_union_in_leaf.yang");
26 assertTrue(context != null);
28 final List<Type> genTypes = DefaultBindingGenerator.generateFor(context);
29 assertTrue(genTypes != null);
31 boolean parentContainerFound = false;
32 boolean bitLeafTOFound = false;
33 boolean unionLeafTOFound = false;
35 boolean firstBitPropertyFound = false;
36 boolean secondBitPropertyFound = false;
37 boolean thirdBitPropertyFound = false;
39 boolean firstBitPropertyTypeOK = false;
40 boolean secondBitPropertyTypeOK = false;
41 boolean thirdBitPropertyTypeOK = false;
43 boolean int32UnionPropertyFound = false;
44 boolean int32UnionPropertyTypeOK = false;
45 boolean stringUnionPropertyFound = false;
46 boolean stringUnionPropertyTypeOK = false;
47 boolean uint8UnionPropertyFound = false;
48 boolean uint8UnionPropertyTypeOK = false;
50 for (Type type : genTypes) {
51 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
52 if (type.getName().equals("ParentContainer")) {
53 parentContainerFound = true;
54 GeneratedType parentContainer = (GeneratedType) type;
55 List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
56 for (GeneratedType genType : enclosedTypes) {
57 if (genType instanceof GeneratedTransferObject) {
58 if (genType.getName().equals("BitLeaf")) {
59 bitLeafTOFound = true;
60 GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType;
62 List<GeneratedProperty> bitLeafProperties = bitLeafTO.getProperties();
63 for (GeneratedProperty bitLeafProperty : bitLeafProperties) {
64 String bitLeafPropertyType = bitLeafProperty.getReturnType().getName();
65 if (bitLeafProperty.getName().equals("firstBit")) {
66 firstBitPropertyFound = true;
67 if (bitLeafPropertyType.equals("Boolean")) {
68 firstBitPropertyTypeOK = true;
70 } else if (bitLeafProperty.getName().equals("secondBit")) {
71 secondBitPropertyFound = true;
72 if (bitLeafPropertyType.equals("Boolean")) {
73 secondBitPropertyTypeOK = true;
75 } else if (bitLeafProperty.getName().equals("thirdBit")) {
76 thirdBitPropertyFound = true;
77 if (bitLeafPropertyType.equals("Boolean")) {
78 thirdBitPropertyTypeOK = true;
84 } else if (genType.getName().equals("UnionLeaf")) {
85 unionLeafTOFound = true;
86 GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;
88 List<GeneratedProperty> unionLeafProperties = unionLeafTO.getProperties();
89 for (GeneratedProperty unionLeafProperty : unionLeafProperties) {
90 String unionLeafPropertyType = unionLeafProperty.getReturnType().getName();
91 if (unionLeafProperty.getName().equals("int32")) {
92 int32UnionPropertyFound = true;
93 if (unionLeafPropertyType.equals("Integer")) {
94 int32UnionPropertyTypeOK = true;
96 } else if (unionLeafProperty.getName().equals("string")) {
97 stringUnionPropertyFound = true;
98 if (unionLeafPropertyType.equals("String")) {
99 stringUnionPropertyTypeOK = true;
101 } else if (unionLeafProperty.getName().equals("uint8")) {
102 uint8UnionPropertyFound = true;
103 if (unionLeafPropertyType.equals("Uint8")) {
104 uint8UnionPropertyTypeOK = true;
116 assertTrue(parentContainerFound);
118 assertTrue(bitLeafTOFound);
119 assertTrue(firstBitPropertyFound);
120 assertTrue(secondBitPropertyFound);
121 assertTrue(thirdBitPropertyFound);
123 assertTrue(firstBitPropertyTypeOK);
124 assertTrue(secondBitPropertyTypeOK);
125 assertTrue(thirdBitPropertyTypeOK);
127 assertTrue(unionLeafTOFound);
128 assertTrue(int32UnionPropertyFound);
129 assertTrue(int32UnionPropertyTypeOK);
130 assertTrue(stringUnionPropertyFound);
131 assertTrue(stringUnionPropertyTypeOK);
132 assertTrue(uint8UnionPropertyFound);
133 assertTrue(uint8UnionPropertyTypeOK);