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.generator.api.BindingGenerator;
21 import org.opendaylight.mdsal.binding.model.api.GeneratedType;
22 import org.opendaylight.mdsal.binding.model.api.MethodSignature;
23 import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
24 import org.opendaylight.mdsal.binding.model.api.Type;
25 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
26 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
28 public class IdentityrefTypeTest {
30 private static List<File> testModels = null;
33 public void loadTestResources() throws URISyntaxException {
34 URI folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").toURI();
35 File folderFile = new File(folderPath);
36 testModels = new ArrayList<>();
38 if (folderFile.isFile()) {
39 testModels.add(folderFile);
41 for (File file : folderFile.listFiles()) {
50 * Test mainly for the method TypeProviderImpl#provideTypeForIdentityref(IdentityrefTypeDefinition)
51 * provideTypeForIdentityref}.
54 public void testIdentityrefYangBuiltInType() {
55 final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
57 assertNotNull(context);
58 final BindingGenerator bindingGen = new BindingGeneratorImpl();
59 final List<Type> genTypes = bindingGen.generateTypes(context);
61 GeneratedType moduleGenType = null;
62 for (Type type : genTypes) {
63 if (type.getName().equals("ModuleIdentityrefData")) {
64 if (type instanceof GeneratedType) {
65 moduleGenType = (GeneratedType) type;
70 assertNotNull("Generated type for whole module wasn't found", moduleGenType);
72 String typeName = null;
73 String actualTypeName = "";
74 int numOfActualTypes = 0;
75 List<MethodSignature> methodSignatures = moduleGenType.getMethodDefinitions();
76 for (MethodSignature methodSignature : methodSignatures) {
77 if (methodSignature.getName().equals("getLf")) {
78 Type returnType = methodSignature.getReturnType();
79 if (returnType instanceof ParameterizedType) {
80 typeName = returnType.getName();
81 Type[] actualTypes = ((ParameterizedType) returnType).getActualTypeArguments();
82 numOfActualTypes = actualTypes.length;
83 actualTypeName = actualTypes[0].getName();
87 assertNotNull("The method 'getLf' was not found", typeName);
88 assertEquals("Return type has incorrect name", "Class", typeName);
89 assertEquals("Incorrect number of type parameters", 1, numOfActualTypes);
90 assertEquals("Return type has incorrect actual parameter", "SomeIdentity", actualTypeName);