Unit tests for some uncovered Intent types

Change-Id: I9ddd0a4f8d12222b6f5c6bc2d127d6082bc0649d
diff --git a/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java
index 7daf09e..196d6ad 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/MplsIntentTest.java
@@ -15,15 +15,70 @@
  */
 package org.onosproject.net.intent;
 
-import org.junit.Test;
+import java.util.Optional;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MplsLabel;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.core.IsEqual.equalTo;
 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.connectPoint;
 
 /**
  * Unit tests for the MplsIntent class.
  */
 
-public class MplsIntentTest {
+public class MplsIntentTest extends AbstractIntentTest {
+    static final int PRIORITY = 22;
+
+    MplsIntent intent1;
+    MplsIntent intent2;
+
+    Optional<MplsLabel> label1;
+    Optional<MplsLabel> label2;
+
+    TrafficSelector selector;
+    TrafficTreatment treatment;
+
+    @Before
+    public void mplsIntentTestSetUp() throws Exception {
+
+        label1 = Optional.of(MplsLabel.mplsLabel(1));
+        label2 = Optional.of(MplsLabel.mplsLabel(2));
+
+        selector = new IntentTestsMocks.MockSelector();
+        treatment = new IntentTestsMocks.MockTreatment();
+
+        intent1 = MplsIntent.builder()
+                .appId(APP_ID)
+                .ingressLabel(label1)
+                .egressLabel(label2)
+                .ingressPoint(connectPoint("in", 1))
+                .egressPoint(connectPoint("out", 1))
+                .selector(selector)
+                .treatment(treatment)
+                .priority(PRIORITY)
+                .build();
+
+        intent2 = MplsIntent.builder()
+                .appId(APP_ID)
+                .ingressLabel(label1)
+                .egressLabel(label2)
+                .ingressPoint(connectPoint("in", 2))
+                .egressPoint(connectPoint("out", 2))
+                .selector(selector)
+                .treatment(treatment)
+                .priority(PRIORITY)
+                .build();
+    }
 
     /**
      * Checks that the MplsIntent class is immutable.
@@ -33,4 +88,30 @@
         assertThatClassIsImmutable(MplsIntent.class);
     }
 
+    /**
+     * Checks the operation of equals(), hashCode() and toString() methods.
+     */
+    @Test
+    public void testEquals() {
+        new EqualsTester()
+                .addEqualityGroup(intent1)
+                .addEqualityGroup(intent2)
+                .testEquals();
+    }
+
+    /**
+     * Checks that the MplsIntent objects are created correctly.
+     */
+    @Test
+    public void testContents() {
+        assertThat(intent1.appId(), equalTo(APP_ID));
+        assertThat(intent1.ingressLabel(), equalTo(label1));
+        assertThat(intent1.egressLabel(), equalTo(label2));
+        assertThat(intent1.ingressPoint(), equalTo(connectPoint("in", 1)));
+        assertThat(intent1.egressPoint(), equalTo(connectPoint("out", 1)));
+        assertThat(intent1.selector(), equalTo(intent2.selector()));
+        assertThat(intent1.treatment(), equalTo(intent2.treatment()));
+        assertThat(intent1.priority(), is(PRIORITY));
+
+    }
 }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java
index 020e4bd..551f19e 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/MplsPathIntentTest.java
@@ -15,14 +15,64 @@
  */
 package org.onosproject.net.intent;
 
-import org.junit.Test;
+import java.util.Optional;
 
+import org.junit.Before;
+import org.junit.Test;
+import org.onlab.packet.MplsLabel;
+import org.onosproject.net.Path;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
+
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.core.IsEqual.equalTo;
 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.createPath;
 
 /**
  * Unit tests for the MplsPathIntent class.
  */
-public class MplsPathIntentTest {
+public class MplsPathIntentTest extends AbstractIntentTest {
+
+    static final int PRIORITY = 777;
+
+    MplsPathIntent intent1;
+    MplsPathIntent intent2;
+    Path defaultPath;
+    Optional<MplsLabel> label1;
+    Optional<MplsLabel> label2;
+    TrafficSelector selector;
+    TrafficTreatment treatment;
+
+    @Before
+    public void mplsPathIntentTestSetUp() {
+        defaultPath = createPath("a", "b", "c");
+        selector = new IntentTestsMocks.MockSelector();
+        treatment = new IntentTestsMocks.MockTreatment();
+
+        label1 = Optional.of(MplsLabel.mplsLabel(1));
+        label2 = Optional.of(MplsLabel.mplsLabel(2));
+        intent1 = MplsPathIntent.builder()
+                .appId(APP_ID)
+                .ingressLabel(label1)
+                .egressLabel(label2)
+                .path(defaultPath)
+                .priority(PRIORITY)
+                .build();
+
+        intent2 = MplsPathIntent.builder()
+                .appId(APP_ID)
+                .ingressLabel(label1)
+                .egressLabel(label2)
+                .path(defaultPath)
+                .priority(PRIORITY)
+                .build();
+    }
+
 
     /**
      * Checks that the MplsPathIntent class is immutable.
@@ -32,4 +82,29 @@
         assertThatClassIsImmutable(MplsPathIntent.class);
     }
 
+    /**
+     * Checks the operation of equals(), hashCode() and toString() methods.
+     */
+    @Test
+    public void testEquals() {
+        new EqualsTester()
+                .addEqualityGroup(intent1)
+                .addEqualityGroup(intent2)
+                .testEquals();
+    }
+
+    /**
+     * Checks that the MPLS path intent objects are created correctly.
+     */
+    @Test
+    public void testContents() {
+        assertThat(intent1.appId(), equalTo(APP_ID));
+        assertThat(intent1.ingressLabel(), equalTo(label1));
+        assertThat(intent1.egressLabel(), equalTo(label2));
+        assertThat(intent1.selector(), equalTo(intent2.selector()));
+        assertThat(intent1.treatment(), equalTo(intent2.treatment()));
+        assertThat(intent1.priority(), is(PRIORITY));
+        assertThat(intent1.path(), is(defaultPath));
+    }
+
 }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/OpticalPathIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/OpticalPathIntentTest.java
index a9e3b56..f05e93c 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/OpticalPathIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/OpticalPathIntentTest.java
@@ -15,11 +15,48 @@
  */
 package org.onosproject.net.intent;
 
+import org.hamcrest.Matchers;
+import org.junit.Before;
 import org.junit.Test;
+import org.onosproject.net.Path;
 
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.core.IsEqual.equalTo;
 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.connectPoint;
+import static org.onosproject.net.NetTestTools.createPath;
 
-public class OpticalPathIntentTest {
+public class OpticalPathIntentTest extends AbstractIntentTest {
+
+    static final int PRIORITY = 777;
+
+    OpticalPathIntent intent1;
+    OpticalPathIntent intent2;
+    Path defaultPath;
+
+    @Before
+    public void opticalPathIntentTestSetUp() {
+        defaultPath = createPath("a", "b", "c");
+        intent1 = OpticalPathIntent.builder()
+                .appId(APP_ID)
+                .src(connectPoint("one", 1))
+                .dst(connectPoint("two", 2))
+                .path(defaultPath)
+                .priority(PRIORITY)
+                .build();
+
+        intent2 = OpticalPathIntent.builder()
+                .appId(APP_ID)
+                .src(connectPoint("two", 1))
+                .dst(connectPoint("one", 2))
+                .path(defaultPath)
+                .priority(PRIORITY)
+                .build();
+    }
 
     /**
      * Checks that the OpticalPathIntent class is immutable.
@@ -29,4 +66,26 @@
         assertThatClassIsImmutable(OpticalPathIntent.class);
     }
 
+    /**
+     * Checks the operation of equals(), hashCode() and toString() methods.
+     */
+    @Test
+    public void testEquals() {
+        new EqualsTester()
+                .addEqualityGroup(intent1)
+                .addEqualityGroup(intent2)
+                .testEquals();
+    }
+
+    /**
+     * Checks that the optical path ntent objects are created correctly.
+     */
+    @Test
+    public void testContents() {
+        assertThat(intent1.appId(), equalTo(APP_ID));
+        assertThat(intent1.src(), Matchers.equalTo(connectPoint("one", 1)));
+        assertThat(intent1.dst(), Matchers.equalTo(connectPoint("two", 2)));
+        assertThat(intent1.priority(), is(PRIORITY));
+        assertThat(intent1.path(), is(defaultPath));
+    }
 }
diff --git a/core/api/src/test/java/org/onosproject/net/intent/TwoWayP2PIntentTest.java b/core/api/src/test/java/org/onosproject/net/intent/TwoWayP2PIntentTest.java
index 08a9656..0986216 100644
--- a/core/api/src/test/java/org/onosproject/net/intent/TwoWayP2PIntentTest.java
+++ b/core/api/src/test/java/org/onosproject/net/intent/TwoWayP2PIntentTest.java
@@ -15,14 +15,56 @@
  */
 package org.onosproject.net.intent;
 
+import org.hamcrest.Matchers;
+import org.junit.Before;
 import org.junit.Test;
+import org.onosproject.net.flow.TrafficSelector;
+import org.onosproject.net.flow.TrafficTreatment;
 
+import com.google.common.testing.EqualsTester;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.is;
+import static org.hamcrest.core.IsEqual.equalTo;
 import static org.onlab.junit.ImmutableClassChecker.assertThatClassIsImmutable;
-
+import static org.onosproject.net.NetTestTools.APP_ID;
+import static org.onosproject.net.NetTestTools.connectPoint;
 /**
  * Unit tests for the TwoWayP2PIntent class.
  */
-public class TwoWayP2PIntentTest {
+public class TwoWayP2PIntentTest extends AbstractIntentTest {
+
+    TrafficSelector selector;
+    TrafficTreatment treatment;
+
+    TwoWayP2PIntent intent1;
+    TwoWayP2PIntent intent2;
+
+    static final int PRIORITY = 12;
+
+    @Before
+    public void twoWatP2PIntentTestSetUp() {
+        selector = new IntentTestsMocks.MockSelector();
+        treatment = new IntentTestsMocks.MockTreatment();
+
+        intent1 = TwoWayP2PIntent.builder()
+                .appId(APP_ID)
+                .priority(PRIORITY)
+                .selector(selector)
+                .treatment(treatment)
+                .one(connectPoint("one", 1))
+                .two(connectPoint("two", 2))
+                .build();
+
+        intent2 = TwoWayP2PIntent.builder()
+                .appId(APP_ID)
+                .priority(PRIORITY)
+                .selector(selector)
+                .treatment(treatment)
+                .one(connectPoint("two", 2))
+                .two(connectPoint("three", 2))
+                .build();
+    }
 
     /**
      * Checks that the TwoWayP2PIntent class is immutable.
@@ -32,4 +74,27 @@
         assertThatClassIsImmutable(TwoWayP2PIntent.class);
     }
 
+    /**
+     * Checks the operation of equals(), hashCode() and toString() methods.
+     */
+    @Test
+    public void testEquals() {
+        new EqualsTester()
+                .addEqualityGroup(intent1)
+                .addEqualityGroup(intent2)
+                .testEquals();
+    }
+
+    /**
+     * Checks that the optical path ntent objects are created correctly.
+     */
+    @Test
+    public void testContents() {
+        assertThat(intent1.appId(), equalTo(APP_ID));
+        assertThat(intent1.one(), Matchers.equalTo(connectPoint("one", 1)));
+        assertThat(intent1.two(), Matchers.equalTo(connectPoint("two", 2)));
+        assertThat(intent1.priority(), is(PRIORITY));
+        assertThat(intent1.selector(), is(selector));
+        assertThat(intent1.treatment(), is(treatment));
+    }
 }