Update BindingRuntime{Context,Generator,Types}
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / mdsal / binding / generator / impl / GeneratedTypesBitsTest.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.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import java.util.List;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
20 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
21 import org.opendaylight.mdsal.binding.model.api.MethodSignature.Parameter;
22 import org.opendaylight.mdsal.binding.model.api.Type;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
24
25 public class GeneratedTypesBitsTest {
26     @Test
27     public void testGeneretedTypesBitsTest() {
28         final List<Type> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
29             "/simple-bits-demo.yang"));
30         assertTrue(genTypes != null);
31
32         List<MethodSignature> methodSignaturesList = null;
33
34         boolean leafParentFound = false;
35
36         boolean byteTypeFound = false;
37         int classPropertiesNumb = 0;
38         int toStringPropertiesNum = 0;
39         int equalPropertiesNum = 0;
40         int hashPropertiesNum = 0;
41
42         String nameReturnParamType = "";
43         boolean getByteLeafMethodFound = false;
44         boolean setByteLeafMethodFound = false;
45         int setByteLeafMethodParamNum = 0;
46
47         for (final Type type : genTypes) {
48             if (type instanceof GeneratedTransferObject) { // searching for
49                                                            // ByteType
50                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
51                 if (genTO.getName().equals("ByteType")) {
52                     byteTypeFound = true;
53                     List<GeneratedProperty> genProperties = genTO.getProperties();
54                     classPropertiesNumb = genProperties.size();
55
56                     genProperties = genTO.getToStringIdentifiers();
57                     toStringPropertiesNum = genProperties.size();
58
59                     genProperties = genTO.getEqualsIdentifiers();
60                     equalPropertiesNum = genProperties.size();
61
62                     genProperties = genTO.getHashCodeIdentifiers();
63                     hashPropertiesNum = genProperties.size();
64
65                 }
66             } else if (type instanceof GeneratedType) {
67                 // searching for interface LeafParameterContainer
68                 final GeneratedType genType = (GeneratedType) type;
69                 if (genType.getName().equals("LeafParentContainer")) {
70                     leafParentFound = true;
71                     // check of methods
72                     methodSignaturesList = genType.getMethodDefinitions();
73                     if (methodSignaturesList != null) {
74                         // loop through all methods
75                         for (MethodSignature methodSignature : methodSignaturesList) {
76                             if (methodSignature.getName().equals("getByteLeaf")) {
77                                 getByteLeafMethodFound = true;
78
79                                 nameReturnParamType = methodSignature.getReturnType().getName();
80                             } else if (methodSignature.getName().equals("setByteLeaf")) {
81                                 setByteLeafMethodFound = true;
82
83                                 List<Parameter> parameters = methodSignature.getParameters();
84                                 setByteLeafMethodParamNum = parameters.size();
85                             }
86
87                         }
88                     }
89                 }
90             }
91         }
92
93         assertTrue(byteTypeFound);
94
95         assertEquals(8, classPropertiesNumb);
96
97         assertEquals(8, toStringPropertiesNum);
98         assertEquals(8, equalPropertiesNum);
99         assertEquals(8, hashPropertiesNum);
100         assertTrue(leafParentFound);
101
102         assertNotNull(methodSignaturesList);
103
104         assertTrue(getByteLeafMethodFound);
105         assertEquals("ByteType", nameReturnParamType);
106
107         assertFalse(setByteLeafMethodFound);
108         assertEquals(0, setByteLeafMethodParamNum);
109     }
110 }