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;
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.generator.impl.BindingGeneratorImpl;
21 import org.opendaylight.mdsal.binding.model.api.GeneratedProperty;
22 import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
24 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
25 import org.opendaylight.mdsal.binding.model.api.Type;
26 import org.opendaylight.mdsal.binding.model.api.MethodSignature.Parameter;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
30 public class GeneratedTypesBitsTest {
33 public void testGeneretedTypesBitsTest() throws Exception {
34 final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();
36 final SchemaContext context = YangParserTestUtils.parseYangSources(new File(yangTypesPath));
37 assertTrue(context != null);
39 final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
40 final List<Type> genTypes = bindingGen.generateTypes(context);
41 assertTrue(genTypes != null);
43 List<MethodSignature> methodSignaturesList = null;
45 boolean leafParentFound = false;
47 boolean byteTypeFound = false;
48 int classPropertiesNumb = 0;
49 int toStringPropertiesNum = 0;
50 int equalPropertiesNum = 0;
51 int hashPropertiesNum = 0;
53 String nameReturnParamType = "";
54 boolean getByteLeafMethodFound = false;
55 boolean setByteLeafMethodFound = false;
56 int setByteLeafMethodParamNum = 0;
58 for (final Type type : genTypes) {
59 if (type instanceof GeneratedTransferObject) { // searching for
61 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
62 if (genTO.getName().equals("ByteType")) {
64 List<GeneratedProperty> genProperties = genTO.getProperties();
65 classPropertiesNumb = genProperties.size();
67 genProperties = genTO.getToStringIdentifiers();
68 toStringPropertiesNum = genProperties.size();
70 genProperties = genTO.getEqualsIdentifiers();
71 equalPropertiesNum = genProperties.size();
73 genProperties = genTO.getHashCodeIdentifiers();
74 hashPropertiesNum = genProperties.size();
77 } else if (type instanceof GeneratedType) { // searching for
79 // LeafParameterContainer
80 final GeneratedType genType = (GeneratedType) type;
81 if (genType.getName().equals("LeafParentContainer")) {
82 leafParentFound = true;
84 methodSignaturesList = genType.getMethodDefinitions();
85 if (methodSignaturesList != null) {
86 for (MethodSignature methodSignature : methodSignaturesList) { // loop
90 if (methodSignature.getName().equals("getByteLeaf")) {
91 getByteLeafMethodFound = true;
93 nameReturnParamType = methodSignature.getReturnType().getName();
94 } else if (methodSignature.getName().equals("setByteLeaf")) {
95 setByteLeafMethodFound = true;
97 List<Parameter> parameters = methodSignature.getParameters();
98 setByteLeafMethodParamNum = parameters.size();
108 assertTrue(byteTypeFound);
110 assertEquals(8, classPropertiesNumb);
112 assertEquals(8, toStringPropertiesNum);
113 assertEquals(8, equalPropertiesNum);
114 assertEquals(8, hashPropertiesNum);
115 assertTrue(leafParentFound);
117 assertNotNull(methodSignaturesList);
119 assertTrue(getByteLeafMethodFound);
120 assertEquals("ByteType", nameReturnParamType);
122 assertFalse(setByteLeafMethodFound);
123 assertEquals(0, setByteLeafMethodParamNum);