Java Code Examples for org.opendaylight.yangtools.yang.model.api.Module#getGroupings()

The following examples show how to use org.opendaylight.yangtools.yang.model.api.Module#getGroupings() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: YinFileGroupingStmtTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGrouping() throws URISyntaxException {
    final Module testModule = TestUtils.findModule(context, "config").get();
    assertNotNull(testModule);

    final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
    assertEquals(1, groupings.size());

    final Iterator<? extends GroupingDefinition> groupingsIterator = groupings.iterator();
    final GroupingDefinition grouping = groupingsIterator.next();
    assertEquals("service-ref", grouping.getQName().getLocalName());
    assertEquals(Optional.of("Type of references to a particular service instance. This type\n"
            + "can be used when defining module configuration to refer to a\n"
            + "particular service instance. Containers using this grouping\n"
            + "should not define anything else. The run-time implementation\n"
            + "is expected to inject a reference to the service as the value\n"
            + "of the container."), grouping.getDescription());

    final Collection<? extends DataSchemaNode> children = grouping.getChildNodes();
    assertEquals(2, children.size());

    final LeafSchemaNode leaf1 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
            testModule.getQNameModule(), "type")).get();
    assertTrue(leaf1.isMandatory());

    final LeafSchemaNode leaf2 = (LeafSchemaNode) grouping.findDataChildByName(QName.create(
            testModule.getQNameModule(), "name")).get();
    assertTrue(leaf2.isMandatory());
}
 
Example 2
Source File: GroupingTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testGrouping() {
    final Module testModule = TestUtils.findModule(ctx, "baz").get();
    final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition grouping = groupings.iterator().next();
    final Collection<? extends DataSchemaNode> children = grouping.getChildNodes();
    assertEquals(5, children.size());
}
 
Example 3
Source File: GroupingAndUsesStmtTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void groupingTest() throws ReactorException {
    final SchemaContext result = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(MODULE, GROUPING_MODULE)
            .buildEffective();
    assertNotNull(result);

    final Module testModule = result.findModules("baz").iterator().next();
    assertNotNull(testModule);

    final Collection<? extends GroupingDefinition> groupings = testModule.getGroupings();
    assertEquals(1, groupings.size());

    final Iterator<? extends GroupingDefinition> groupingsIterator = groupings.iterator();
    final GroupingDefinition grouping = groupingsIterator.next();
    assertEquals("target", grouping.getQName().getLocalName());
    assertEquals(5, grouping.getChildNodes().size());

    final AnyxmlSchemaNode anyXmlNode = (AnyxmlSchemaNode) grouping.getDataChildByName(
        QName.create(testModule.getQNameModule(), "data"));
    assertNotNull(anyXmlNode);
    final ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) grouping.getDataChildByName(
        QName.create(testModule.getQNameModule(), "how"));
    assertNotNull(choiceNode);
    final LeafSchemaNode leafNode = (LeafSchemaNode) grouping.getDataChildByName(
        QName.create(testModule.getQNameModule(), "address"));
    assertNotNull(leafNode);
    final ContainerSchemaNode containerNode = (ContainerSchemaNode) grouping.getDataChildByName(
        QName.create(testModule.getQNameModule(), "port"));
    assertNotNull(containerNode);
    final ListSchemaNode listNode = (ListSchemaNode) grouping.getDataChildByName(
        QName.create(testModule.getQNameModule(), "addresses"));
    assertNotNull(listNode);

    assertEquals(1, grouping.getGroupings().size());
    assertEquals("target-inner", grouping.getGroupings().iterator().next().getQName().getLocalName());

    assertEquals(1, grouping.getTypeDefinitions().size());
    assertEquals("group-type", grouping.getTypeDefinitions().iterator().next().getQName().getLocalName());

    final Collection<? extends UnknownSchemaNode> unknownSchemaNodes = grouping.getUnknownSchemaNodes();
    assertEquals(1, unknownSchemaNodes.size());
    final UnknownSchemaNode extensionUse = unknownSchemaNodes.iterator().next();
    assertEquals("opendaylight", extensionUse.getExtensionDefinition().getQName().getLocalName());
}
 
