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;
18 import org.junit.Test;
19 import org.opendaylight.yangtools.yang.common.QName;
20 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
22 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
23 import org.opendaylight.yangtools.yang.model.api.Module;
24 import org.opendaylight.yangtools.yang.stmt.TestUtils;
26 public class YinFileGroupingStmtTest extends AbstractYinModulesTest {
29 public void testGrouping() throws URISyntaxException {
30 final Module testModule = TestUtils.findModule(context, "config").get();
31 assertNotNull(testModule);
33 final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
34 assertEquals(1, groupings.size());
36 final Iterator<? extends GroupingDefinition> groupingsIterator = groupings.iterator();
37 final GroupingDefinition grouping = groupingsIterator.next();
38 assertEquals("service-ref", grouping.getQName().getLocalName());
39 assertEquals(Optional.of("Type of references to a particular service instance. This type\n"
40 + "can be used when defining module configuration to refer to a\n"
41 + "particular service instance. Containers using this grouping\n"
42 + "should not define anything else. The run-time implementation\n"
43 + "is expected to inject a reference to the service as the value\n"
44 + "of the container."), grouping.getDescription());
46 final Collection<? extends DataSchemaNode> children = grouping.getChildNodes();
47 assertEquals(2, children.size());
49 final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
50 testModule.getQNameModule(), "type")).get();
51 assertTrue(leaf1.isMandatory());
53 final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
54 testModule.getQNameModule(), "name")).get();
55 assertTrue(leaf2.isMandatory());