Fix Revision confusion
[netconf.git] / restconf / restconf-nb-rfc8040 / src / test / java / org / opendaylight / restconf / nb / rfc8040 / services / simple / impl / RestconfSchemaServiceTest.java
index d3c0a19cd94f82c3639114d7ca3eec96816c46f8..667925bfaf729453097519294aa51de87ba39663 100644 (file)
@@ -5,7 +5,6 @@
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
  * and is available at http://www.eclipse.org/legal/epl-v10.html
  */
-
 package org.opendaylight.restconf.nb.rfc8040.services.simple.impl;
 
 import static org.junit.Assert.assertEquals;
@@ -14,19 +13,15 @@ import static org.junit.Assert.assertNull;
 import static org.junit.Assert.fail;
 import static org.mockito.Mockito.when;
 
-import com.google.common.collect.ImmutableClassToInstanceMap;
-import java.util.HashMap;
 import org.junit.Before;
 import org.junit.Rule;
 import org.junit.Test;
 import org.junit.rules.ExpectedException;
 import org.mockito.Mock;
 import org.mockito.MockitoAnnotations;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
-import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
-import org.opendaylight.controller.md.sal.dom.broker.impl.mount.DOMMountPointServiceImpl;
-import org.opendaylight.controller.md.sal.dom.broker.spi.mount.SimpleDOMMountPoint;
+import org.opendaylight.mdsal.dom.api.DOMMountPointService;
 import org.opendaylight.mdsal.dom.api.DOMYangTextSourceProvider;
+import org.opendaylight.mdsal.dom.broker.DOMMountPointServiceImpl;
 import org.opendaylight.restconf.common.errors.RestconfDocumentedException;
 import org.opendaylight.restconf.common.errors.RestconfError;
 import org.opendaylight.restconf.common.schema.SchemaExportContext;
@@ -36,7 +31,7 @@ import org.opendaylight.restconf.nb.rfc8040.handlers.SchemaContextHandler;
 import org.opendaylight.restconf.nb.rfc8040.services.simple.api.RestconfSchemaService;
 import org.opendaylight.restconf.nb.rfc8040.utils.RestconfConstants;
 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.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@@ -63,8 +58,6 @@ public class RestconfSchemaServiceTest {
     @Mock
     private SchemaContextHandler mockContextHandler;
     @Mock
-    private DOMMountPointServiceHandler mockMountPointHandler;
-    @Mock
     private DOMYangTextSourceProvider sourceProvider;
 
     // schema context with modules
@@ -74,10 +67,6 @@ public class RestconfSchemaServiceTest {
     // schema context with mount points
     private SchemaContext schemaContextWithMountPoints;
 
-    // mount point with schema context with modules behind mount point
-    private DOMMountPoint mountPoint;
-    // mount point with null schema context
-    private DOMMountPoint mountPointWithNullSchemaContext;
     // mount point service
     private DOMMountPointService mountPointService;
 
@@ -85,32 +74,24 @@ public class RestconfSchemaServiceTest {
     public void setup() throws Exception {
         MockitoAnnotations.initMocks(this);
 
-        this.schemaContext = YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules"));
+        this.schemaContext = YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules"));
         this.schemaContextBehindMountPoint = YangParserTestUtils
-                .parseYangSources(TestRestconfUtils.loadFiles("/modules/modules-behind-mount-point"));
+                .parseYangFiles(TestRestconfUtils.loadFiles("/modules/modules-behind-mount-point"));
         this.schemaContextWithMountPoints =
-                YangParserTestUtils.parseYangSources(TestRestconfUtils.loadFiles("/modules/mount-points"));
-
-        // create and register mount points
-        this.mountPoint = SimpleDOMMountPoint.create(
-                YangInstanceIdentifier.of(QName.create("mount:point:1", "2016-01-01", "cont")),
-                ImmutableClassToInstanceMap.copyOf(new HashMap<>()),
-                this.schemaContextBehindMountPoint
-        );
-
-        this.mountPointWithNullSchemaContext = SimpleDOMMountPoint.create(
-                YangInstanceIdentifier.of(QName.create("mount:point:2", "2016-01-01", "cont")),
-                ImmutableClassToInstanceMap.copyOf(new HashMap<>()),
-                null
-        );
+                YangParserTestUtils.parseYangFiles(TestRestconfUtils.loadFiles("/modules/mount-points"));
 
         this.mountPointService = new DOMMountPointServiceImpl();
-        ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPoint);
-        ((DOMMountPointServiceImpl) this.mountPointService).registerMountPoint(this.mountPointWithNullSchemaContext);
-        when(this.mockMountPointHandler.get()).thenReturn(this.mountPointService);
-
-        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler, this.mockMountPointHandler,
-                sourceProvider);
+        // create and register mount points
+        mountPointService
+                .createMountPoint(YangInstanceIdentifier.of(QName.create("mount:point:1", "2016-01-01", "cont")))
+                .addInitialSchemaContext(schemaContextBehindMountPoint)
+                .register();
+        mountPointService
+                .createMountPoint(YangInstanceIdentifier.of(QName.create("mount:point:2", "2016-01-01", "cont")))
+                .register();
+
+        this.schemaService = new RestconfSchemaServiceImpl(this.mockContextHandler,
+                DOMMountPointServiceHandler.newInstance(mountPointService), sourceProvider);
     }
 
     /**
@@ -139,8 +120,7 @@ public class RestconfSchemaServiceTest {
         assertNotNull("Existing module should be found", module);
 
         assertEquals("Not expected module name", "module1", module.getName());
-        assertEquals("Not expected module revision", "2014-01-01",
-                SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()));
+        assertEquals("Not expected module revision", Revision.ofNullable("2014-01-01"), module.getRevision());
         assertEquals("Not expected module namespace", "module:1", module.getNamespace().toString());
     }
 
@@ -180,8 +160,7 @@ public class RestconfSchemaServiceTest {
         assertNotNull("Existing module should be found", module);
 
         assertEquals("Not expected module name", "module1-behind-mount-point", module.getName());
-        assertEquals("Not expected module revision", "2014-02-03",
-                SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision()));
+        assertEquals("Not expected module revision", Revision.ofNullable("2014-02-03"), module.getRevision());
         assertEquals("Not expected module namespace", "module:1:behind:mount:point", module.getNamespace().toString());
     }