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