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