74cfed5fb13bbfaf8eeed80298216869bc3a8286
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / test / java / org / opendaylight / controller / yang / model / parser / impl / YangModelParserTest.java
1 /*
2  * Copyright (c) 2013 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.controller.yang.model.parser.impl;
9
10 import static org.junit.Assert.*;
11
12 import java.io.IOException;
13 import java.util.Set;
14
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.controller.model.util.Int32;
18 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
19 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
20 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
22 import org.opendaylight.controller.yang.model.api.Module;
23 import org.opendaylight.controller.yang.model.parser.api.YangModelParser;
24
25 public class YangModelParserTest {
26
27     private final String testFile1 = "src/test/resources/model/testfile1.yang";
28     private final String testFile2 = "src/test/resources/model/testfile2.yang";
29     private YangModelParser tested;
30
31     @Before
32     public void init() throws IOException {
33         tested = new YangModelParserImpl();
34     }
35
36     @Test
37     public void testAugment() {
38         Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
39         assertEquals(2, modules.size());
40
41         Module m2 = null;
42         for(Module m : modules) {
43             if(m.getName().equals("types2")) {
44                 m2 = m;
45             }
46         }
47         assertNotNull(m2);
48
49         AugmentationSchema augment = m2.getAugmentations().iterator().next();
50         assertNotNull(augment);
51     }
52
53     @Test
54     public void testAugmentTarget() {
55         Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
56         assertEquals(2, modules.size());
57
58         Module m1 = null;
59         for(Module m : modules) {
60             if(m.getName().equals("types1")) {
61                 m1 = m;
62             }
63         }
64         assertNotNull(m1);
65
66         ContainerSchemaNode container = (ContainerSchemaNode)m1.getDataChildByName("interfaces");
67         assertNotNull(container);
68
69         ListSchemaNode list = (ListSchemaNode)container.getDataChildByName("ifEntry");
70         assertNotNull(list);
71
72         LeafSchemaNode leaf = (LeafSchemaNode)list.getDataChildByName("ds0ChannelNumber");
73         assertNotNull(leaf);
74     }
75
76     @Test
77     public void testTypeDef() {
78         Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
79         assertEquals(2, modules.size());
80
81         Module m1 = null;
82         for(Module m : modules) {
83             if(m.getName().equals("types1")) {
84                 m1 = m;
85             }
86         }
87         assertNotNull(m1);
88
89         LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("testleaf");
90         assertTrue(testleaf.getType().getBaseType() instanceof Int32);
91     }
92
93 }