Merge "Fix minor bug in FRM proactive flow code path"
[controller.git] / opendaylight / sal / yang-prototype / code-generator / binding-generator-impl / src / test / java / org / opendaylight / controller / sal / binding / generator / impl / GeneratedTypesBitsTest.java
1 package org.opendaylight.controller.sal.binding.generator.impl;
2
3 import static org.junit.Assert.*;
4
5 import java.io.File;
6 import java.util.ArrayList;
7 import java.util.List;
8 import java.util.Set;
9
10 import org.junit.Test;
11 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
12 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
13 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
14 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
15 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
16 import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
17 import org.opendaylight.controller.sal.binding.model.api.Type;
18 import org.opendaylight.yangtools.yang.model.api.Module;
19 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
20 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
21 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
22
23 public class GeneratedTypesBitsTest {
24
25     private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
26         final YangModelParser parser = new YangParserImpl();
27
28         final List<File> inputFiles = new ArrayList<File>();
29         for (int i = 0; i < yangFiles.length; ++i) {
30             inputFiles.add(new File(yangFiles[i]));
31         }
32
33         final Set<Module> modules = parser.parseYangModels(inputFiles);
34         return parser.resolveSchemaContext(modules);
35     }
36
37     @Test
38     public void testGeneretedTypesBitsTest() {
39         final String yangTypesPath = getClass().getResource("/simple-bits-demo.yang").getPath();
40
41         final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
42         assertTrue(context != null);
43
44         final BindingGenerator bindingGen = new BindingGeneratorImpl();
45         final List<Type> genTypes = bindingGen.generateTypes(context);
46         assertTrue(genTypes != null);
47
48         List<MethodSignature> methodSignaturesList = null;
49
50         boolean leafParentFound = false;
51
52         boolean byteTypeFound = false;
53         int classPropertiesNumb = 0;
54         int toStringPropertiesNum = 0;
55         int equalPropertiesNum = 0;
56         int hashPropertiesNum = 0;
57
58         String nameReturnParamType = "";
59         String nameMethodeParamType = "";
60         boolean getByteLeafMethodFound = false;
61         boolean setByteLeafMethodFound = false;
62         int setByteLeafMethodParamNum = 0;
63
64         for (final Type type : genTypes) {
65             if (type instanceof GeneratedTransferObject) { // searching for
66                                                            // ByteType
67                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
68                 if (genTO.getName().equals("ByteType")) {
69                     byteTypeFound = true;
70                     List<GeneratedProperty> genProperties = genTO.getProperties();
71                     classPropertiesNumb = genProperties.size();
72
73                     genProperties = null;
74                     genProperties = genTO.getToStringIdentifiers();
75                     toStringPropertiesNum = genProperties.size();
76
77                     genProperties = null;
78                     genProperties = genTO.getEqualsIdentifiers();
79                     equalPropertiesNum = genProperties.size();
80
81                     genProperties = null;
82                     genProperties = genTO.getHashCodeIdentifiers();
83                     hashPropertiesNum = genProperties.size();
84
85                 }
86             } else if (type instanceof GeneratedType) { // searching for
87                                                         // interface
88                                                         // LeafParameterContainer
89                 final GeneratedType genType = (GeneratedType) type;
90                 if (genType.getName().equals("LeafParentContainer")) {
91                     leafParentFound = true;
92                     // check of methods
93                     methodSignaturesList = genType.getMethodDefinitions();
94                     if (methodSignaturesList != null) {
95                         for (MethodSignature methodSignature : methodSignaturesList) { // loop
96                                                                                        // through
97                                                                                        // all
98                                                                                        // methods
99                             if (methodSignature.getName().equals("getByteLeaf")) {
100                                 getByteLeafMethodFound = true;
101
102                                 nameReturnParamType = methodSignature.getReturnType().getName();
103                             } else if (methodSignature.getName().equals("setByteLeaf")) {
104                                 setByteLeafMethodFound = true;
105
106                                 List<Parameter> parameters = methodSignature.getParameters();
107                                 setByteLeafMethodParamNum = parameters.size();
108                                 for (Parameter parameter : parameters) {
109                                     nameMethodeParamType = parameter.getType().getName();
110                                 }
111
112                             }
113
114                         }
115                     }
116                 }
117             }
118
119         }
120
121         assertTrue(byteTypeFound);
122
123         assertEquals(classPropertiesNumb,8);
124
125         assertEquals(toStringPropertiesNum,8);
126         assertEquals(equalPropertiesNum,8);
127         assertEquals(hashPropertiesNum,8);
128         assertTrue(leafParentFound);
129
130         assertNotNull(methodSignaturesList);
131
132         assertTrue(getByteLeafMethodFound);
133         assertEquals(nameReturnParamType,"ByteType");
134
135         assertFalse(setByteLeafMethodFound);
136         assertEquals(0, setByteLeafMethodParamNum);
137     }
138
139 }