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.net.URISyntaxException;
17 import java.util.List;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
21 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
22 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
23 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
24 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
25 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter;
26 import org.opendaylight.yangtools.sal.binding.model.api.Type;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
29 public class GeneratedTypesBitsTest {
33 public void testGeneretedTypesBitsTest() throws URISyntaxException {
34 final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();
36 final SchemaContext context = SupportTestUtil.resolveSchemaContextFromFiles(yangTypesPath);
37 assertTrue(context != null);
39 final BindingGenerator bindingGen = new BindingGeneratorImpl();
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 String nameMethodeParamType = "";
55 boolean getByteLeafMethodFound = false;
56 boolean setByteLeafMethodFound = false;
57 int setByteLeafMethodParamNum = 0;
59 for (final Type type : genTypes) {
60 if (type instanceof GeneratedTransferObject) { // searching for
62 final GeneratedTransferObject genTO = (GeneratedTransferObject) type;
63 if (genTO.getName().equals("ByteType")) {
65 List<GeneratedProperty> genProperties = genTO.getProperties();
66 classPropertiesNumb = genProperties.size();
69 genProperties = genTO.getToStringIdentifiers();
70 toStringPropertiesNum = genProperties.size();
73 genProperties = genTO.getEqualsIdentifiers();
74 equalPropertiesNum = genProperties.size();
77 genProperties = genTO.getHashCodeIdentifiers();
78 hashPropertiesNum = genProperties.size();
81 } else if (type instanceof GeneratedType) { // searching for
83 // LeafParameterContainer
84 final GeneratedType genType = (GeneratedType) type;
85 if (genType.getName().equals("LeafParentContainer")) {
86 leafParentFound = true;
88 methodSignaturesList = genType.getMethodDefinitions();
89 if (methodSignaturesList != null) {
90 for (MethodSignature methodSignature : methodSignaturesList) { // loop
94 if (methodSignature.getName().equals("getByteLeaf")) {
95 getByteLeafMethodFound = true;
97 nameReturnParamType = methodSignature.getReturnType().getName();
98 } else if (methodSignature.getName().equals("setByteLeaf")) {
99 setByteLeafMethodFound = true;
101 List<Parameter> parameters = methodSignature.getParameters();
102 setByteLeafMethodParamNum = parameters.size();
103 for (Parameter parameter : parameters) {
104 nameMethodeParamType = parameter.getType().getName();
116 assertTrue(byteTypeFound);
118 assertEquals(classPropertiesNumb,8);
120 assertEquals(toStringPropertiesNum,8);
121 assertEquals(equalPropertiesNum,8);
122 assertEquals(hashPropertiesNum,8);
123 assertTrue(leafParentFound);
125 assertNotNull(methodSignaturesList);
127 assertTrue(getByteLeafMethodFound);
128 assertEquals(nameReturnParamType,"ByteType");
130 assertFalse(setByteLeafMethodFound);
131 assertEquals(0, setByteLeafMethodParamNum);