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.impl;
10 import static org.junit.Assert.*;
12 import java.io.IOException;
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;
25 public class YangModelParserTest {
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;
32 public void init() throws IOException {
33 tested = new YangModelParserImpl();
37 public void testAugment() {
38 Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
39 assertEquals(2, modules.size());
42 for(Module m : modules) {
43 if(m.getName().equals("types2")) {
49 AugmentationSchema augment = m2.getAugmentations().iterator().next();
50 assertNotNull(augment);
54 public void testAugmentTarget() {
55 Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
56 assertEquals(2, modules.size());
59 for(Module m : modules) {
60 if(m.getName().equals("types1")) {
66 ContainerSchemaNode container = (ContainerSchemaNode)m1.getDataChildByName("interfaces");
67 assertNotNull(container);
69 ListSchemaNode list = (ListSchemaNode)container.getDataChildByName("ifEntry");
72 LeafSchemaNode leaf = (LeafSchemaNode)list.getDataChildByName("ds0ChannelNumber");
77 public void testTypeDef() {
78 Set<Module> modules = tested.parseYangModels(testFile1, testFile2);
79 assertEquals(2, modules.size());
82 for(Module m : modules) {
83 if(m.getName().equals("types1")) {
89 LeafSchemaNode testleaf = (LeafSchemaNode)m1.getDataChildByName("testleaf");
90 assertTrue(testleaf.getType().getBaseType() instanceof Int32);