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.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27 public class IdentityrefTypeTest {
29 private static List<File> testModels = null;
32 public void loadTestResources() throws URISyntaxException {
33 URI folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").toURI();
34 File folderFile = new File(folderPath);
35 testModels = new ArrayList<>();
37 if (folderFile.isFile()) {
38 testModels.add(folderFile);
40 for (File file : folderFile.listFiles()) {
49 * Test mainly for the method TypeProviderImpl#provideTypeForIdentityref(IdentityrefTypeDefinition)
50 * provideTypeForIdentityref}.
53 public void testIdentityrefYangBuiltInType() {
54 final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
56 assertNotNull(context);
57 final List<Type> genTypes = DefaultBindingGenerator.generateFor(context);
59 GeneratedType moduleGenType = null;
60 for (Type type : genTypes) {
61 if (type.getName().equals("ModuleIdentityrefData")) {
62 if (type instanceof GeneratedType) {
63 moduleGenType = (GeneratedType) type;
68 assertNotNull("Generated type for whole module wasn't found", moduleGenType);
70 String typeName = null;
71 String actualTypeName = "";
72 int numOfActualTypes = 0;
73 List<MethodSignature> methodSignatures = moduleGenType.getMethodDefinitions();
74 for (MethodSignature methodSignature : methodSignatures) {
75 if (methodSignature.getName().equals("getLf")) {
76 Type returnType = methodSignature.getReturnType();
77 if (returnType instanceof ParameterizedType) {
78 typeName = returnType.getName();
79 Type[] actualTypes = ((ParameterizedType) returnType).getActualTypeArguments();
80 numOfActualTypes = actualTypes.length;
81 actualTypeName = actualTypes[0].getName();
85 assertNotNull("The method 'getLf' was not found", typeName);
86 assertEquals("Return type has incorrect name", "Class", typeName);
87 assertEquals("Incorrect number of type parameters", 1, numOfActualTypes);
88 assertEquals("Return type has incorrect actual parameter", "SomeIdentity", actualTypeName);