2 * Copyright (c) 2013 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.assertNotNull;
14 import java.util.ArrayList;
15 import java.util.List;
18 import org.junit.Before;
19 import org.junit.BeforeClass;
20 import org.junit.Test;
21 import org.opendaylight.yangtools.sal.binding.generator.api.BindingGenerator;
22 import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
23 import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
24 import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
25 import org.opendaylight.yangtools.sal.binding.model.api.Type;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.model.parser.api.YangModelParser;
29 import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
31 public class IdentityrefTypeTest {
33 private static List<File> testModels = null;
36 public void loadTestResources() {
37 String folderPath = IdentityrefTypeTest.class.getResource("/identityref.yang").getPath();
38 File folderFile = new File(folderPath);
39 testModels = new ArrayList<File>();
41 if (folderFile.isFile()) {
42 testModels.add(folderFile);
44 for (File file : folderFile.listFiles()) {
53 * Test mainly for the method
54 * {@link TypeProviderImpl#provideTypeForIdentityref()
55 * provideTypeForIdentityref}
58 public void testIdentityrefYangBuiltInType() {
60 final YangModelParser parser = new YangParserImpl();
61 final Set<Module> modules = parser.parseYangModels(testModels);
62 final SchemaContext context = parser.resolveSchemaContext(modules);
64 assertNotNull(context);
65 final BindingGenerator bindingGen = new BindingGeneratorImpl();
66 final List<Type> genTypes = bindingGen.generateTypes(context);
68 GeneratedType moduleGenType = null;
69 for (Type type : genTypes) {
70 if (type.getName().equals("ModuleIdentityrefData")) {
71 if (type instanceof GeneratedType) {
72 moduleGenType = (GeneratedType) type;
77 assertNotNull("Generated type for whole module wasn't found", moduleGenType);
79 String typeName = null;
80 String actualTypeName = "";
81 int numOfActualTypes = 0;
82 List<MethodSignature> methodSignatures = moduleGenType.getMethodDefinitions();
83 for (MethodSignature methodSignature : methodSignatures) {
84 if (methodSignature.getName().equals("getLf")) {
85 Type returnType = methodSignature.getReturnType();
86 if (returnType instanceof ParameterizedType) {
87 typeName = returnType.getName();
88 Type[] actualTypes = ((ParameterizedType) returnType).getActualTypeArguments();
89 numOfActualTypes = actualTypes.length;
90 actualTypeName = actualTypes[0].getName();
94 assertNotNull("The method 'getLf' wasn't found", typeName);
95 assertEquals("Return type has incorrect name", "Class", typeName);
96 assertEquals("Incorrect number of type parameters", 1, numOfActualTypes);
97 assertEquals("Return type has incorrect actual parameter", "SomeIdentity", actualTypeName);