Merge "Fixing ForwardingRulesManager code that got lost in a previous merge"
[controller.git] / opendaylight / sal / yang-prototype / code-generator / yang-model-parser-impl / src / test / java / org / opendaylight / controller / yang / model / parser / builder / impl / YangModelBuilderTest.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.builder.impl;
9
10 import static org.junit.Assert.*;
11
12 import java.io.File;
13 import java.text.ParseException;
14 import java.util.Set;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.yang.model.api.AugmentationSchema;
19 import org.opendaylight.controller.yang.model.api.DataNodeContainer;
20 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.controller.yang.model.api.Module;
22 import org.opendaylight.controller.yang.model.parser.impl.YangModelParserImpl;
23
24 public class YangModelBuilderTest {
25
26     private Set<Module> builtModules;
27
28     @Before
29     public void init() {
30         builtModules = parseModules();
31     }
32
33     @Test
34     public void testAugment() throws ParseException {
35         for(Module module : builtModules) {
36             if(module.getName().equals("types2")) {
37                 Set<AugmentationSchema> augmentations = module.getAugmentations();
38                 assertEquals(1, augmentations.size());
39                 AugmentationSchema augment = augmentations.iterator().next();
40                 LeafSchemaNode augmentedLeaf = (LeafSchemaNode)augment.getDataChildByName("ds0ChannelNumber");
41                 assertNotNull(augmentedLeaf);
42                 assertTrue(augmentedLeaf.isAugmenting());
43             } else if(module.getName().equals("types1")) {
44                 DataNodeContainer interfaces = (DataNodeContainer)module.getDataChildByName("interfaces");
45                 DataNodeContainer ifEntry = (DataNodeContainer)interfaces.getDataChildByName("ifEntry");
46                 assertNotNull(ifEntry);
47             } else {
48                 fail("unexpected module");
49             }
50         }
51     }
52
53     private Set<Module> parseModules() {
54         String yangFilesDir = "src/test/resources/model";
55         File resourceDir = new File(yangFilesDir);
56
57         String[] dirList = resourceDir.list();
58         String[] absFiles = new String[dirList.length];
59
60         int i = 0;
61         for (String fileName : dirList) {
62             File abs = new File(resourceDir, fileName);
63             absFiles[i] = abs.getAbsolutePath();
64             i++;
65         }
66
67         YangModelParserImpl parser = new YangModelParserImpl();
68         Set<Module> modules = parser.parseYangModels(absFiles);
69
70         return modules;
71     }
72
73 }