1 package org.opendaylight.controller.sal.binding.generator.impl;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertNotNull;
5 import static org.junit.Assert.assertTrue;
8 import java.util.ArrayList;
12 import org.junit.Test;
13 import org.opendaylight.controller.sal.binding.generator.api.BindingGenerator;
14 import org.opendaylight.controller.sal.binding.model.api.GeneratedProperty;
15 import org.opendaylight.controller.sal.binding.model.api.GeneratedTransferObject;
16 import org.opendaylight.controller.sal.binding.model.api.GeneratedType;
17 import org.opendaylight.controller.sal.binding.model.api.MethodSignature;
18 import org.opendaylight.controller.sal.binding.model.api.MethodSignature.Parameter;
19 import org.opendaylight.controller.sal.binding.model.api.Type;
20 import org.opendaylight.controller.yang.model.api.Module;
21 import org.opendaylight.controller.yang.model.api.SchemaContext;
22 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
23 import org.opendaylight.controller.yang.parser.impl.YangParserImpl;
25 public class GeneratedTypesBitsTest {
27 private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
28 final YangModelParser parser = new YangParserImpl();
30 final List<File> inputFiles = new ArrayList<File>();
31 for (int i = 0; i < yangFiles.length; ++i) {
32 inputFiles.add(new File(yangFiles[i]));
35 final Set<Module> modules = parser.parseYangModels(inputFiles);
36 return parser.resolveSchemaContext(modules);
40 public void testGeneretedTypesBitsTest() {
41 final String yangTypesPath = getClass().getResource("/simple-bits-demo.yang").getPath();
43 final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
44 assertTrue(context != null);
46 final BindingGenerator bindingGen = new BindingGeneratorImpl();
47 final List<Type> genTypes = bindingGen.generateTypes(context);
48 assertTrue(genTypes != null);
50 List<MethodSignature> methodSignaturesList = null;
52 boolean leafParentFound = false;
54 boolean byteTypeFound = false;
55 int classPropertiesNumb = 0;
56 int toStringPropertiesNum = 0;
57 int equalPropertiesNum = 0;
58 int hashPropertiesNum = 0;
60 String nameReturnParamType = "";
61 String nameMethodeParamType = "";
62 boolean getByteLeafMethodFound = false;
63 boolean setByteLeafMethodFound = false;
64 int setByteLeafMethodParamNum = 0;
66 for (final Type type : genTypes) {
67 if (type instanceof GeneratedTransferObject) { // searching for
69 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
70 if (genTO.getName().equals("ByteType")) {
72 List<GeneratedProperty> genProperties = genTO.getProperties();
73 classPropertiesNumb = genProperties.size();
76 genProperties = genTO.getToStringIdentifiers();
77 toStringPropertiesNum = genProperties.size();
80 genProperties = genTO.getEqualsIdentifiers();
81 equalPropertiesNum = genProperties.size();
84 genProperties = genTO.getHashCodeIdentifiers();
85 hashPropertiesNum = genProperties.size();
88 } else if (type instanceof GeneratedType) { // searching for
90 // LeafParameterContainer
91 final GeneratedType genType = (GeneratedType) type;
92 if (genType.getName().equals("LeafParentContainer")) {
93 leafParentFound = true;
95 methodSignaturesList = genType.getMethodDefinitions();
96 if (methodSignaturesList != null) {
97 for (MethodSignature methodSignature : methodSignaturesList) { // loop
101 if (methodSignature.getName().equals("getByteLeaf")) {
102 getByteLeafMethodFound = true;
104 nameReturnParamType = methodSignature.getReturnType().getName();
105 } else if (methodSignature.getName().equals("setByteLeaf")) {
106 setByteLeafMethodFound = true;
108 List<Parameter> parameters = methodSignature.getParameters();
109 setByteLeafMethodParamNum = parameters.size();
110 for (Parameter parameter : parameters) {
111 nameMethodeParamType = parameter.getType().getName();
123 assertTrue(byteTypeFound);
125 assertEquals(classPropertiesNumb,8);
127 assertEquals(toStringPropertiesNum,8);
128 assertEquals(equalPropertiesNum,8);
129 assertEquals(hashPropertiesNum,8);
130 assertTrue(leafParentFound);
132 assertNotNull(methodSignaturesList);
134 assertTrue(getByteLeafMethodFound);
135 assertEquals(nameReturnParamType,"ByteType");
137 assertTrue(setByteLeafMethodFound);
138 assertEquals(setByteLeafMethodParamNum,1);
139 assertEquals(nameMethodeParamType,"ByteType");