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