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;
17 import java.util.Optional;
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.stmt.TestUtils;
27 public class YinFileGroupingStmtTest extends AbstractYinModulesTest {
30 public void testGrouping() throws URISyntaxException {
31 final Module testModule = TestUtils.findModule(context, "config").get();
32 assertNotNull(testModule);
34 final Set<GroupingDefinition> groupings = testModule.getGroupings();
35 assertEquals(1, groupings.size());
37 final Iterator<GroupingDefinition> groupingsIterator = groupings.iterator();
38 final GroupingDefinition grouping = groupingsIterator.next();
39 assertEquals("service-ref", grouping.getQName().getLocalName());
40 assertEquals(Optional.of("Type of references to a particular service instance. This type\n"
41 + "can be used when defining module configuration to refer to a\n"
42 + "particular service instance. Containers using this grouping\n"
43 + "should not define anything else. The run-time implementation\n"
44 + "is expected to inject a reference to the service as the value\n"
45 + "of the container."), grouping.getDescription());
47 final Collection<DataSchemaNode> children = grouping.getChildNodes();
48 assertEquals(2, children.size());
50 final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
51 testModule.getQNameModule(), "type")).get();
52 assertTrue(leaf1.isMandatory());
54 final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
55 testModule.getQNameModule(), "name")).get();
56 assertTrue(leaf2.isMandatory());