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.assertNotNull;
15 import java.net.URISyntaxException;
16 import java.util.ArrayList;
17 import java.util.List;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
21 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
22 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
23 import org.opendaylight.mdsal.binding.model.api.Type;
24 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
26 public class IdentityrefTypeTest {
28 private static List<File> testModels = null;
31 public void loadTestResources() throws URISyntaxException {
32 URI folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").toURI();
33 File folderFile = new File(folderPath);
34 testModels = new ArrayList<>();
36 if (folderFile.isFile()) {
37 testModels.add(folderFile);
39 for (File file : folderFile.listFiles()) {
48 * Test mainly for the method TypeProviderImpl#provideTypeForIdentityref(IdentityrefTypeDefinition)
49 * provideTypeForIdentityref}.
52 public void testIdentityrefYangBuiltInType() {
53 final List<Type> genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangFiles(testModels));
55 GeneratedType moduleGenType = null;
56 for (Type type : genTypes) {
57 if (type.getName().equals("ModuleIdentityrefData")) {
58 if (type instanceof GeneratedType) {
59 moduleGenType = (GeneratedType) type;
64 assertNotNull("Generated type for whole module wasn't found", moduleGenType);
66 String typeName = null;
67 String actualTypeName = "";
68 int numOfActualTypes = 0;
69 List<MethodSignature> methodSignatures = moduleGenType.getMethodDefinitions();
70 for (MethodSignature methodSignature : methodSignatures) {
71 if (methodSignature.getName().equals("getLf")) {
72 Type returnType = methodSignature.getReturnType();
73 if (returnType instanceof ParameterizedType) {
74 typeName = returnType.getName();
75 Type[] actualTypes = ((ParameterizedType) returnType).getActualTypeArguments();
76 numOfActualTypes = actualTypes.length;
77 actualTypeName = actualTypes[0].getName();
81 assertNotNull("The method 'getLf' was not found", typeName);
82 assertEquals("Return type has incorrect name", "Class", typeName);
83 assertEquals("Incorrect number of type parameters", 1, numOfActualTypes);
84 assertEquals("Return type has incorrect actual parameter", "SomeIdentity", actualTypeName);