ONOS-3650 Device driver multiple inheritance

Change-Id: Ib7b72d44533d4e63c4122662b50485243562aa21
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java
index e3d6910..883c8ab 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverDataTest.java
@@ -20,6 +20,8 @@
 import org.junit.Test;
 import org.onosproject.net.DeviceId;
 
+import java.util.ArrayList;
+
 import static org.junit.Assert.*;
 import static org.onosproject.net.DeviceId.deviceId;
 
@@ -32,7 +34,7 @@
 
     @Before
     public void setUp() {
-        ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a",
+        ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a",
                                 ImmutableMap.of(TestBehaviour.class,
                                                 TestBehaviourImpl.class),
                                 ImmutableMap.of("foo", "bar"));
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java
index 717cda2..5e4552d 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverHandlerTest.java
@@ -19,6 +19,8 @@
 import org.junit.Before;
 import org.junit.Test;
 
+import java.util.ArrayList;
+
 import static org.junit.Assert.assertSame;
 import static org.junit.Assert.assertTrue;
 
@@ -30,7 +32,7 @@
 
     @Before
     public void setUp() {
-        ddc = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a",
+        ddc = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a",
                                 ImmutableMap.of(TestBehaviour.class,
                                                 TestBehaviourImpl.class,
                                                 TestBehaviourTwo.class,
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverProviderTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverProviderTest.java
index 4568fd9..5c9f5e0 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverProviderTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverProviderTest.java
@@ -18,6 +18,7 @@
 import com.google.common.collect.ImmutableMap;
 import org.junit.Test;
 
+import java.util.ArrayList;
 import java.util.Set;
 
 import static com.google.common.collect.ImmutableSet.of;
@@ -28,15 +29,15 @@
     @Test
     public void basics() {
         DefaultDriverProvider ddp = new DefaultDriverProvider();
-        DefaultDriver one = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a",
+        DefaultDriver one = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a",
                                               ImmutableMap.of(TestBehaviour.class,
                                                               TestBehaviourImpl.class),
                                               ImmutableMap.of("foo", "bar"));
-        DefaultDriver two = new DefaultDriver("foo.bar", null, "", "", "",
+        DefaultDriver two = new DefaultDriver("foo.bar", new ArrayList<>(), "", "", "",
                                               ImmutableMap.of(TestBehaviourTwo.class,
                                                               TestBehaviourTwoImpl.class),
                                               ImmutableMap.of("goo", "wee"));
-        DefaultDriver three = new DefaultDriver("goo.foo", null, "BigTop", "better", "2.2",
+        DefaultDriver three = new DefaultDriver("goo.foo", new ArrayList<>(), "BigTop", "better", "2.2",
                                                 ImmutableMap.of(TestBehaviourTwo.class,
                                                                 TestBehaviourTwoImpl.class),
                                                 ImmutableMap.of("goo", "gee"));
diff --git a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
index 01cc7a1..9e7adc3 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/DefaultDriverTest.java
@@ -18,6 +18,8 @@
 import com.google.common.collect.ImmutableMap;
 import org.junit.Test;
 
+import java.util.ArrayList;
+
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.onosproject.net.driver.DefaultDriverDataTest.DEVICE_ID;
@@ -26,7 +28,7 @@
 
     @Test
     public void basics() {
-        DefaultDriver ddp = new DefaultDriver("foo.base", null, "Circus", "lux", "1.2a",
+        DefaultDriver ddp = new DefaultDriver("foo.base", new ArrayList<>(), "Circus", "lux", "1.2a",
                                               ImmutableMap.of(TestBehaviour.class,
                                                               TestBehaviourImpl.class,
                                                               TestBehaviourTwo.class,
@@ -62,12 +64,12 @@
 
     @Test
     public void merge() {
-        DefaultDriver one = new DefaultDriver("foo.bar", null, "Circus", "lux", "1.2a",
+        DefaultDriver one = new DefaultDriver("foo.bar", new ArrayList<>(), "Circus", "lux", "1.2a",
                                               ImmutableMap.of(TestBehaviour.class,
                                                               TestBehaviourImpl.class),
                                               ImmutableMap.of("foo", "bar"));
         Driver ddc =
-                one.merge(new DefaultDriver("foo.bar", null, "", "", "",
+                one.merge(new DefaultDriver("foo.bar", new ArrayList<>(), "", "", "",
                                             ImmutableMap.of(TestBehaviourTwo.class,
                                                             TestBehaviourTwoImpl.class),
                                             ImmutableMap.of("goo", "wee")));
diff --git a/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourImpl2.java b/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourImpl2.java
new file mode 100644
index 0000000..5661033
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourImpl2.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.driver;
+
+/**
+ * Test behaviour.
+ */
+public class TestBehaviourImpl2 extends AbstractHandlerBehaviour implements TestBehaviour {
+}
diff --git a/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourThree.java b/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourThree.java
new file mode 100644
index 0000000..ca45b75
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourThree.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.driver;
+
+/**
+ * Test behaviour.
+ */
+public interface TestBehaviourThree extends HandlerBehaviour {
+}
diff --git a/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourThreeImpl.java b/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourThreeImpl.java
new file mode 100644
index 0000000..4b4c4e2
--- /dev/null
+++ b/core/api/src/test/java/org/onosproject/net/driver/TestBehaviourThreeImpl.java
@@ -0,0 +1,22 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.onosproject.net.driver;
+
+/**
+ * Test behaviour.
+ */
+public class TestBehaviourThreeImpl extends AbstractHandlerBehaviour implements TestBehaviourThree {
+}
diff --git a/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java b/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java
index 15abc2b..e82d559 100644
--- a/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java
+++ b/core/api/src/test/java/org/onosproject/net/driver/XmlDriverLoaderTest.java
@@ -16,6 +16,7 @@
 package org.onosproject.net.driver;
 
 import org.junit.Test;
+import org.onosproject.net.DeviceId;
 
 import java.io.IOException;
 import java.io.InputStream;
@@ -77,4 +78,38 @@
         driver.createBehaviour(new DefaultDriverData(driver, DEVICE_ID), TestBehaviour.class);
     }
 
+    @Test
+    public void multipleDrivers() throws IOException {
+        XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader());
+        InputStream stream = getClass().getResourceAsStream("drivers.multipleInheritance.xml");
+        DriverProvider provider = loader.loadDrivers(stream, null);
+        Iterator<Driver> iterator = provider.getDrivers().iterator();
+        Driver driver;
+        do {
+            driver = iterator.next();
+        } while (!driver.name().equals("foo.2"));
+        assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviour.class));
+        assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviourTwo.class));
+    }
+
+    @Test
+    public void multipleDriversSameBehaviors() throws IOException {
+        XmlDriverLoader loader = new XmlDriverLoader(getClass().getClassLoader());
+        InputStream stream = getClass().getResourceAsStream("drivers.sameMultipleInheritance.xml");
+        DriverProvider provider = loader.loadDrivers(stream, null);
+        Iterator<Driver> iterator = provider.getDrivers().iterator();
+        Driver driver;
+        do {
+            driver = iterator.next();
+        } while (!driver.name().equals("foo.2"));
+        assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviour.class));
+        Behaviour b2 = driver.createBehaviour(new DefaultDriverHandler(
+                                                      new DefaultDriverData(
+                                                              driver, DeviceId.deviceId("test_device"))),
+                                              TestBehaviour.class);
+        assertTrue("incorrect multiple same behaviour inheritance", b2.getClass()
+                .getSimpleName().equals("TestBehaviourImpl2"));
+        assertTrue("incorrect multiple behaviour inheritance", driver.hasBehaviour(TestBehaviourTwo.class));
+    }
+
 }