Add unit tests for LISP address serializer and deserializer

Change-Id: I56538221f3951d18c1feb9343d87cbb46c3ed04d
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispAppDataLcafAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispAppDataLcafAddressTest.java
index ea528a0..f9a00ee 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispAppDataLcafAddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispAppDataLcafAddressTest.java
@@ -16,12 +16,20 @@
 package org.onosproject.lisp.msg.types;
 
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispReaderException;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
+import org.onosproject.lisp.msg.types.LispAppDataLcafAddress.AppDataLcafAddressWriter;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.types.LispAppDataLcafAddress.AppDataAddressBuilder;
+import static org.onosproject.lisp.msg.types.LispAppDataLcafAddress.AppDataLcafAddressReader;
 
 /**
  * Unit tests for LispAppDataLcafAddress class.
@@ -35,8 +43,8 @@
     @Before
     public void setup() {
 
-        LispAppDataLcafAddress.AppDataAddressBuilder builder1 =
-                new LispAppDataLcafAddress.AppDataAddressBuilder();
+        AppDataAddressBuilder builder1 =
+                new AppDataAddressBuilder();
 
         LispAfiAddress ipv4Address1 = new LispIpv4Address(IpAddress.valueOf("192.168.1.1"));
 
@@ -50,8 +58,8 @@
                     .withAddress(ipv4Address1)
                     .build();
 
-        LispAppDataLcafAddress.AppDataAddressBuilder builder2 =
-                new LispAppDataLcafAddress.AppDataAddressBuilder();
+        AppDataAddressBuilder builder2 =
+                new AppDataAddressBuilder();
 
         sameAsAddress1 = builder2
                             .withProtocol((byte) 0x01)
@@ -63,8 +71,8 @@
                             .withAddress(ipv4Address1)
                             .build();
 
-        LispAppDataLcafAddress.AppDataAddressBuilder builder3 =
-                new LispAppDataLcafAddress.AppDataAddressBuilder();
+        AppDataAddressBuilder builder3 =
+                new AppDataAddressBuilder();
 
         LispAfiAddress ipv4Address2 = new LispIpv4Address(IpAddress.valueOf("192.168.2.1"));
 
@@ -100,4 +108,18 @@
         assertThat(appDataLcafAddress.getRemotePortHigh(), is((short) 254));
         assertThat(appDataLcafAddress.getAddress(), is(ipv4Address));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        AppDataLcafAddressWriter writer = new AppDataLcafAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        AppDataLcafAddressReader reader = new AppDataLcafAddressReader();
+        LispAppDataLcafAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispDistinguishedNameAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispDistinguishedNameAddressTest.java
index 074b0ca..fc2a160 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispDistinguishedNameAddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispDistinguishedNameAddressTest.java
@@ -16,12 +16,18 @@
 package org.onosproject.lisp.msg.types;
 
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
 
+import static org.onosproject.lisp.msg.types.LispDistinguishedNameAddress.*;
+
 /**
  * Unit tests for LispDistinguishedNameAddress class.
  */
@@ -52,4 +58,18 @@
 
         assertThat(distinguishedNameAddress.getDistinguishedName(), is("distAddress1"));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        DistinguishedNameAddressWriter writer = new DistinguishedNameAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        DistinguishedNameAddressReader reader = new DistinguishedNameAddressReader();
