BUG-868: remove deprecated YangInstanceIdentifier methods
[yangtools.git] / yang / yang-data-api / src / test / java / org / opendaylight / yangtools / yang / data / api / InstanceIdentifierTest.java
index 3cc626389c705b1186d8ffab111133d4fe849b32..cc34224da23a7cf8b6e40856e37c89c6651dd0c9 100644 (file)
@@ -10,17 +10,19 @@ package org.opendaylight.yangtools.yang.data.api;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
-
 import com.google.common.base.Optional;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Sets;
-
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
 import java.util.Collections;
 import java.util.Iterator;
 import java.util.Map.Entry;
-
 import org.junit.Test;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
@@ -166,7 +168,7 @@ public class InstanceIdentifierTest {
         assertEquals( "PathArg 3 node type", nodeName3, it.next().getNodeType() );
         assertEquals( "PathArg 4 node type", nodeName4, it.next().getNodeType() );
 
-        newID = YangInstanceIdentifier.builder( nodeName1 ).build();
+        newID = YangInstanceIdentifier.builder().node( nodeName1 ).build();
 
         assertNotNull( "InstanceIdentifier is null", newID );
         assertEquals( "Path size", 1, Iterables.size(newID.getPathArguments()) );
@@ -301,4 +303,24 @@ public class InstanceIdentifierTest {
 
         assertNotNull( node1.toString() ); // for code coverage
     }
+
+    @Test
+    public void serializationTest() throws IOException, ClassNotFoundException {
+        final YangInstanceIdentifier expected = YangInstanceIdentifier.create(new NodeIdentifier(nodeName1), new NodeIdentifier(nodeName2));
+
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        final ObjectOutputStream oos = new ObjectOutputStream(bos);
+        oos.writeObject(expected);
+        oos.close();
+
+        final byte[] bytes = bos.toByteArray();
+        final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
+        final ObjectInputStream ois = new ObjectInputStream(bis);
+
+        final YangInstanceIdentifier read = (YangInstanceIdentifier) ois.readObject();
+        assertEquals(0, ois.available());
+        ois.close();
+
+        assertEquals(expected, read);
+    }
 }