Remove @Deprecated ClassLoaderUtils as it's now in yangtools.util
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / yangtools / sal / binding / generator / impl / stmt / parser / retest / GenerateInnerClassForBitsAndUnionInLeavesTest.java
1 /*
2  * Copyright (c) 2014 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.yangtools.sal.binding.generator.impl.stmt.parser.retest;
9
10 import static org.junit.Assert.assertTrue;
11
12 import org.opendaylight.yangtools.sal.binding.generator.impl.BindingGeneratorImpl;
13
14 import java.io.File;
15 import java.net.URI;
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;
24
25 public class GenerateInnerClassForBitsAndUnionInLeavesTest {
26
27     @Test
28     public void testInnerClassCreationForBitsAndUnionsInLeafes() throws Exception {
29         final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI();
30
31         final SchemaContext context = RetestUtils.parseYangSources(new File(yangTypesPath));
32         assertTrue(context != null);
33
34         final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
35         final List<Type> genTypes = bindingGen.generateTypes(context);
36         assertTrue(genTypes != null);
37
38         boolean parentContainerFound = false;
39         boolean bitLeafTOFound = false;
40         boolean unionLeafTOFound = false;
41
42         boolean firstBitPropertyFound = false;
43         boolean secondBitPropertyFound = false;
44         boolean thirdBitPropertyFound = false;
45
46         boolean firstBitPropertyTypeOK = false;
47         boolean secondBitPropertyTypeOK = false;
48         boolean thirdBitPropertyTypeOK = false;
49
50         boolean int32UnionPropertyFound = false;
51         boolean int32UnionPropertyTypeOK = false;
52         boolean stringUnionPropertyFound = false;
53         boolean stringUnionPropertyTypeOK = false;
54         boolean uint8UnionPropertyFound = false;
55         boolean uint8UnionPropertyTypeOK = false;
56
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;
68
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;
76                                         }
77                                     } else if (bitLeafProperty.getName().equals("secondBit")) {
78                                         secondBitPropertyFound = true;
79                                         if (bitLeafPropertyType.equals("Boolean")) {
80                                             secondBitPropertyTypeOK = true;
81                                         }
82                                     } else if (bitLeafProperty.getName().equals("thirdBit")) {
83                                         thirdBitPropertyFound = true;
84                                         if (bitLeafPropertyType.equals("Boolean")) {
85                                             thirdBitPropertyTypeOK = true;
86                                         }
87                                     }
88
89                                 }
90
91                             } else if (genType.getName().equals("UnionLeaf")) {
92                                 unionLeafTOFound = true;
93                                 GeneratedTransferObject unionLeafTO = (GeneratedTransferObject) genType;
94
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;
102                                         }
103                                     } else if (unionLeafProperty.getName().equals("string")) {
104                                         stringUnionPropertyFound = true;
105                                         if (unionLeafPropertyType.equals("String")) {
106                                             stringUnionPropertyTypeOK = true;
107                                         }
108                                     } else if (unionLeafProperty.getName().equals("uint8")) {
109                                         uint8UnionPropertyFound = true;
110                                         if (unionLeafPropertyType.equals("Short")) {
111                                             uint8UnionPropertyTypeOK = true;
112                                         }
113                                     }
114
115                                 }
116
117                             }
118                         }
119                     }
120                 }
121             }
122         }
123         assertTrue(parentContainerFound);
124
125         assertTrue(bitLeafTOFound);
126         assertTrue(firstBitPropertyFound);
127         assertTrue(secondBitPropertyFound);
128         assertTrue(thirdBitPropertyFound);
129
130         assertTrue(firstBitPropertyTypeOK);
131         assertTrue(secondBitPropertyTypeOK);
132         assertTrue(thirdBitPropertyTypeOK);
133
134         assertTrue(unionLeafTOFound);
135         assertTrue(int32UnionPropertyFound);
136         assertTrue(int32UnionPropertyTypeOK);
137         assertTrue(stringUnionPropertyFound);
138         assertTrue(stringUnionPropertyTypeOK);
139         assertTrue(uint8UnionPropertyFound);
140         assertTrue(uint8UnionPropertyTypeOK);
141
142     }
143 }