+        LispDistinguishedNameAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv4AddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv4AddressTest.java
index 099a7c1..f247a32 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv4AddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv4AddressTest.java
@@ -16,12 +16,18 @@
 package org.onosproject.lisp.msg.types;
 
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.types.LispIpv4Address.Ipv4AddressReader;
+import static org.onosproject.lisp.msg.types.LispIpv4Address.Ipv4AddressWriter;
 
 /**
  * Unit tests for LispIpv4Address class.
@@ -52,4 +58,18 @@
         LispIpv4Address ipv4Address = address1;
         assertThat(ipv4Address.getAddress(), is(IpAddress.valueOf("192.168.1.1")));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        Ipv4AddressWriter writer = new Ipv4AddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        Ipv4AddressReader reader = new Ipv4AddressReader();
+        LispIpv4Address deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                    .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv6AddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv6AddressTest.java
index d78b247..37ed606 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv6AddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispIpv6AddressTest.java
@@ -16,12 +16,19 @@
 package org.onosproject.lisp.msg.types;
 
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.types.LispIpv6Address.Ipv6AddressReader;
+import static org.onosproject.lisp.msg.types.LispIpv6Address.Ipv6AddressWriter;
+
 
 /**
  * Unit tests for LispIpv6Address class.
@@ -52,4 +59,18 @@
         LispIpv6Address ipv6Address = address1;
         assertThat(ipv6Address.getAddress(), is(IpAddress.valueOf("1111:2222:3333:4444:5555:6666:7777:8885")));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        Ipv6AddressWriter writer = new Ipv6AddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        Ipv6AddressReader reader = new Ipv6AddressReader();
+        LispIpv6Address deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispListLcafAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispListLcafAddressTest.java
index 070ae73..771a2a7 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispListLcafAddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispListLcafAddressTest.java
@@ -17,14 +17,21 @@
 
 import com.google.common.collect.Lists;
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispReaderException;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
 
 import java.util.List;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressReader;
+import static org.onosproject.lisp.msg.types.LispListLcafAddress.ListLcafAddressWriter;
 
 /**
  * Unit tests for LispListLcafAddress class.
@@ -79,4 +86,18 @@
 
         assertThat(listLcafAddress.getAddresses(), is(afiAddresses1));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        ListLcafAddressWriter writer = new ListLcafAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        ListLcafAddressReader reader = new ListLcafAddressReader();
+        LispListLcafAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispMacAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispMacAddressTest.java
index f77a306..f28c7f6 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispMacAddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispMacAddressTest.java
@@ -16,12 +16,18 @@
 package org.onosproject.lisp.msg.types;
 
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.MacAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.types.LispMacAddress.MacAddressReader;
+import static org.onosproject.lisp.msg.types.LispMacAddress.MacAddressWriter;
 
 /**
  * Unit tests for LispMacAddress class.
@@ -52,4 +58,18 @@
         LispMacAddress macAddress = address1;
         assertThat(macAddress.getAddress(), is(MacAddress.valueOf("00:00:00:00:00:01")));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        MacAddressWriter writer = new MacAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        MacAddressReader reader = new MacAddressReader();
+        LispMacAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSegmentLcafAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSegmentLcafAddressTest.java
index b1f811c..eda8f0a 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSegmentLcafAddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSegmentLcafAddressTest.java
@@ -16,12 +16,19 @@
 package org.onosproject.lisp.msg.types;
 
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispReaderException;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.types.LispSegmentLcafAddress.SegmentLcafAddressReader;
+import static org.onosproject.lisp.msg.types.LispSegmentLcafAddress.SegmentLcafAddressWriter;
 
 /**
  * Unit tests for LispSegmentLcafAddress class.
@@ -83,4 +90,18 @@
         assertThat(segmentLcafAddress.getInstanceId(), is(1));
         assertThat(segmentLcafAddress.getAddress(), is(ipv4Address));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        SegmentLcafAddressWriter writer = new SegmentLcafAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        SegmentLcafAddressReader reader = new SegmentLcafAddressReader();
+        LispSegmentLcafAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }
diff --git a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddressTest.java b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddressTest.java
index e212a1c..c3d74e4 100644
--- a/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddressTest.java
+++ b/protocols/lisp/msg/src/test/java/org/onosproject/lisp/msg/types/LispSourceDestLcafAddressTest.java
@@ -16,12 +16,19 @@
 package org.onosproject.lisp.msg.types;
 
 import com.google.common.testing.EqualsTester;
+import io.netty.buffer.ByteBuf;
+import io.netty.buffer.Unpooled;
 import org.junit.Before;
 import org.junit.Test;
 import org.onlab.packet.IpAddress;
+import org.onosproject.lisp.msg.exceptions.LispParseError;
+import org.onosproject.lisp.msg.exceptions.LispReaderException;
+import org.onosproject.lisp.msg.exceptions.LispWriterException;
 
 import static org.hamcrest.MatcherAssert.assertThat;
 import static org.hamcrest.Matchers.is;
+import static org.onosproject.lisp.msg.types.LispSourceDestLcafAddress.SourceDestLcafAddressReader;
+import static org.onosproject.lisp.msg.types.LispSourceDestLcafAddress.SourceDestLcafAddressWriter;
 
 /**
  * Unit tests for LispSourceDestLcafAddress class.
@@ -95,4 +102,18 @@
         assertThat(sourceDestLcafAddress.getSrcPrefix(), is(srcAddress));
         assertThat(sourceDestLcafAddress.getDstPrefix(), is(dstAddress));
     }
+
+    @Test
+    public void testSerialization() throws LispWriterException, LispParseError, LispReaderException {
+        ByteBuf byteBuf = Unpooled.buffer();
+
+        SourceDestLcafAddressWriter writer = new SourceDestLcafAddressWriter();
+        writer.writeTo(byteBuf, address1);
+
+        SourceDestLcafAddressReader reader = new SourceDestLcafAddressReader();
+        LispSourceDestLcafAddress deserialized = reader.readFrom(byteBuf);
+
+        new EqualsTester()
+                .addEqualityGroup(address1, deserialized).testEquals();
+    }
 }