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.hamcrest.CoreMatchers.instanceOf;
11 import static org.hamcrest.MatcherAssert.assertThat;
12 import static org.junit.Assert.assertEquals;
16 import java.net.URISyntaxException;
17 import java.util.ArrayList;
18 import java.util.List;
19 import org.junit.Before;
20 import org.junit.Test;
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.mdsal.binding.model.ri.Types;
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 List<GeneratedType> genTypes = DefaultBindingGenerator.generateFor(
56 YangParserTestUtils.parseYangFiles(testModels));
57 assertEquals(2, genTypes.size());
59 GeneratedType moduleGenType = genTypes.stream()
60 .filter(type -> type.getName().equals("ModuleIdentityrefData"))
64 List<MethodSignature> methodSignatures = moduleGenType.getMethodDefinitions();
65 assertEquals(2, methodSignatures.size());
67 MethodSignature methodSignature = methodSignatures.get(0);
68 assertEquals("getLf", methodSignature.getName());
69 assertEquals("requireLf", methodSignatures.get(1).getName());
71 Type returnType = methodSignature.getReturnType();
72 assertThat(returnType, instanceOf(ParameterizedType.class));
73 ParameterizedType parameterized = (ParameterizedType) returnType;
74 assertEquals(Types.CLASS, parameterized.getRawType());
76 Type[] actualTypes = parameterized.getActualTypeArguments();
77 assertEquals("Incorrect number of type parameters", 1, actualTypes.length);
78 assertEquals("Return type has incorrect actual parameter",
79 "org.opendaylight.yang.gen.v1.urn.identityref.module.rev131109.SomeIdentity",
80 actualTypes[0].getFullyQualifiedName());