Unit test for RequestSuccess.java and derived classes 35/53135/8
authormiroslav.kovac <miroslav.kovac@pantheon.tech>
Fri, 10 Mar 2017 11:57:15 +0000 (12:57 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Fri, 17 Mar 2017 18:21:32 +0000 (18:21 +0000)
Change-Id: Ic8998c07ae714f862e18bddccda790fc8c90ee9e
Signed-off-by: miroslav.kovac <miroslav.kovac@pantheon.tech>
13 files changed:
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractRequestSuccessTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientSuccessTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessNoDataTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessTest.java
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseTest.java

diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractRequestSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractRequestSuccessTest.java
new file mode 100644 (file)
index 0000000..f0bb6f3
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.access.commands;
+
+import org.apache.commons.lang.SerializationUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.FrontendType;
+import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.MemberName;
+import org.opendaylight.controller.cluster.access.concepts.RequestSuccess;
+
+public abstract class AbstractRequestSuccessTest<T extends RequestSuccess> {
+
+    private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
+            MemberName.forName("test"), FrontendType.forName("one"));
+    protected static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
+    protected static final LocalHistoryIdentifier HISTORY_IDENTIFIER = new LocalHistoryIdentifier(
+            CLIENT_IDENTIFIER, 0);
+
+    protected abstract T object();
+
+    @SuppressWarnings("unchecked")
+    @Test
+    public void serializationTest() {
+        final Object deserialize = SerializationUtils.clone(object());
+
+        Assert.assertEquals(object().getTarget(), ((T) deserialize).getTarget());
+        Assert.assertEquals(object().getVersion(), ((T) deserialize).getVersion());
+        Assert.assertEquals(object().getSequence(), ((T) deserialize).getSequence());
+        doAdditionalAssertions((T) deserialize);
+    }
+
+    protected abstract void doAdditionalAssertions(final Object deserialize);
+}
index d67ebd8..de9d9ff 100644 (file)
@@ -7,35 +7,12 @@
  */
 package org.opendaylight.controller.cluster.access.commands;
 
-import org.apache.commons.lang.SerializationUtils;
-import org.junit.Assert;
-import org.junit.Test;
-import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
-import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
-import org.opendaylight.controller.cluster.access.concepts.FrontendType;
-import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
-import org.opendaylight.controller.cluster.access.concepts.MemberName;
 import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
 
