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.sal.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;
17 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
20 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
21 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
22 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
23 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
24 import org.opendaylight.mdsal.binding.model.api.Type;
25 import org.opendaylight.mdsal.binding.model.api.MethodSignature.Parameter;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
29 public class GeneratedTypesBitsTest {
32 public void testGeneretedTypesBitsTest() throws Exception {
33 final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();
35 final SchemaContext context = YangParserTestUtils.parseYangSources(new File(yangTypesPath));
36 assertTrue(context != null);
38 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
39 final List<Type> genTypes = bindingGen.generateTypes(context);
40 assertTrue(genTypes != null);
42 List<MethodSignature> methodSignaturesList = null;
44 boolean leafParentFound = false;
46 boolean byteTypeFound = false;
47 int classPropertiesNumb = 0;
48 int toStringPropertiesNum = 0;
49 int equalPropertiesNum = 0;
50 int hashPropertiesNum = 0;
52 String nameReturnParamType = "";
53 boolean getByteLeafMethodFound = false;
54 boolean setByteLeafMethodFound = false;
55 int setByteLeafMethodParamNum = 0;
57 for (final Type type : genTypes) {
58 if (type instanceof GeneratedTransferObject) { // searching for
60 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
61 if (genTO.getName().equals("ByteType")) {
63 List<GeneratedProperty> genProperties = genTO.getProperties();
64 classPropertiesNumb = genProperties.size();
66 genProperties = genTO.getToStringIdentifiers();
67 toStringPropertiesNum = genProperties.size();
69 genProperties = genTO.getEqualsIdentifiers();
70 equalPropertiesNum = genProperties.size();
72 genProperties = genTO.getHashCodeIdentifiers();
73 hashPropertiesNum = genProperties.size();
76 } else if (type instanceof GeneratedType) { // searching for
78 // LeafParameterContainer
79 final GeneratedType genType = (GeneratedType) type;
80 if (genType.getName().equals("LeafParentContainer")) {
81 leafParentFound = true;
83 methodSignaturesList = genType.getMethodDefinitions();
84 if (methodSignaturesList != null) {
85 for (MethodSignature methodSignature : methodSignaturesList) { // loop
89 if (methodSignature.getName().equals("getByteLeaf")) {
90 getByteLeafMethodFound = true;
92 nameReturnParamType = methodSignature.getReturnType().getName();
93 } else if (methodSignature.getName().equals("setByteLeaf")) {
94 setByteLeafMethodFound = true;
96 List<Parameter> parameters = methodSignature.getParameters();
97 setByteLeafMethodParamNum = parameters.size();
107 assertTrue(byteTypeFound);
109 assertEquals(8, classPropertiesNumb);
111 assertEquals(8, toStringPropertiesNum);
112 assertEquals(8, equalPropertiesNum);
113 assertEquals(8, hashPropertiesNum);
114 assertTrue(leafParentFound);
116 assertNotNull(methodSignaturesList);
118 assertTrue(getByteLeafMethodFound);
119 assertEquals("ByteType", nameReturnParamType);
121 assertFalse(setByteLeafMethodFound);
122 assertEquals(0, setByteLeafMethodParamNum);