2 * Copyright (c) 2016 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.yangtools.yang.stmt.yin;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
14 import java.net.URISyntaxException;
15 import java.util.Collection;
16 import java.util.Iterator;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.common.QName;
21 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
22 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
23 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
24 import org.opendaylight.yangtools.yang.model.api.Module;
25 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
26 import org.opendaylight.yangtools.yang.stmt.TestUtils;
28 public class YinFileGroupingStmtTest {
30 private Set<Module> modules;
33 public void init() throws URISyntaxException, ReactorException {
34 modules = TestUtils.loadYinModules(getClass().getResource("/semantic-statement-parser/yin/modules").toURI());
35 assertEquals(9, modules.size());
39 public void testGrouping() throws URISyntaxException {
40 final Module testModule = TestUtils.findModule(modules, "config");
41 assertNotNull(testModule);
43 final Set<GroupingDefinition> groupings = testModule.getGroupings();
44 assertEquals(1, groupings.size());
46 final Iterator<GroupingDefinition> groupingsIterator = groupings.iterator();
47 final GroupingDefinition grouping = groupingsIterator.next();
48 assertEquals("service-ref", grouping.getQName().getLocalName());
49 assertEquals("Type of references to a particular service instance. This type\n" +
50 "can be used when defining module configuration to refer to a\n" +
51 "particular service instance. Containers using this grouping\n" +
52 "should not define anything else. The run-time implementation\n" +
53 "is expected to inject a reference to the service as the value\n" +
54 "of the container.", grouping.getDescription());
56 final Collection<DataSchemaNode> children = grouping.getChildNodes();
57 assertEquals(2, children.size());
59 final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
60 testModule.getQNameModule(), "type"));
62 assertTrue(leaf1.getConstraints().isMandatory());
64 final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
65 testModule.getQNameModule(), "name"));
67 assertTrue(leaf2.getConstraints().isMandatory());