-public abstract class AbstractTransactionSuccessTest<T extends TransactionSuccess> {
-    private static final FrontendIdentifier FRONTEND_IDENTIFIER = FrontendIdentifier.create(
-            MemberName.forName("test"), FrontendType.forName("one"));
-    private static final ClientIdentifier CLIENT_IDENTIFIER = ClientIdentifier.create(FRONTEND_IDENTIFIER, 0);
-    private static final LocalHistoryIdentifier HISTORY_IDENTIFIER = new LocalHistoryIdentifier(
-            CLIENT_IDENTIFIER, 0);
+public abstract class AbstractTransactionSuccessTest<T extends TransactionSuccess>
+        extends AbstractRequestSuccessTest {
 
     protected static final TransactionIdentifier TRANSACTION_IDENTIFIER = new TransactionIdentifier(
             HISTORY_IDENTIFIER, 0);
 
-    protected abstract T object();
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void serializationTest() {
-        final Object deserialize = SerializationUtils.clone(object());
-
-        Assert.assertEquals(object().getTarget(), ((T) deserialize).getTarget());
-        Assert.assertEquals(object().getVersion(), ((T) deserialize).getVersion());
-        Assert.assertEquals(object().getSequence(), ((T) deserialize).getSequence());
-    }
 }
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientSuccessTest.java
new file mode 100644 (file)
index 0000000..ea346e8
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.access.commands;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSelection;
+import akka.actor.ActorSystem;
+import akka.actor.ExtendedActorSystem;
+import akka.serialization.JavaSerializer;
+import akka.testkit.TestProbe;
+import com.google.common.base.MoreObjects;
+import com.google.common.collect.ImmutableList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Optional;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.controller.cluster.access.ABIVersion;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
+import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
+
+public class ConnectClientSuccessTest extends AbstractRequestSuccessTest<ConnectClientSuccess> {
+
+    private static final DataTree TREE = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
+    private static final ActorSystem SYSTEM = ActorSystem.create("test");
+    private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
+    private static final ActorSelection ACTOR_SELECTION =  ActorSelection.apply(ACTOR_REF, "foo");
+    private static final List<ActorSelection> ALTERNATES = ImmutableList.of(ACTOR_SELECTION);
+    private static final int MAX_MESSAGES = 10;
+    private static final ConnectClientSuccess OBJECT = new ConnectClientSuccess(
+            CLIENT_IDENTIFIER, 0, ACTOR_REF, ALTERNATES, TREE, MAX_MESSAGES);
+
+    @Override
+    protected ConnectClientSuccess object() {
+        return OBJECT;
+    }
+
+    @Before
+    public void setUp() {
+        JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
+    }
+
+    @Test
+    public void testGetAlternates() {
+        final Collection<ActorSelection> alternates = OBJECT.getAlternates();
+        Assert.assertArrayEquals(ALTERNATES.toArray(), alternates.toArray());
+    }
+
+    @Test
+    public void testGetBackend() {
+        final ActorRef actorRef = OBJECT.getBackend();
+        Assert.assertEquals(ACTOR_REF, actorRef);
+    }
+
+    @Test
+    public void testGetDataTree() {
+        final DataTree tree = OBJECT.getDataTree().get();
+        Assert.assertEquals(TREE, tree);
+    }
+
+    @Test
+    public void testGetMaxMessages() {
+        final int maxMessages = OBJECT.getMaxMessages();
+        Assert.assertEquals(MAX_MESSAGES, maxMessages);
+    }
+
+    @Test
+    public void cloneAsVersionTest() throws Exception {
+        final ConnectClientSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
+        Assert.assertEquals(OBJECT, clone);
+    }
+
+    @Test
+    public void addToStringAttributes() throws Exception {
+        final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
+        Assert.assertTrue(result.toString().contains("alternates=" + ALTERNATES));
+        Assert.assertTrue(result.toString().contains("dataTree=" + TREE));
+        Assert.assertTrue(result.toString().contains("maxMessages=" + MAX_MESSAGES));
+    }
+
+    @Override
+    protected void doAdditionalAssertions(final Object deserialize) {
+        Assert.assertTrue(deserialize instanceof ConnectClientSuccess);
+        Assert.assertEquals(OBJECT.getAlternates().size(), ((ConnectClientSuccess) deserialize).getAlternates().size());
+        Assert.assertEquals(OBJECT.getBackend(), ((ConnectClientSuccess) deserialize).getBackend());
+        Assert.assertEquals(Optional.empty(), ((ConnectClientSuccess) deserialize).getDataTree());
+        Assert.assertEquals(OBJECT.getMaxMessages(), ((ConnectClientSuccess) deserialize).getMaxMessages());
+    }
+}
index fe823ef..aa68eaa 100644 (file)
@@ -40,4 +40,10 @@ public class ExistsTransactionSuccessTest extends AbstractTransactionSuccessTest
         final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
         Assert.assertTrue(result.toString().contains("exists=" + EXISTS));
     }
+
+    @Override
+    protected void doAdditionalAssertions(final Object deserialize) {
+        Assert.assertTrue(deserialize instanceof ExistsTransactionSuccess);
+        Assert.assertEquals(OBJECT.getExists(), ((ExistsTransactionSuccess) deserialize).getExists());
+    }
 }
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/LocalHistorySuccessTest.java
new file mode 100644 (file)
index 0000000..219f914
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.controller.cluster.access.commands;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.cluster.access.ABIVersion;
+
+public class LocalHistorySuccessTest extends AbstractRequestSuccessTest<LocalHistorySuccess> {
+
+    private static final LocalHistorySuccess OBJECT = new LocalHistorySuccess(
+            HISTORY_IDENTIFIER, 0);
+
+    @Override
+    protected LocalHistorySuccess object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void cloneAsVersionTest() throws Exception {
+        final LocalHistorySuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
+        Assert.assertEquals(OBJECT.getSequence(), clone.getSequence());
+        Assert.assertEquals(OBJECT.getTarget(), clone.getTarget());
+        Assert.assertEquals(OBJECT.getVersion(), clone.getVersion());
+    }
+
+    @Override
+    protected void doAdditionalAssertions(final Object deserialize) {
+        Assert.assertTrue(deserialize instanceof LocalHistorySuccess);
+    }
+}
index 1f7e3d4..c31caf2 100644 (file)
@@ -27,4 +27,9 @@ public class ModifyTransactionSuccessTest extends AbstractTransactionSuccessTest
         Assert.assertEquals(OBJECT.getSequence(), clone.getSequence());
         Assert.assertEquals(OBJECT.getTarget(), clone.getTarget());
     }
