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.generator.api.BindingGenerator;
18 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
19 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
20 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
21 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
22 import org.opendaylight.mdsal.binding.model.api.MethodSignature.Parameter;
23 import org.opendaylight.mdsal.binding.model.api.Type;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27 public class GeneratedTypesBitsTest {
30 public void testGeneretedTypesBitsTest() {
31 final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-bits-demo.yang");
32 assertTrue(context != null);
34 final BindingGenerator bindingGen = new BindingGeneratorImpl();
35 final List<Type> genTypes = bindingGen.generateTypes(context);
36 assertTrue(genTypes != null);
38 List<MethodSignature> methodSignaturesList = null;
40 boolean leafParentFound = false;
42 boolean byteTypeFound = false;
43 int classPropertiesNumb = 0;
44 int toStringPropertiesNum = 0;
45 int equalPropertiesNum = 0;
46 int hashPropertiesNum = 0;
48 String nameReturnParamType = "";
49 boolean getByteLeafMethodFound = false;
50 boolean setByteLeafMethodFound = false;
51 int setByteLeafMethodParamNum = 0;
53 for (final Type type : genTypes) {
54 if (type instanceof GeneratedTransferObject) { // searching for
56 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
57 if (genTO.getName().equals("ByteType")) {
59 List<GeneratedProperty> genProperties = genTO.getProperties();
60 classPropertiesNumb = genProperties.size();
62 genProperties = genTO.getToStringIdentifiers();
63 toStringPropertiesNum = genProperties.size();
65 genProperties = genTO.getEqualsIdentifiers();
66 equalPropertiesNum = genProperties.size();
68 genProperties = genTO.getHashCodeIdentifiers();
69 hashPropertiesNum = genProperties.size();
72 } else if (type instanceof GeneratedType) {
73 // searching for interface LeafParameterContainer
74 final GeneratedType genType = (GeneratedType) type;
75 if (genType.getName().equals("LeafParentContainer")) {
76 leafParentFound = true;
78 methodSignaturesList = genType.getMethodDefinitions();
79 if (methodSignaturesList != null) {
80 // loop through all methods
81 for (MethodSignature methodSignature : methodSignaturesList) {
82 if (methodSignature.getName().equals("getByteLeaf")) {
83 getByteLeafMethodFound = true;
85 nameReturnParamType = methodSignature.getReturnType().getName();
86 } else if (methodSignature.getName().equals("setByteLeaf")) {
87 setByteLeafMethodFound = true;
89 List<Parameter> parameters = methodSignature.getParameters();
90 setByteLeafMethodParamNum = parameters.size();
99 assertTrue(byteTypeFound);
101 assertEquals(8, classPropertiesNumb);
103 assertEquals(8, toStringPropertiesNum);
104 assertEquals(8, equalPropertiesNum);
105 assertEquals(8, hashPropertiesNum);
106 assertTrue(leafParentFound);
108 assertNotNull(methodSignaturesList);
110 assertTrue(getByteLeafMethodFound);
111 assertEquals("ByteType", nameReturnParamType);
113 assertFalse(setByteLeafMethodFound);
114 assertEquals(0, setByteLeafMethodParamNum);