2 * Copyright (c) 2013 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.controller.yang.model.parser.builder.impl;
10 import static org.junit.Assert.*;
13 import java.text.ParseException;
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;
24 public class YangModelBuilderTest {
26 private Set<Module> builtModules;
30 builtModules = parseModules();
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);
48 fail("unexpected module");
53 private Set<Module> parseModules() {
54 String yangFilesDir = "src/test/resources/model";
55 File resourceDir = new File(yangFilesDir);
57 String[] dirList = resourceDir.list();
58 String[] absFiles = new String[dirList.length];
61 for (String fileName : dirList) {
62 File abs = new File(resourceDir, fileName);
63 absFiles[i] = abs.getAbsolutePath();
67 YangModelParserImpl parser = new YangModelParserImpl();
68 Set<Module> modules = parser.parseYangModels(absFiles);