Fix ReadyLocalTransactionSerializer
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / ReadyLocalTransactionSerializerTest.java
index 3ff8163f7d0df512401b0347dd8d6c4d818e15a6..5a585bcd372733d9a807e61ffd965e257128517f 100644 (file)
@@ -10,6 +10,9 @@ package org.opendaylight.controller.cluster.datastore.messages;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertNotNull;
 
+import akka.actor.ExtendedActorSystem;
+import akka.testkit.JavaTestKit;
+import java.io.NotSerializableException;
 import java.util.List;
 import org.junit.Test;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
@@ -21,9 +24,9 @@ import org.opendaylight.controller.cluster.datastore.modification.WriteModificat
 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
 import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
 import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
-import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
 
@@ -35,9 +38,9 @@ import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFac
 public class ReadyLocalTransactionSerializerTest extends AbstractTest {
 
     @Test
-    public void testToAndFromBinary() {
-        TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
-        dataTree.setSchemaContext(TestModel.createTestContext());
+    public void testToAndFromBinary() throws NotSerializableException {
+        DataTree dataTree = new InMemoryDataTreeFactory().create(
+            DataTreeConfiguration.DEFAULT_OPERATIONAL, TestModel.createTestContext());
         DataTreeModification modification = dataTree.takeSnapshot().newModification();
 
         ContainerNode writeData = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
@@ -48,16 +51,20 @@ public class ReadyLocalTransactionSerializerTest extends AbstractTest {
         TransactionIdentifier txId = nextTransactionId();
         ReadyLocalTransaction readyMessage = new ReadyLocalTransaction(txId, modification, true);
 
-        ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer();
-
-        byte[] bytes = serializer.toBinary(readyMessage);
-
-        Object deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
+        final ExtendedActorSystem system = (ExtendedActorSystem) ExtendedActorSystem.create("test");
+        final Object deserialized;
+        try {
+            final ReadyLocalTransactionSerializer serializer = new ReadyLocalTransactionSerializer(system);
+            final byte[] bytes = serializer.toBinary(readyMessage);
+            deserialized = serializer.fromBinary(bytes, ReadyLocalTransaction.class);
+        } finally {
+            JavaTestKit.shutdownActorSystem(system);
+        }
 
         assertNotNull("fromBinary returned null", deserialized);
         assertEquals("fromBinary return type", BatchedModifications.class, deserialized.getClass());
         BatchedModifications batched = (BatchedModifications)deserialized;
-        assertEquals("getTransactionID", txId, batched.getTransactionID());
+        assertEquals("getTransactionID", txId, batched.getTransactionId());
         assertEquals("getVersion", DataStoreVersions.CURRENT_VERSION, batched.getVersion());
 
         List<Modification> batchedMods = batched.getModifications();