1 package org.opendaylight.controller.sal.binding.generator.impl;
3 import static org.junit.Assert.*;
6 import java.util.ArrayList;
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;
23 public class GeneratedTypesBitsTest {
25 private SchemaContext resolveSchemaContextFromFiles(final String... yangFiles) {
26 final YangModelParser parser = new YangParserImpl();
28 final List<File> inputFiles = new ArrayList<File>();
29 for (int i = 0; i < yangFiles.length; ++i) {
30 inputFiles.add(new File(yangFiles[i]));
33 final Set<Module> modules = parser.parseYangModels(inputFiles);
34 return parser.resolveSchemaContext(modules);
38 public void testGeneretedTypesBitsTest() {
39 final String yangTypesPath = getClass().getResource("/simple-bits-demo.yang").getPath();
41 final SchemaContext context = resolveSchemaContextFromFiles(yangTypesPath);
42 assertTrue(context != null);
44 final BindingGenerator bindingGen = new BindingGeneratorImpl();
45 final List<Type> genTypes = bindingGen.generateTypes(context);
46 assertTrue(genTypes != null);
48 List<MethodSignature> methodSignaturesList = null;
50 boolean leafParentFound = false;
52 boolean byteTypeFound = false;
53 int classPropertiesNumb = 0;
54 int toStringPropertiesNum = 0;
55 int equalPropertiesNum = 0;
56 int hashPropertiesNum = 0;
58 String nameReturnParamType = "";
59 String nameMethodeParamType = "";
60 boolean getByteLeafMethodFound = false;
61 boolean setByteLeafMethodFound = false;
62 int setByteLeafMethodParamNum = 0;
64 for (final Type type : genTypes) {
65 if (type instanceof GeneratedTransferObject) { // searching for
67 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
68 if (genTO.getName().equals("ByteType")) {
70 List<GeneratedProperty> genProperties = genTO.getProperties();
71 classPropertiesNumb = genProperties.size();
74 genProperties = genTO.getToStringIdentifiers();
75 toStringPropertiesNum = genProperties.size();
78 genProperties = genTO.getEqualsIdentifiers();
79 equalPropertiesNum = genProperties.size();
82 genProperties = genTO.getHashCodeIdentifiers();
83 hashPropertiesNum = genProperties.size();
86 } else if (type instanceof GeneratedType) { // searching for
88 // LeafParameterContainer
89 final GeneratedType genType = (GeneratedType) type;
90 if (genType.getName().equals("LeafParentContainer")) {
91 leafParentFound = true;
93 methodSignaturesList = genType.getMethodDefinitions();
94 if (methodSignaturesList != null) {
95 for (MethodSignature methodSignature : methodSignaturesList) { // loop
99 if (methodSignature.getName().equals("getByteLeaf")) {
100 getByteLeafMethodFound = true;
102 nameReturnParamType = methodSignature.getReturnType().getName();
103 } else if (methodSignature.getName().equals("setByteLeaf")) {
104 setByteLeafMethodFound = true;
106 List<Parameter> parameters = methodSignature.getParameters();
107 setByteLeafMethodParamNum = parameters.size();
108 for (Parameter parameter : parameters) {
109 nameMethodeParamType = parameter.getType().getName();
121 assertTrue(byteTypeFound);
123 assertEquals(classPropertiesNumb,8);
125 assertEquals(toStringPropertiesNum,8);
126 assertEquals(equalPropertiesNum,8);
127 assertEquals(hashPropertiesNum,8);
128 assertTrue(leafParentFound);
130 assertNotNull(methodSignaturesList);
132 assertTrue(getByteLeafMethodFound);
133 assertEquals(nameReturnParamType,"ByteType");
135 assertFalse(setByteLeafMethodFound);
136 assertEquals(0, setByteLeafMethodParamNum);