2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.binding.generator.impl;
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;
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.yangtools.yang.test.util.YangParserTestUtils;
24 public class GeneratedTypesBitsTest {
26 public void testGeneretedTypesBitsTest() {
27 final List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
28 "/simple-bits-demo.yang"));
29 assertTrue(genTypes != null);
31 List<MethodSignature> methodSignaturesList = null;
33 boolean leafParentFound = false;
35 boolean byteTypeFound = false;
36 int classPropertiesNumb = 0;
37 int toStringPropertiesNum = 0;
38 int equalPropertiesNum = 0;
39 int hashPropertiesNum = 0;
41 String nameReturnParamType = "";
42 boolean getByteLeafMethodFound = false;
43 boolean setByteLeafMethodFound = false;
44 int setByteLeafMethodParamNum = 0;
46 for (final GeneratedType type : genTypes) {
47 if (type instanceof GeneratedTransferObject) {
48 // searching for ByteType
49 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
50 if (genTO.getName().equals("ByteType")) {
52 List<GeneratedProperty> genProperties = genTO.getProperties();
53 classPropertiesNumb = genProperties.size();
55 genProperties = genTO.getToStringIdentifiers();
56 toStringPropertiesNum = genProperties.size();
58 genProperties = genTO.getEqualsIdentifiers();
59 equalPropertiesNum = genProperties.size();
61 genProperties = genTO.getHashCodeIdentifiers();
62 hashPropertiesNum = genProperties.size();
66 // searching for interface LeafParameterContainer
67 final GeneratedType genType = type;
68 if (genType.getName().equals("LeafParentContainer")) {
69 leafParentFound = true;
71 methodSignaturesList = genType.getMethodDefinitions();
72 if (methodSignaturesList != null) {
73 // loop through all methods
74 for (MethodSignature methodSignature : methodSignaturesList) {
75 if (methodSignature.getName().equals("getByteLeaf")) {
76 getByteLeafMethodFound = true;
78 nameReturnParamType = methodSignature.getReturnType().getName();
79 } else if (methodSignature.getName().equals("setByteLeaf")) {
80 setByteLeafMethodFound = true;
82 List<Parameter> parameters = methodSignature.getParameters();
83 setByteLeafMethodParamNum = parameters.size();
91 assertTrue(byteTypeFound);
93 assertEquals(8, classPropertiesNumb);
95 assertEquals(8, toStringPropertiesNum);
96 assertEquals(8, equalPropertiesNum);
97 assertEquals(8, hashPropertiesNum);
98 assertTrue(leafParentFound);
100 assertNotNull(methodSignaturesList);
102 assertTrue(getByteLeafMethodFound);
103 assertEquals("ByteType", nameReturnParamType);
105 assertFalse(setByteLeafMethodFound);
106 assertEquals(0, setByteLeafMethodParamNum);