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