+
+    @Override
+    protected void doAdditionalAssertions(final Object deserialize) {
+        Assert.assertTrue(deserialize instanceof ModifyTransactionSuccess);
+    }
 }
\ No newline at end of file
index 9e7c796..5259fe4 100644 (file)
@@ -33,4 +33,10 @@ public class ReadTransactionSuccessNoDataTest extends AbstractTransactionSuccess
         final ReadTransactionSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
         Assert.assertEquals(OBJECT, clone);
     }
+
+    @Override
+    protected void doAdditionalAssertions(Object deserialize) {
+        Assert.assertTrue(deserialize instanceof ReadTransactionSuccess);
+        Assert.assertEquals(OBJECT.getData(), ((ReadTransactionSuccess) deserialize).getData());
+    }
 }
\ No newline at end of file
index 0f4871f..a76e6d3 100644 (file)
@@ -40,4 +40,10 @@ public class ReadTransactionSuccessTest extends AbstractTransactionSuccessTest<R
         final ReadTransactionSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
         Assert.assertEquals(OBJECT, clone);
     }
+
+    @Override
+    protected void doAdditionalAssertions(Object deserialize) {
+        Assert.assertTrue(deserialize instanceof ReadTransactionSuccess);
+        Assert.assertEquals(OBJECT.getData(), ((ReadTransactionSuccess) deserialize).getData());
+    }
 }
\ No newline at end of file
index f7bd108..10904d1 100644 (file)
@@ -25,4 +25,9 @@ public class TransactionAbortSuccessTest extends AbstractTransactionSuccessTest<
         final TransactionAbortSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
         Assert.assertEquals(OBJECT, clone);
     }
+
+    @Override
+    protected void doAdditionalAssertions(Object deserialize) {
+        Assert.assertTrue(deserialize instanceof TransactionAbortSuccess);
+    }
 }
\ No newline at end of file
index 80001e0..7bfea57 100644 (file)
@@ -25,4 +25,9 @@ public class TransactionCanCommitSuccessTest extends AbstractTransactionSuccessT
         final TransactionCanCommitSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
         Assert.assertEquals(OBJECT, clone);
     }
+
+    @Override
+    protected void doAdditionalAssertions(Object deserialize) {
+        Assert.assertTrue(deserialize instanceof TransactionCanCommitSuccess);
+    }
 }
\ No newline at end of file
index 6d5049c..fe4afff 100644 (file)
@@ -25,4 +25,9 @@ public class TransactionCommitSuccessTest extends AbstractTransactionSuccessTest
         final TransactionCommitSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
         Assert.assertEquals(OBJECT, clone);
     }
+
+    @Override
+    protected void doAdditionalAssertions(Object deserialize) {
+        Assert.assertTrue(deserialize instanceof TransactionCommitSuccess);
+    }
 }
\ No newline at end of file
index fbb0faf..18d530a 100644 (file)
@@ -25,4 +25,9 @@ public class TransactionPreCommitSuccessTest extends AbstractTransactionSuccessT
         final TransactionPreCommitSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
         Assert.assertEquals(OBJECT, clone);
     }
+
+    @Override
+    protected void doAdditionalAssertions(Object deserialize) {
+        Assert.assertTrue(deserialize instanceof TransactionPreCommitSuccess);
+    }
 }
\ No newline at end of file
index 4a60a0f..2e71360 100644 (file)
@@ -25,4 +25,9 @@ public class TransactionPurgeResponseTest extends AbstractTransactionSuccessTest
         final TransactionPurgeResponse clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
         Assert.assertEquals(OBJECT, clone);
     }
+
+    @Override
+    protected void doAdditionalAssertions(Object deserialize) {
+        Assert.assertTrue(deserialize instanceof TransactionPurgeResponse);
+    }
 }
\ No newline at end of file