Update BindingRuntime{Context,Generator,Types}
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / GenerateInnerClassForBitsAndUnionInLeavesTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.mdsal.binding.generator.impl;
9
10 import static org.junit.Assert.assertTrue;
11
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.test.util.YangParserTestUtils;
19
20 public class GenerateInnerClassForBitsAndUnionInLeavesTest {
21     @Test
22     public void testInnerClassCreationForBitsAndUnionsInLeafes() {
23         final List<Type> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
24             "/bit_and_union_in_leaf.yang"));
25         assertTrue(genTypes != null);
26
27         boolean parentContainerFound = false;
28         boolean bitLeafTOFound = false;
29         boolean unionLeafTOFound = false;
30
31         boolean firstBitPropertyFound = false;
32         boolean secondBitPropertyFound = false;
33         boolean thirdBitPropertyFound = false;
34
35         boolean firstBitPropertyTypeOK = false;
36         boolean secondBitPropertyTypeOK = false;
37         boolean thirdBitPropertyTypeOK = false;
38
39         boolean int32UnionPropertyFound = false;
40         boolean int32UnionPropertyTypeOK = false;
41         boolean stringUnionPropertyFound = false;
42         boolean stringUnionPropertyTypeOK = false;
43         boolean uint8UnionPropertyFound = false;
44         boolean uint8UnionPropertyTypeOK = false;
45
46         for (Type type : genTypes) {
47             if (type instanceof GeneratedType && !(type instanceof GeneratedTransferObject)) {
48                 if (type.getName().equals("ParentContainer")) {
49                     parentContainerFound = true;
50                     GeneratedType parentContainer = (GeneratedType) type;
51                     List<GeneratedType> enclosedTypes = parentContainer.getEnclosedTypes();
52                     for (GeneratedType genType : enclosedTypes) {
53                         if (genType instanceof GeneratedTransferObject) {
54                             if (genType.getName().equals("BitLeaf")) {
55                                 bitLeafTOFound = true;
56                                 GeneratedTransferObject bitLeafTO = (GeneratedTransferObject) genType;
57
58                                 List<GeneratedProperty> bitLeafProperties = bitLeafTO.getProperties();
59                                 for (GeneratedProperty bitLeafProperty : bitLeafProperties) {
60                                     String bitLeafPropertyType = bitLeafProperty.getReturnType().getName();
61                                     if (bitLeafProperty.getName().equals("firstBit")) {
62                                         firstBitPropertyFound = true;
63                                         if (bitLeafPropertyType.equals("Boolean")) {
64                                             firstBitPropertyTypeOK = true;
65                                         }
66                                     } else if (bitLeafProperty.getName().equals("secondBit")) {
67                                         secondBitPropertyFound = true;
68                                         if (bitLeafPropertyType.equals("Boolean")) {
69                                             secondBitPropertyTypeOK = true;
70                                         }
71                                     } else if (bitLeafProperty.getName().equals("thirdBit")) {
72                                         thirdBitPropertyFound = true;
73                                         if (bitLeafPropertyType.equals("Boolean")) {
74                                             thirdBitPropertyTypeOK = true;
75                                         }
76                                     }
77
78                                 }
79
80                             } else if (genType.getName().equals("UnionLeaf")) {
81                                 unionLeafTOFound = true;
82                                 GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;
83
84                                 List<GeneratedProperty> unionLeafProperties = unionLeafTO.getProperties();
85                                 for (GeneratedProperty unionLeafProperty : unionLeafProperties) {
86                                     String unionLeafPropertyType = unionLeafProperty.getReturnType().getName();
87                                     if (unionLeafProperty.getName().equals("int32")) {
88                                         int32UnionPropertyFound = true;
89                                         if (unionLeafPropertyType.equals("Integer")) {
90                                             int32UnionPropertyTypeOK = true;
91                                         }
92                                     } else if (unionLeafProperty.getName().equals("string")) {
93                                         stringUnionPropertyFound = true;
94                                         if (unionLeafPropertyType.equals("String")) {
95                                             stringUnionPropertyTypeOK = true;
96                                         }
97                                     } else if (unionLeafProperty.getName().equals("uint8")) {
98                                         uint8UnionPropertyFound = true;
99                                         if (unionLeafPropertyType.equals("Uint8")) {
100                                             uint8UnionPropertyTypeOK = true;
101                                         }
102                                     }
103
104                                 }
105
106                             }
107                         }
108                     }
109                 }
110             }
111         }
112         assertTrue(parentContainerFound);
113
114         assertTrue(bitLeafTOFound);
115         assertTrue(firstBitPropertyFound);
116         assertTrue(secondBitPropertyFound);
117         assertTrue(thirdBitPropertyFound);
118
119         assertTrue(firstBitPropertyTypeOK);
120         assertTrue(secondBitPropertyTypeOK);
121         assertTrue(thirdBitPropertyTypeOK);
122
123         assertTrue(unionLeafTOFound);
124         assertTrue(int32UnionPropertyFound);
125         assertTrue(int32UnionPropertyTypeOK);
126         assertTrue(stringUnionPropertyFound);
127         assertTrue(stringUnionPropertyTypeOK);
128         assertTrue(uint8UnionPropertyFound);
129         assertTrue(uint8UnionPropertyTypeOK);
130
131     }
132 }