Example 4
Source File: YangParserWithContextTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Test
public void testUsesFromContext() throws ReactorException {
    final SchemaContext context = RFC7950Reactors.defaultReactor().newBuild()
            .addSources(BAZ, FOO, BAR, SUBFOO, sourceForResource("/context-test/test2.yang"))
            .buildEffective();

    final Module testModule = context.findModule("test2", Revision.of("2013-06-18")).get();
    final Module contextModule = context.findModules(URI.create("urn:opendaylight.baz")).iterator().next();
    assertNotNull(contextModule);
    final Collection<? extends GroupingDefinition> groupings = contextModule.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition grouping = groupings.iterator().next();

    // get node containing uses
    final ContainerSchemaNode peer = (ContainerSchemaNode) testModule.getDataChildByName(QName.create(
            testModule.getQNameModule(), "peer"));
    final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(QName.create(
            testModule.getQNameModule(), "destination"));

    // check uses
    final Collection<? extends UsesNode> uses = destination.getUses();
    assertEquals(1, uses.size());

    // check uses process
    final AnyxmlSchemaNode data_u = (AnyxmlSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "data"));
    assertNotNull(data_u);
    assertTrue(data_u.isAddedByUses());

    final AnyxmlSchemaNode data_g = (AnyxmlSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "data"));
    assertNotNull(data_g);
    assertFalse(data_g.isAddedByUses());
    assertFalse(data_u.equals(data_g));

    final ChoiceSchemaNode how_u = (ChoiceSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "how"));
    assertNotNull(how_u);
    assertTrue(how_u.isAddedByUses());

    final ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "how"));
    assertNotNull(how_g);
    assertFalse(how_g.isAddedByUses());
    assertFalse(how_u.equals(how_g));

    final LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "address"));
    assertNotNull(address_u);
    assertTrue(address_u.isAddedByUses());

    final LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "address"));
    assertNotNull(address_g);
    assertFalse(address_g.isAddedByUses());
    assertFalse(address_u.equals(address_g));

    final ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "port"));
    assertNotNull(port_u);
    assertTrue(port_u.isAddedByUses());

    final ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "port"));
    assertNotNull(port_g);
    assertFalse(port_g.isAddedByUses());
    assertFalse(port_u.equals(port_g));

    final ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName(QName.create(
            testModule.getQNameModule(), "addresses"));
    assertNotNull(addresses_u);
    assertTrue(addresses_u.isAddedByUses());

    final ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName(QName.create(
            contextModule.getQNameModule(), "addresses"));
    assertNotNull(addresses_g);
    assertFalse(addresses_g.isAddedByUses());
    assertFalse(addresses_u.equals(addresses_g));

    // grouping defined by 'uses'
    final Collection<? extends GroupingDefinition> groupings_u = destination.getGroupings();
    assertEquals(0, groupings_u.size());

    // grouping defined in 'grouping' node
    final Collection<? extends GroupingDefinition> groupings_g = grouping.getGroupings();
    assertEquals(1, groupings_g.size());
    final GroupingDefinition grouping_g = groupings_g.iterator().next();
    assertFalse(grouping_g.isAddedByUses());

    final Collection<? extends UnknownSchemaNode> nodes_u = destination.getUnknownSchemaNodes();
    assertEquals(1, nodes_u.size());
    final UnknownSchemaNode node_u = nodes_u.iterator().next();
    assertTrue(node_u.isAddedByUses());

    final Collection<? extends UnknownSchemaNode> nodes_g = grouping.getUnknownSchemaNodes();
    assertEquals(1, nodes_g.size());
    final UnknownSchemaNode node_g = nodes_g.iterator().next();
    assertFalse(node_g.isAddedByUses());
    assertFalse(node_u.equals(node_g));
}