Revert "Fix broken tests according to yangtools...
[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.io.File;
16 import java.net.URI;
17 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
20 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
21 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
22 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
24 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
25 import org.opendaylight.mdsal.binding.model.api.Type;
26 import org.opendaylight.mdsal.binding.model.api.MethodSignature.Parameter;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
29
30 public class GeneratedTypesBitsTest {
31
32     @Test
33     public void testGeneretedTypesBitsTest() throws Exception {
34         final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();
35
36         final SchemaContext context = YangParserTestUtils.parseYangSources(new File(yangTypesPath));
37         assertTrue(context != null);
38
39         final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
40         final List<Type> genTypes = bindingGen.generateTypes(context);
41         assertTrue(genTypes != null);
42
43         List<MethodSignature> methodSignaturesList = null;
44
45         boolean leafParentFound = false;
46
47         boolean byteTypeFound = false;
48         int classPropertiesNumb = 0;
49         int toStringPropertiesNum = 0;
50         int equalPropertiesNum = 0;
51         int hashPropertiesNum = 0;
52
53         String nameReturnParamType = "";
54         boolean getByteLeafMethodFound = false;
55         boolean setByteLeafMethodFound = false;
56         int setByteLeafMethodParamNum = 0;
57
58         for (final Type type : genTypes) {
59             if (type instanceof GeneratedTransferObject) { // searching for
60                                                            // ByteType
61                 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
62                 if (genTO.getName().equals("ByteType")) {
63                     byteTypeFound = true;
64                     List<GeneratedProperty> genProperties = genTO.getProperties();
65                     classPropertiesNumb = genProperties.size();
66
67                     genProperties = genTO.getToStringIdentifiers();
68                     toStringPropertiesNum = genProperties.size();
69
70                     genProperties = genTO.getEqualsIdentifiers();
71                     equalPropertiesNum = genProperties.size();
72
73                     genProperties = genTO.getHashCodeIdentifiers();
74                     hashPropertiesNum = genProperties.size();
75
76                 }
77             } else if (type instanceof GeneratedType) { // searching for
78                                                         // interface
79                                                         // LeafParameterContainer
80                 final GeneratedType genType = (GeneratedType) type;
81                 if (genType.getName().equals("LeafParentContainer")) {
82                     leafParentFound = true;
83                     // check of methods
84                     methodSignaturesList = genType.getMethodDefinitions();
85                     if (methodSignaturesList != null) {
86                         for (MethodSignature methodSignature : methodSignaturesList) { // loop
87                                                                                        // through
88                                                                                        // all
89                                                                                        // methods
90                             if (methodSignature.getName().equals("getByteLeaf")) {
91                                 getByteLeafMethodFound = true;
92
93                                 nameReturnParamType = methodSignature.getReturnType().getName();
94                             } else if (methodSignature.getName().equals("setByteLeaf")) {
95                                 setByteLeafMethodFound = true;
96
97                                 List<Parameter> parameters = methodSignature.getParameters();
98                                 setByteLeafMethodParamNum = parameters.size();
99                             }
100
101                         }
102                     }
103                 }
104             }
105
106         }
107
108         assertTrue(byteTypeFound);
109
110         assertEquals(8, classPropertiesNumb);
111
112         assertEquals(8, toStringPropertiesNum);
113         assertEquals(8, equalPropertiesNum);
114         assertEquals(8, hashPropertiesNum);
115         assertTrue(leafParentFound);
116
117         assertNotNull(methodSignaturesList);
118
119         assertTrue(getByteLeafMethodFound);
120         assertEquals("ByteType", nameReturnParamType);
121
122         assertFalse(setByteLeafMethodFound);
123         assertEquals(0, setByteLeafMethodParamNum);
124     }
125
126 }