Search in sources :

Example 6 with GroupingDefinition

use of org.opendaylight.yangtools.yang.model.api.GroupingDefinition in project yangtools by opendaylight.

the class GroupingTest method testUses.

@Test
public void testUses() {
    // suffix _u = added by uses
    // suffix _g = defined in grouping
    // get grouping
    final Collection<? extends GroupingDefinition> groupings = BAZ.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition grouping = groupings.iterator().next();
    // get node containing uses
    final ContainerSchemaNode peer = (ContainerSchemaNode) FOO.getDataChildByName(fooQName("peer"));
    final ContainerSchemaNode destination = (ContainerSchemaNode) peer.getDataChildByName(fooQName("destination"));
    // check uses
    final Collection<? extends UsesNode> uses = destination.getUses();
    assertEquals(1, uses.size());
    // check uses process
    final AnyxmlSchemaNode data_u = (AnyxmlSchemaNode) destination.getDataChildByName(fooQName("data"));
    assertTrue(data_u.isAddedByUses());
    final AnyxmlSchemaNode data_g = (AnyxmlSchemaNode) grouping.getDataChildByName(bazQName("data"));
    assertFalse(data_g.isAddedByUses());
    assertNotEquals(data_u, data_g);
    final ChoiceSchemaNode how_u = (ChoiceSchemaNode) destination.getDataChildByName(fooQName("how"));
    assertIsAddedByUses(how_u, true);
    assertEquals(2, how_u.getCases().size());
    final ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName(bazQName("how"));
    assertIsAddedByUses(how_g, false);
    assertEquals(2, how_g.getCases().size());
    assertNotEquals(how_u, how_g);
    final LeafSchemaNode address_u = (LeafSchemaNode) destination.getDataChildByName(fooQName("address"));
    assertEquals(Optional.of("1.2.3.4"), address_u.getType().getDefaultValue());
    assertEquals(Optional.of("IP address of target node"), address_u.getDescription());
    assertEquals(Optional.of("address reference added by refine"), address_u.getReference());
    assertEquals(Optional.of(Boolean.FALSE), address_u.effectiveConfig());
    assertTrue(address_u.isAddedByUses());
    assertFalse(address_u.isMandatory());
    final LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName(bazQName("address"));
    assertFalse(address_g.isAddedByUses());
    assertEquals(Optional.empty(), address_g.getType().getDefaultValue());
    assertEquals(Optional.of("Target IP address"), address_g.getDescription());
    assertEquals(Optional.empty(), address_g.getReference());
    assertEquals(Optional.empty(), address_g.effectiveConfig());
    assertTrue(address_g.isMandatory());
    assertNotEquals(address_u, address_g);
    final ContainerSchemaNode port_u = (ContainerSchemaNode) destination.getDataChildByName(fooQName("port"));
    assertIsAddedByUses(port_u, true);
    final ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName(bazQName("port"));
    assertIsAddedByUses(port_g, false);
    assertNotEquals(port_u, port_g);
    final ListSchemaNode addresses_u = (ListSchemaNode) destination.getDataChildByName(fooQName("addresses"));
    assertIsAddedByUses(addresses_u, true);
    final ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName(bazQName("addresses"));
    assertIsAddedByUses(addresses_g, false);
    assertNotEquals(addresses_u, 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();
    assertIsAddedByUses(grouping_g, false);
    assertEquals(0, destination.getUnknownSchemaNodes().size());
    assertEquals(1, grouping.asEffectiveStatement().getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) Test(org.junit.Test)

Example 7 with GroupingDefinition

use of org.opendaylight.yangtools.yang.model.api.GroupingDefinition in project yangtools by opendaylight.

the class GroupingTest method testGrouping.

@Test
public void testGrouping() {
    final Collection<? extends GroupingDefinition> groupings = BAZ.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition grouping = groupings.iterator().next();
    final Collection<? extends DataSchemaNode> children = grouping.getChildNodes();
    assertEquals(5, children.size());
}
Also used : GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Example 8 with GroupingDefinition

use of org.opendaylight.yangtools.yang.model.api.GroupingDefinition in project yangtools by opendaylight.

the class GroupingTest method testUsesUnderModule.

@Test
public void testUsesUnderModule() {
    // suffix _u = added by uses
    // suffix _g = defined in grouping
    // get grouping
    final Collection<? extends GroupingDefinition> groupings = BAZ.getGroupings();
    assertEquals(1, groupings.size());
    final GroupingDefinition grouping = groupings.iterator().next();
    // check uses
    final Collection<? extends UsesNode> uses = FOO.getUses();
    assertEquals(1, uses.size());
    // check uses process
    final AnyxmlSchemaNode data_u = (AnyxmlSchemaNode) FOO.getDataChildByName(fooQName("data"));
    assertTrue(data_u.isAddedByUses());
    final AnyxmlSchemaNode data_g = (AnyxmlSchemaNode) grouping.getDataChildByName(bazQName("data"));
    assertFalse(data_g.isAddedByUses());
    assertNotEquals(data_u, data_g);
    final ChoiceSchemaNode how_u = (ChoiceSchemaNode) FOO.getDataChildByName(fooQName("how"));
    assertIsAddedByUses(how_u, true);
    assertFalse(how_u.isAugmenting());
    final Collection<? extends CaseSchemaNode> cases_u = how_u.getCases();
    assertEquals(2, cases_u.size());
    final CaseSchemaNode interval = how_u.findCaseNodes("interval").iterator().next();
    assertFalse(interval.isAugmenting());
    final LeafSchemaNode name = (LeafSchemaNode) interval.getDataChildByName(fooQName("name"));
    assertTrue(name.isAugmenting());
    final LeafSchemaNode intervalLeaf = (LeafSchemaNode) interval.getDataChildByName(fooQName("interval"));
    assertFalse(intervalLeaf.isAugmenting());
    final ChoiceSchemaNode how_g = (ChoiceSchemaNode) grouping.getDataChildByName(bazQName("how"));
    assertIsAddedByUses(how_g, false);
    assertNotEquals(how_u, how_g);
    final LeafSchemaNode address_u = (LeafSchemaNode) FOO.getDataChildByName(fooQName("address"));
    assertEquals(Optional.empty(), address_u.getType().getDefaultValue());
    assertEquals(Optional.of("Target IP address"), address_u.getDescription());
    assertFalse(address_u.getReference().isPresent());
    assertEquals(Optional.empty(), address_u.effectiveConfig());
    assertTrue(address_u.isAddedByUses());
    final LeafSchemaNode address_g = (LeafSchemaNode) grouping.getDataChildByName(bazQName("address"));
    assertFalse(address_g.isAddedByUses());
    assertEquals(Optional.empty(), address_g.getType().getDefaultValue());
    assertEquals(Optional.of("Target IP address"), address_g.getDescription());
    assertFalse(address_g.getReference().isPresent());
    assertEquals(Optional.empty(), address_g.effectiveConfig());
    assertNotEquals(address_u, address_g);
    final ContainerSchemaNode port_u = (ContainerSchemaNode) FOO.getDataChildByName(fooQName("port"));
    assertIsAddedByUses(port_u, true);
    final ContainerSchemaNode port_g = (ContainerSchemaNode) grouping.getDataChildByName(bazQName("port"));
    assertIsAddedByUses(port_g, false);
    assertNotEquals(port_u, port_g);
    final ListSchemaNode addresses_u = (ListSchemaNode) FOO.getDataChildByName(fooQName("addresses"));
    assertIsAddedByUses(addresses_u, true);
    final ListSchemaNode addresses_g = (ListSchemaNode) grouping.getDataChildByName(bazQName("addresses"));
    assertIsAddedByUses(addresses_g, false);
    assertNotEquals(addresses_u, addresses_g);
    // grouping defined by 'uses'
    final Collection<? extends GroupingDefinition> groupings_u = FOO.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();
    assertIsAddedByUses(grouping_g, false);
    assertEquals(0, grouping.getUnknownSchemaNodes().size());
    assertEquals(1, grouping.asEffectiveStatement().getDeclared().declaredSubstatements(UnrecognizedStatement.class).size());
    final UsesNode un = uses.iterator().next();
    final Collection<? extends AugmentationSchemaNode> usesAugments = un.getAugmentations();
    assertEquals(1, usesAugments.size());
    final AugmentationSchemaNode augment = usesAugments.iterator().next();
    assertEquals(Optional.of("inner augment"), augment.getDescription());
    final Collection<? extends DataSchemaNode> children = augment.getChildNodes();
    assertEquals(1, children.size());
    final DataSchemaNode leaf = children.iterator().next();
    assertTrue(leaf instanceof LeafSchemaNode);
    assertEquals("name", leaf.getQName().getLocalName());
}
Also used : AugmentationSchemaNode(org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode) DataSchemaNode(org.opendaylight.yangtools.yang.model.api.DataSchemaNode) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) UsesNode(org.opendaylight.yangtools.yang.model.api.UsesNode) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) CaseSchemaNode(org.opendaylight.yangtools.yang.model.api.CaseSchemaNode) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) Test(org.junit.Test)

