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.mdsal.binding.model.api.Type;
23 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
25 public class GeneratedTypesBitsTest {
27 public void testGeneretedTypesBitsTest() {
28 final List<Type> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
29 "/simple-bits-demo.yang"));
30 assertTrue(genTypes != null);
32 List<MethodSignature> methodSignaturesList = null;
34 boolean leafParentFound = false;
36 boolean byteTypeFound = false;
37 int classPropertiesNumb = 0;
38 int toStringPropertiesNum = 0;
39 int equalPropertiesNum = 0;
40 int hashPropertiesNum = 0;
42 String nameReturnParamType = "";
43 boolean getByteLeafMethodFound = false;
44 boolean setByteLeafMethodFound = false;
45 int setByteLeafMethodParamNum = 0;
47 for (final Type type : genTypes) {
48 if (type instanceof GeneratedTransferObject) { // searching for
50 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
51 if (genTO.getName().equals("ByteType")) {
53 List<GeneratedProperty> genProperties = genTO.getProperties();
54 classPropertiesNumb = genProperties.size();
56 genProperties = genTO.getToStringIdentifiers();
57 toStringPropertiesNum = genProperties.size();
59 genProperties = genTO.getEqualsIdentifiers();
60 equalPropertiesNum = genProperties.size();
62 genProperties = genTO.getHashCodeIdentifiers();
63 hashPropertiesNum = genProperties.size();
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;
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;
79 nameReturnParamType = methodSignature.getReturnType().getName();
80 } else if (methodSignature.getName().equals("setByteLeaf")) {
81 setByteLeafMethodFound = true;
83 List<Parameter> parameters = methodSignature.getParameters();
84 setByteLeafMethodParamNum = parameters.size();
93 assertTrue(byteTypeFound);
95 assertEquals(8, classPropertiesNumb);
97 assertEquals(8, toStringPropertiesNum);
98 assertEquals(8, equalPropertiesNum);
99 assertEquals(8, hashPropertiesNum);
100 assertTrue(leafParentFound);
102 assertNotNull(methodSignaturesList);
104 assertTrue(getByteLeafMethodFound);
105 assertEquals("ByteType", nameReturnParamType);
107 assertFalse(setByteLeafMethodFound);
108 assertEquals(0, setByteLeafMethodParamNum);