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.yangtools.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.yangtools.binding.model.api.GeneratedProperty;
18 import org.opendaylight.yangtools.binding.model.api.GeneratedTransferObject;
19 import org.opendaylight.yangtools.binding.model.api.MethodSignature;
20 import org.opendaylight.yangtools.binding.model.api.MethodSignature.Parameter;
21 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 public class GeneratedTypesBitsTest {
25 public void testGeneretedTypesBitsTest() {
26 final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangResource(
27 "/simple-bits-demo.yang"));
28 assertTrue(genTypes != null);
30 List<MethodSignature> methodSignaturesList = null;
32 boolean leafParentFound = false;
34 boolean byteTypeFound = false;
35 int classPropertiesNumb = 0;
36 int toStringPropertiesNum = 0;
37 int equalPropertiesNum = 0;
38 int hashPropertiesNum = 0;
40 String nameReturnParamType = "";
41 boolean getByteLeafMethodFound = false;
42 boolean setByteLeafMethodFound = false;
43 int setByteLeafMethodParamNum = 0;
45 for (var genType : genTypes) {
46 if (genType instanceof GeneratedTransferObject genTO) {
47 if (genTO.getName().equals("ByteType")) {
49 List<GeneratedProperty> genProperties = genTO.getProperties();
50 classPropertiesNumb = genProperties.size();
52 genProperties = genTO.getToStringIdentifiers();
53 toStringPropertiesNum = genProperties.size();
55 genProperties = genTO.getEqualsIdentifiers();
56 equalPropertiesNum = genProperties.size();
58 genProperties = genTO.getHashCodeIdentifiers();
59 hashPropertiesNum = genProperties.size();
62 } else if (genType.getName().equals("LeafParentContainer")) {
63 leafParentFound = true;
65 methodSignaturesList = genType.getMethodDefinitions();
66 if (methodSignaturesList != null) {
67 // loop through all methods
68 for (var methodSignature : methodSignaturesList) {
69 if (methodSignature.getName().equals("getByteLeaf")) {
70 getByteLeafMethodFound = true;
72 nameReturnParamType = methodSignature.getReturnType().getName();
73 } else if (methodSignature.getName().equals("setByteLeaf")) {
74 setByteLeafMethodFound = true;
76 List<Parameter> parameters = methodSignature.getParameters();
77 setByteLeafMethodParamNum = parameters.size();
84 assertTrue(byteTypeFound);
86 assertEquals(8, classPropertiesNumb);
88 assertEquals(8, toStringPropertiesNum);
89 assertEquals(8, equalPropertiesNum);
90 assertEquals(8, hashPropertiesNum);
91 assertTrue(leafParentFound);
93 assertNotNull(methodSignaturesList);
95 assertTrue(getByteLeafMethodFound);
96 assertEquals("ByteType", nameReturnParamType);
98 assertFalse(setByteLeafMethodFound);
99 assertEquals(0, setByteLeafMethodParamNum);