use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode in project yangtools by opendaylight.
the class NotificationStmtTest method notificationTest.
@Test
public void notificationTest() throws Exception {
final SchemaContext result = TestUtils.parseYangSource("/model/baz.yang", "/model/bar.yang");
assertNotNull(result);
final Module testModule = result.findModules("baz").iterator().next();
assertNotNull(testModule);
final Collection<? extends NotificationDefinition> notifications = testModule.getNotifications();
assertEquals(1, notifications.size());
final NotificationDefinition notification = notifications.iterator().next();
assertEquals("event", notification.getQName().getLocalName());
assertEquals(3, notification.getChildNodes().size());
LeafSchemaNode leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "event-class"));
assertNotNull(leaf);
leaf = (LeafSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "severity"));
assertNotNull(leaf);
final AnyxmlSchemaNode anyXml = (AnyxmlSchemaNode) notification.getDataChildByName(QName.create(testModule.getQNameModule(), "reporting-entity"));
assertNotNull(anyXml);
}
use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode 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());
}
use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode 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());
}
use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode 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());
}
use of org.opendaylight.yangtools.yang.model.api.AnyxmlSchemaNode in project netconf by opendaylight.
the class DefinitionGenerator method processChildren.
/**
* Processes the nodes.
*/
private ObjectNode processChildren(final ObjectNode parentNode, final Collection<? extends DataSchemaNode> nodes, final String parentName, final ObjectNode definitions, final DefinitionNames definitionNames, final boolean isConfig, final SchemaInferenceStack stack, final OAversion oaversion) throws IOException {
final ObjectNode properties = JsonNodeFactory.instance.objectNode();
final ArrayNode required = JsonNodeFactory.instance.arrayNode();
for (final DataSchemaNode node : nodes) {
stack.enterSchemaTree(node.getQName());
if (!isConfig || node.isConfiguration()) {
/*
Add module name prefix to property name, when needed, when ServiceNow can process colons,
use RestDocGenUtil#resolveNodesName for creating property name
*/
final String propertyName = node.getQName().getLocalName();
final ObjectNode property;
if (node instanceof LeafSchemaNode) {
processLeafNode((LeafSchemaNode) node, propertyName, properties, required, stack, definitions, definitionNames, oaversion);
} else if (node instanceof AnyxmlSchemaNode) {
processAnyXMLNode((AnyxmlSchemaNode) node, propertyName, properties, required);
} else if (node instanceof AnydataSchemaNode) {
processAnydataNode((AnydataSchemaNode) node, propertyName, properties, required);
} else {
if (node instanceof ListSchemaNode || node instanceof ContainerSchemaNode) {
property = processDataNodeContainer((DataNodeContainer) node, parentName, definitions, definitionNames, isConfig, stack, oaversion);
if (!isConfig) {
processActionNodeContainer(node, parentName, definitions, definitionNames, stack, oaversion);
}
} else if (node instanceof LeafListSchemaNode) {
property = processLeafListNode((LeafListSchemaNode) node, stack, definitions, definitionNames, oaversion);
} else if (node instanceof ChoiceSchemaNode) {
for (final CaseSchemaNode variant : ((ChoiceSchemaNode) node).getCases()) {
stack.enterSchemaTree(variant.getQName());
processChoiceNode(variant.getChildNodes(), parentName, definitions, definitionNames, isConfig, stack, properties, oaversion);
stack.exit();
}
stack.exit();
// FIXME dangerous statement here! Try to rework without continue.
continue;
} else {
throw new IllegalArgumentException("Unknown DataSchemaNode type: " + node.getClass());
}
properties.set(propertyName, property);
}
}
stack.exit();
}
parentNode.set(PROPERTIES_KEY, properties);
setRequiredIfNotEmpty(parentNode, required);
return properties;
}
Aggregations