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.generator.api.BindingGenerator;
15 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
16 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
18 import org.opendaylight.mdsal.binding.model.api.Type;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
22 public class GenerateInnerClassForBitsAndUnionInLeavesTest {
25 public void testInnerClassCreationForBitsAndUnionsInLeafes() {
26 final SchemaContext context = YangParserTestUtils.parseYangResource("/bit_and_union_in_leaf.yang");
27 assertTrue(context != null);
29 final BindingGenerator bindingGen = new BindingGeneratorImpl();
30 final List<Type> genTypes = bindingGen.generateTypes(context);
31 assertTrue(genTypes != null);
33 boolean parentContainerFound = false;
34 boolean bitLeafTOFound = false;
35 boolean unionLeafTOFound = false;
37 boolean firstBitPropertyFound = false;
38 boolean secondBitPropertyFound = false;
39 boolean thirdBitPropertyFound = false;
41 boolean firstBitPropertyTypeOK = false;
42 boolean secondBitPropertyTypeOK = false;
43 boolean thirdBitPropertyTypeOK = false;
45 boolean int32UnionPropertyFound = false;
46 boolean int32UnionPropertyTypeOK = false;
47 boolean stringUnionPropertyFound = false;
48 boolean stringUnionPropertyTypeOK = false;
49 boolean uint8UnionPropertyFound = false;
50 boolean uint8UnionPropertyTypeOK = false;
52 for (Type type : genTypes) {
53 if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
54 if (type.getName().equals("ParentContainer")) {
55 parentContainerFound = true;
56 GeneratedType parentContainer = (GeneratedType) type;
57 List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
58 for (GeneratedType genType : enclosedTypes) {
59 if (genType instanceof GeneratedTransferObject) {
60 if (genType.getName().equals("BitLeaf")) {
61 bitLeafTOFound = true;
62 GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType;
64 List<GeneratedProperty> bitLeafProperties = bitLeafTO.getProperties();
65 for (GeneratedProperty bitLeafProperty : bitLeafProperties) {
66 String bitLeafPropertyType = bitLeafProperty.getReturnType().getName();
67 if (bitLeafProperty.getName().equals("firstBit")) {
68 firstBitPropertyFound = true;
69 if (bitLeafPropertyType.equals("Boolean")) {
70 firstBitPropertyTypeOK = true;
72 } else if (bitLeafProperty.getName().equals("secondBit")) {
73 secondBitPropertyFound = true;
74 if (bitLeafPropertyType.equals("Boolean")) {
75 secondBitPropertyTypeOK = true;
77 } else if (bitLeafProperty.getName().equals("thirdBit")) {
78 thirdBitPropertyFound = true;
79 if (bitLeafPropertyType.equals("Boolean")) {
80 thirdBitPropertyTypeOK = true;
86 } else if (genType.getName().equals("UnionLeaf")) {
87 unionLeafTOFound = true;
88 GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;
90 List<GeneratedProperty> unionLeafProperties = unionLeafTO.getProperties();
91 for (GeneratedProperty unionLeafProperty : unionLeafProperties) {
92 String unionLeafPropertyType = unionLeafProperty.getReturnType().getName();
93 if (unionLeafProperty.getName().equals("int32")) {
94 int32UnionPropertyFound = true;
95 if (unionLeafPropertyType.equals("Integer")) {
96 int32UnionPropertyTypeOK = true;
98 } else if (unionLeafProperty.getName().equals("string")) {
99 stringUnionPropertyFound = true;
100 if (unionLeafPropertyType.equals("String")) {
101 stringUnionPropertyTypeOK = true;
103 } else if (unionLeafProperty.getName().equals("uint8")) {
104 uint8UnionPropertyFound = true;
105 if (unionLeafPropertyType.equals("Uint8")) {
106 uint8UnionPropertyTypeOK = true;
118 assertTrue(parentContainerFound);
120 assertTrue(bitLeafTOFound);
121 assertTrue(firstBitPropertyFound);
122 assertTrue(secondBitPropertyFound);
123 assertTrue(thirdBitPropertyFound);
125 assertTrue(firstBitPropertyTypeOK);
126 assertTrue(secondBitPropertyTypeOK);
127 assertTrue(thirdBitPropertyTypeOK);
129 assertTrue(unionLeafTOFound);
130 assertTrue(int32UnionPropertyFound);
131 assertTrue(int32UnionPropertyTypeOK);
132 assertTrue(stringUnionPropertyFound);
133 assertTrue(stringUnionPropertyTypeOK);
134 assertTrue(uint8UnionPropertyFound);
135 assertTrue(uint8UnionPropertyTypeOK);