import org.opendaylight.restconf.nb.rfc8040.TestRestconfUtils;
import org.opendaylight.restconf.nb.rfc8040.utils.parser.ParserIdentifier;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.Revision;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
@BeforeClass
public static void loadTestSchemaContextAndModules() throws Exception {
schemaContext =
- YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules/restconf-module-testing"));
- schemaContextMonitoring = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules"));
+ YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules/restconf-module-testing"));
+ schemaContextMonitoring = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"));
modules = schemaContextMonitoring.getModules();
modulesRest = YangParserTestUtils
- .parseYangSources(TestRestconfUtils.loadFiles("/modules/restconf-module-testing")).getModules();
+ .parseYangFiles(TestRestconfUtils.loadFiles("/modules/restconf-module-testing")).getModules();
}
@Before
when(this.leafDescription.getQName()).thenReturn(QName.create("", RestconfMappingNodeConstants.DESCRIPTION));
when(this.leafReplaySupport.getQName()).thenReturn(
QName.create("", RestconfMappingNodeConstants.REPLAY_SUPPORT));
- when(this.leafReplayLog.getQName()).thenReturn(QName.create(RestconfMappingNodeConstants.REPLAY_LOG));
+ when(this.leafReplayLog.getQName()).thenReturn(QName.create("", RestconfMappingNodeConstants.REPLAY_LOG));
when(this.leafEvents.getQName()).thenReturn(QName.create("", RestconfMappingNodeConstants.EVENTS));
}
@Test
public void restconfMappingNodeTest() {
// write modules into list module in Restconf
- final Module ietfYangLibMod =
- schemaContext.findModuleByNamespaceAndRevision(IetfYangLibrary.URI_MODULE, IetfYangLibrary.DATE);
- final NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> modules =
+ final Module ietfYangLibMod = schemaContext.findModule(IetfYangLibrary.MODULE_QNAME).get();
+ final NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> mods =
RestconfMappingNodeUtil.mapModulesByIetfYangLibraryYang(RestconfMappingNodeUtilTest.modules,
ietfYangLibMod, schemaContext, "1");
// verify loaded modules
- verifyLoadedModules((ContainerNode) modules);
+ verifyLoadedModules((ContainerNode) mods);
+ // verify deviations
+ verifyDeviations((ContainerNode) mods);
}
@Test
public void restconfStateCapabilitesTest() {
- final Module monitoringModule = schemaContextMonitoring
- .findModuleByNamespaceAndRevision(MonitoringModule.URI_MODULE, MonitoringModule.DATE);
+ final Module monitoringModule = schemaContextMonitoring.findModule(MonitoringModule.MODULE_QNAME).get();
final NormalizedNode<NodeIdentifier, Collection<DataContainerChild<? extends PathArgument, ?>>> normNode =
RestconfMappingNodeUtil.mapCapabilites(monitoringModule);
assertNotNull(normNode);
final List<Object> listOfValues = new ArrayList<>();
- for (final DataContainerChild<? extends PathArgument, ?> child : ((ContainerNode) normNode).getValue()) {
+ for (final DataContainerChild<? extends PathArgument, ?> child : normNode.getValue()) {
if (child.getNodeType().equals(MonitoringModule.CONT_CAPABILITES_QNAME)) {
for (final DataContainerChild<? extends PathArgument, ?> dataContainerChild : ((ContainerNode) child)
.getValue()) {
final Instant start = Instant.now();
final String outputType = "XML";
final URI uri = new URI("uri");
- final Module monitoringModule = schemaContextMonitoring
- .findModuleByNamespaceAndRevision(MonitoringModule.URI_MODULE, MonitoringModule.DATE);
+ final Module monitoringModule = schemaContextMonitoring.findModule(MonitoringModule.MODULE_QNAME).orElse(null);
final boolean exist = true;
final Map<QName, Object> map =
final Instant start = Instant.now();
final String outputType = "JSON";
final URI uri = new URI("uri");
- final Module monitoringModule = schemaContextMonitoring
- .findModuleByNamespaceAndRevision(MonitoringModule.URI_MODULE, MonitoringModule.DATE);
+ final Module monitoringModule = schemaContextMonitoring.findModule(MonitoringModule.MODULE_QNAME).orElse(null);
final boolean exist = true;
final Map<QName, Object> map = prepareMap("notifi", uri, start, outputType);
map.put(MonitoringModule.LEAF_DESCR_STREAM_QNAME, "Notifi");
- final QName notifiQName = QName.create("urn:nested:module", "2014-06-3", "notifi");
+ final QName notifiQName = QName.create("urn:nested:module", "2014-06-03", "notifi");
final NormalizedNode<?, ?> mappedData =
RestconfMappingNodeUtil.mapYangNotificationStreamByIetfRestconfMonitoring(notifiQName,
schemaContextMonitoring.getNotifications(), start, outputType, uri, monitoringModule, exist);
}
}
+ /**
+ * 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.
*
for (final DataContainerChild<? extends PathArgument, ?> child : containerNode.getValue()) {
if (child instanceof LeafNode) {
- assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, ((LeafNode<?>) child).getNodeType());
+ assertEquals(IetfYangLibrary.MODULE_SET_ID_LEAF_QNAME, child.getNodeType());
}
if (child instanceof MapNode) {
- assertEquals(IetfYangLibrary.MODULE_QNAME_LIST, ((MapNode) child).getNodeType());
+ assertEquals(IetfYangLibrary.MODULE_QNAME_LIST, child.getNodeType());
for (final MapEntryNode mapEntryNode : ((MapNode) child).getValue()) {
String name = "";
String revision = "";
.getValue()) {
switch (dataContainerChild.getNodeType().getLocalName()) {
case IetfYangLibrary.SPECIFIC_MODULE_NAME_LEAF:
- name = String.valueOf(((LeafNode<?>) dataContainerChild).getValue());
+ name = String.valueOf(dataContainerChild.getValue());
break;
case IetfYangLibrary.SPECIFIC_MODULE_REVISION_LEAF:
- revision = String.valueOf(((LeafNode<?>) dataContainerChild).getValue());
+ revision = String.valueOf(dataContainerChild.getValue());
break;
default :
LOG.info("Unknown local name '{}' of node.",
final String revision = loadedModules.get(name);
assertNotNull("Expected module not found", revision);
- assertEquals("Not correct revision of loaded module",
- SimpleDateFormatUtil.getRevisionFormat().format(m.getRevision()), revision);
+ assertEquals("Incorrect revision of loaded module", Revision.ofNullable(revision), m.getRevision());
loadedModules.remove(name);
}