Bug fix for retrieving multiple DMs together

Change-Id: I20ebd5dacac657bebbb499aee7c6ab1b4eebfdfa
diff --git a/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManager.java b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManager.java
index 9a351ca..ca8a373 100644
--- a/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManager.java
+++ b/incubator/net/src/main/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManager.java
@@ -87,9 +87,22 @@
             MdId mdName, MaIdShort maName, MepId mepId)
                     throws CfmConfigException, SoamConfigException {
         MepEntry mep = cfmMepService.getMep(mdName, maName, mepId);
+        if (mep == null || mep.deviceId() == null) {
+            throw new CfmConfigException("MEP :"
+                    + mdName + "/" + maName + "/" + mepId + " does not exist");
+        } else if (deviceService.getDevice(mep.deviceId()) == null) {
+            throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+                    + mdName + "/" + maName + "/" + mepId + " does not exist");
+        } else if (!deviceService.getDevice(mep.deviceId()).is(SoamDmProgrammable.class)) {
+            throw new CfmConfigException("Device " + mep.deviceId() + " from MEP :"
+                    + mdName + "/" + maName + "/" + mepId +
+                    " does not implement SoamDmProgrammable");
+        }
         log.debug("Retrieving DMs for MD {}, MA {}, MEP {} on Device {}",
                 mdName, maName, mepId, mep.deviceId());
-        return mep.delayMeasurementList();
+
+        return deviceService.getDevice(mep.deviceId())
+                .as(SoamDmProgrammable.class).getAllDms(mdName, maName, mepId);
     };
 
     @Override
diff --git a/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManagerTest.java b/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManagerTest.java
index 251cc71..a3a6d52 100644
--- a/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManagerTest.java
+++ b/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/SoamManagerTest.java
@@ -166,13 +166,19 @@
 
     @Test
     public void testGetAllDms() throws CfmConfigException, SoamConfigException {
+        expect(deviceService.getDevice(DEVICE_ID1)).andReturn(device1).anyTimes();
+        replay(deviceService);
 
         expect(mepService.getMep(MDNAME1, MANAME1, MEPID1)).andReturn(mep1).anyTimes();
         replay(mepService);
 
+        expect(driverService.getDriver(TEST_DRIVER)).andReturn(testDriver).anyTimes();
+        replay(driverService);
+
         Collection<DelayMeasurementEntry> dmEntries =
                 soamManager.getAllDms(MDNAME1, MANAME1, MEPID1);
-        assertEquals(2, dmEntries.size());
+        assertNotNull(dmEntries);
+        assertEquals(1, dmEntries.size());
     }
 
     @Test
diff --git a/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/TestSoamDmProgrammable.java b/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/TestSoamDmProgrammable.java
index 8d010de..9750550 100644
--- a/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/TestSoamDmProgrammable.java
+++ b/incubator/net/src/test/java/org/onosproject/incubator/net/l2monitoring/soam/impl/TestSoamDmProgrammable.java
@@ -93,7 +93,12 @@
     public Collection<DelayMeasurementEntry> getAllDms(
             MdId mdName, MaIdShort maName, MepId mepId)
             throws CfmConfigException, SoamConfigException {
-        return null;
+        Collection<DelayMeasurementEntry> dmEntries = new ArrayList<>();
+        if (mdName.equals(MDNAME1) && maName.equals(MANAME1) && mepId.equals(MEPID1)) {
+            dmEntries.add(dmEntry1);
+            return dmEntries;
+        }
+        return new ArrayList<>();
     }
 
     @Override