final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> deviationEntryNode =
Builders.mapEntryBuilder((ListSchemaNode) deviationsSchema);
final QName lastComponent = deviation.getTargetPath().getLastComponent();
- addChildOfModuleBySpecificModule(IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF_QNAME, deviationEntryNode,
- context.findModule(lastComponent.getModule()).get().getName(),
+ addChildOfModuleBySpecificModuleInternal(IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF_QNAME,
+ deviationEntryNode, context.findModule(lastComponent.getModule()).get().getName(),
ietfYangLibraryModule);
- addChildOfModuleBySpecificModule(IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF_QNAME, deviationEntryNode,
- lastComponent.getRevision(), ietfYangLibraryModule);
+ if (lastComponent.getRevision().isPresent()) {
+ addChildOfModuleBySpecificModuleInternal(IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF_QNAME,
+ deviationEntryNode, lastComponent.getRevision(),
+ ietfYangLibraryModule);
+ }
deviations.withChild(deviationEntryNode.build());
}
mapEntryBuilder.withChild(deviations.build());
throw new RestconfDocumentedException(qnameOfSchema.getLocalName() + " doesn't exist.");
}
- /**
- * Mapping childrens of list-module.
- *
- * @param specifiLeafQName
- * qname of leaf
- * @param mapEntryBuilder
- * maptEntryBuilder of parent for mapping children
- * @param value
- * valeu of leaf
- * @param ietfYangLibraryModule
- * ietf-yang-library module
- */
- private static void addChildOfModuleBySpecificModule(final QName specifiLeafQName,
- final DataContainerNodeBuilder<NodeIdentifierWithPredicates, MapEntryNode> mapEntryBuilder,
- final Object value, final Module ietfYangLibraryModule) {
- final DataSchemaNode nameLeaf = findNodeInGroupings(specifiLeafQName, ietfYangLibraryModule);
- mapEntryBuilder.withChild(Builders.leafBuilder((LeafSchemaNode) nameLeaf).withValue(value).build());
- }
-
/**
* Find schema of specific leaf in list-module grouping.
*
// verify loaded modules
verifyLoadedModules((ContainerNode) mods);
+ // verify deviations
+ verifyDeviations((ContainerNode) mods);
}
@Test
}
}
+ /**
+ * Verify whether the loaded modules contain any deviations.
+ *
+ * @param containerNode
+ * modules
+ */
+ private static void verifyDeviations(final ContainerNode containerNode) {
+ int deviationsFound = 0;
+ for (final DataContainerChild child : containerNode.getValue()) {
+ if (child instanceof MapNode) {
+ for (final MapEntryNode mapEntryNode : ((MapNode) child).getValue()) {
+ for (final DataContainerChild dataContainerChild : mapEntryNode
+ .getValue()) {
+ if (dataContainerChild.getNodeType()
+ .equals(IetfYangLibrary.SPECIFIC_MODULE_DEVIATION_LIST_QNAME)) {
+ deviationsFound++;
+ }
+ }
+ }
+ }
+ }
+ Assert.assertTrue(deviationsFound > 0);
+ }
+
/**
* Verify loaded modules.
*
--- /dev/null
+module deviator-test {
+ yang-version 1.1;
+ namespace "http://tech/pantheon/deviator-test";
+ prefix dev;
+
+ organization
+ "PANTHEON.tech s.r.o.";
+
+ import deviatee-test {
+ prefix dv;
+ revision-date 2019-06-11;
+ }
+
+ description
+ "Prepared to set deviations";
+
+ revision 2019-06-11 {
+ description
+ "Deviation test";
+ }
+
+ deviation "/dv:test-container/dv:comment" {
+ deviate add {
+ must
+ "(../dv:comment = 'TEST' or ../dv:comment = 'TEST2')" {
+ error-message "Invalid comment for Deviation test";
+ description
+ "This is just a simple deviation test";
+ }
+ }
+ }
+}