Example 9 with GroupingDefinition

use of org.opendaylight.yangtools.yang.model.api.GroupingDefinition in project yangtools by opendaylight.

the class YangParserWithContextTest method testUsesFromContext.

@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(XMLNamespace.of("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());
}
Also used : ContainerSchemaNode(org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode) ListSchemaNode(org.opendaylight.yangtools.yang.model.api.ListSchemaNode) SchemaContext(org.opendaylight.yangtools.yang.model.api.SchemaContext) LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) ChoiceSchemaNode(org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) AnyxmlSchemaNode(org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode) Test(org.junit.Test)

Example 10 with GroupingDefinition

use of org.opendaylight.yangtools.yang.model.api.GroupingDefinition in project yangtools by opendaylight.

the class YinFileGroupingStmtTest method testGrouping.

@Test
public void testGrouping() {
    final Module testModule = context.findModules("config").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("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());
}
Also used : LeafSchemaNode(org.opendaylight.yangtools.yang.model.api.LeafSchemaNode) Module(org.opendaylight.yangtools.yang.model.api.Module) GroupingDefinition(org.opendaylight.yangtools.yang.model.api.GroupingDefinition) Test(org.junit.Test)

Aggregations

GroupingDefinition (org.opendaylight.yangtools.yang.model.api.GroupingDefinition)18 Test (org.junit.Test)13 LeafSchemaNode (org.opendaylight.yangtools.yang.model.api.LeafSchemaNode)8 Module (org.opendaylight.yangtools.yang.model.api.Module)8 ContainerSchemaNode (org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode)7 DataSchemaNode (org.opendaylight.yangtools.yang.model.api.DataSchemaNode)6 ListSchemaNode (org.opendaylight.yangtools.yang.model.api.ListSchemaNode)6 SchemaContext (org.opendaylight.yangtools.yang.model.api.SchemaContext)5 QName (org.opendaylight.yangtools.yang.common.QName)4 AnyxmlSchemaNode (org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode)4 ChoiceSchemaNode (org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode)4 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)3 RestConfModule (org.opendaylight.netconf.sal.rest.api.Draft02.RestConfModule)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 UsesNode (org.opendaylight.yangtools.yang.model.api.UsesNode)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Before (org.junit.Before)1 AugmentationSchemaNode (org.opendaylight.yangtools.yang.model.api.AugmentationSchemaNode)1 CaseSchemaNode (org.opendaylight.yangtools.yang.model.api.CaseSchemaNode)1