2 * Copyright (c) 2014 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;
16 import java.util.List;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
20 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
21 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
22 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
23 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
24 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter;
25 import org.opendaylight.yangtools.sal.binding.model.api.Type;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 public class GeneratedTypesBitsTest {
32 public void testGeneretedTypesBitsTest() throws Exception {
33 final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();
35 final SchemaContext context = SupportTestUtil.resolveSchemaContextFromFiles(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();
67 genProperties = genTO.getToStringIdentifiers();
68 toStringPropertiesNum = genProperties.size();
71 genProperties = genTO.getEqualsIdentifiers();
72 equalPropertiesNum = genProperties.size();
75 genProperties = genTO.getHashCodeIdentifiers();
76 hashPropertiesNum = genProperties.size();
79 } else if (type instanceof GeneratedType) { // searching for
81 // LeafParameterContainer
82 final GeneratedType genType = (GeneratedType) type;
83 if (genType.getName().equals("LeafParentContainer")) {
84 leafParentFound = true;
86 methodSignaturesList = genType.getMethodDefinitions();
87 if (methodSignaturesList != null) {
88 for (MethodSignature methodSignature : methodSignaturesList) { // loop
92 if (methodSignature.getName().equals("getByteLeaf")) {
93 getByteLeafMethodFound = true;
95 nameReturnParamType = methodSignature.getReturnType().getName();
96 } else if (methodSignature.getName().equals("setByteLeaf")) {
97 setByteLeafMethodFound = true;
99 List<Parameter> parameters = methodSignature.getParameters();
100 setByteLeafMethodParamNum = parameters.size();
110 assertTrue(byteTypeFound);
112 assertEquals(classPropertiesNumb,8);
114 assertEquals(toStringPropertiesNum,8);
115 assertEquals(equalPropertiesNum,8);
116 assertEquals(hashPropertiesNum,8);
117 assertTrue(leafParentFound);
119 assertNotNull(methodSignaturesList);
121 assertTrue(getByteLeafMethodFound);
122 assertEquals(nameReturnParamType,"ByteType");
124 assertFalse(setByteLeafMethodFound);
125 assertEquals(0, setByteLeafMethodParamNum);