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;
17 import org.junit.Test;
18 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
19 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
20 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
21 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
22 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
23 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter;
24 import org.opendaylight.yangtools.sal.binding.model.api.Type;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 public class GeneratedTypesBitsTest {
31 public void testGeneretedTypesBitsTest() throws Exception {
32 final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();
34 final SchemaContext context = SupportTestUtil.resolveSchemaContextFromFiles(yangTypesPath);
35 assertTrue(context != null);
37 final BindingGenerator bindingGen = new BindingGeneratorImpl();
38 final List<Type> genTypes = bindingGen.generateTypes(context);
39 assertTrue(genTypes != null);
41 List<MethodSignature> methodSignaturesList = null;
43 boolean leafParentFound = false;
45 boolean byteTypeFound = false;
46 int classPropertiesNumb = 0;
47 int toStringPropertiesNum = 0;
48 int equalPropertiesNum = 0;
49 int hashPropertiesNum = 0;
51 String nameReturnParamType = "";
52 boolean getByteLeafMethodFound = false;
53 boolean setByteLeafMethodFound = false;
54 int setByteLeafMethodParamNum = 0;
56 for (final Type type : genTypes) {
57 if (type instanceof GeneratedTransferObject) { // searching for
59 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
60 if (genTO.getName().equals("ByteType")) {
62 List<GeneratedProperty> genProperties = genTO.getProperties();
63 classPropertiesNumb = genProperties.size();
66 genProperties = genTO.getToStringIdentifiers();
67 toStringPropertiesNum = genProperties.size();
70 genProperties = genTO.getEqualsIdentifiers();
71 equalPropertiesNum = genProperties.size();
74 genProperties = genTO.getHashCodeIdentifiers();
75 hashPropertiesNum = genProperties.size();
78 } else if (type instanceof GeneratedType) { // searching for
80 // LeafParameterContainer
81 final GeneratedType genType = (GeneratedType) type;
82 if (genType.getName().equals("LeafParentContainer")) {
83 leafParentFound = true;
85 methodSignaturesList = genType.getMethodDefinitions();
86 if (methodSignaturesList != null) {
87 for (MethodSignature methodSignature : methodSignaturesList) { // loop
91 if (methodSignature.getName().equals("getByteLeaf")) {
92 getByteLeafMethodFound = true;
94 nameReturnParamType = methodSignature.getReturnType().getName();
95 } else if (methodSignature.getName().equals("setByteLeaf")) {
96 setByteLeafMethodFound = true;
98 List<Parameter> parameters = methodSignature.getParameters();
99 setByteLeafMethodParamNum = parameters.size();
109 assertTrue(byteTypeFound);
111 assertEquals(classPropertiesNumb,8);
113 assertEquals(toStringPropertiesNum,8);
114 assertEquals(equalPropertiesNum,8);
115 assertEquals(hashPropertiesNum,8);
116 assertTrue(leafParentFound);
118 assertNotNull(methodSignaturesList);
120 assertTrue(getByteLeafMethodFound);
121 assertEquals(nameReturnParamType,"ByteType");
123 assertFalse(setByteLeafMethodFound);
124 assertEquals(0, setByteLeafMethodParamNum);