06f6e2892198034072fbaa3cae5f9b157600f42f
[yangtools.git] /
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.binding.generator.impl;
9
10 import static org.junit.Assert.assertEquals;
11
12 import java.io.File;
13 import java.net.URISyntaxException;
14 import java.nio.file.Path;
15 import java.util.ArrayList;
16 import java.util.List;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
20
21 public class IdentityrefTypeTest {
22     private static List<File> testModels;
23
24     @Before
25     public void loadTestResources() throws URISyntaxException {
26         final var folderFile = Path.of(IdentityrefTypeTest.class.getResource("/identityref.yang").toURI()).toFile();
27         testModels = new ArrayList<>();
28
29         if (folderFile.isFile()) {
30             testModels.add(folderFile);
31         } else {
32             for (var file : folderFile.listFiles()) {
33                 if (file.isFile()) {
34                     testModels.add(file);
35                 }
36             }
37         }
38     }
39
40     /**
41      * Test mainly for the method TypeProviderImpl#provideTypeForIdentityref(IdentityrefTypeDefinition)
42      * provideTypeForIdentityref}.
43      */
44     @Test
45     public void testIdentityrefYangBuiltInType() {
46         final var genTypes = DefaultBindingGenerator.generateFor(YangParserTestUtils.parseYangFiles(testModels));
47         assertEquals(2, genTypes.size());
48
49         var moduleGenType = genTypes.stream()
50             .filter(type -> type.getName().equals("ModuleIdentityrefData"))
51             .findFirst()
52             .orElseThrow();
53
54         var methodSignatures = moduleGenType.getMethodDefinitions();
55         assertEquals(3, methodSignatures.size());
56
57         assertEquals("implementedInterface", methodSignatures.get(0).getName());
58         var methodSignature = methodSignatures.get(1);
59         assertEquals("getLf", methodSignature.getName());
60         assertEquals("requireLf", methodSignatures.get(2).getName());
61
62         assertEquals("org.opendaylight.yang.gen.v1.urn.identityref.module.rev131109.SomeIdentity",
63             methodSignature.getReturnType().getFullyQualifiedName());
64     }
65 }