Unit tests for AbstractLocalTransactionRequest derived classes 98/52498/8
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Wed, 1 Mar 2017 12:59:55 +0000 (13:59 +0100)
committerIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 3 Mar 2017 14:38:30 +0000 (14:38 +0000)
Change-Id: I34978326821bf6b8cc7604ee284f2fda20585618
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
opendaylight/md-sal/cds-access-api/pom.xml
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbortLocalTransactionRequestTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionRequestTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequestTest.java [new file with mode: 0644]

index 8783ce66aa2efbca854c8c6df2566bed128f2338..c7ee86edc398c861825226bd5ffd51045342b35d 100644 (file)
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-clustering-commons</artifactId>
         </dependency>
             <groupId>org.opendaylight.controller</groupId>
             <artifactId>sal-clustering-commons</artifactId>
         </dependency>
+
+        <!-- Testing dependencies -->
+        <dependency>
+            <groupId>org.opendaylight.yangtools</groupId>
+            <artifactId>mockito-configuration</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>com.typesafe.akka</groupId>
+            <artifactId>akka-testkit_${scala.version}</artifactId>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <build>
     </dependencies>
 
     <build>
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbortLocalTransactionRequestTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbortLocalTransactionRequestTest.java
new file mode 100644 (file)
index 0000000..ec960c6
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * 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.ActorSystem;
+import akka.testkit.TestProbe;
+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 class AbortLocalTransactionRequestTest extends AbstractTransactionRequestTest<AbortLocalTransactionRequest> {
+
+    private static final FrontendIdentifier FRONTEND = FrontendIdentifier.create(
+            MemberName.forName("test"), FrontendType.forName("one"));
+    private static final ClientIdentifier CLIENT = ClientIdentifier.create(FRONTEND, 0);
+    private static final LocalHistoryIdentifier HISTORY = new LocalHistoryIdentifier(CLIENT, 0);
+    private static final TransactionIdentifier TRANSACTION = new TransactionIdentifier(HISTORY, 0);
+
+    private static final ActorSystem SYSTEM = ActorSystem.create("test");
+    private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
+
+    private static final AbortLocalTransactionRequest OBJECT = new AbortLocalTransactionRequest(TRANSACTION, ACTOR_REF);
+
+    @Override
+    AbortLocalTransactionRequest object() {
+        return OBJECT;
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionRequestTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionRequestTest.java
new file mode 100644 (file)
index 0000000..73ee6d6
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * 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 abstract class AbstractTransactionRequestTest<T extends AbstractLocalTransactionRequest> {
+    abstract T object();
+
+    @Test(expected = UnsupportedOperationException.class)
+    public void testExternalizableProxy() {
+        object().externalizableProxy(ABIVersion.BORON);
+    }
+
+    @Test
+    public void cloneAsVersionTest() {
+        Assert.assertEquals(object(), object().cloneAsVersion(ABIVersion.BORON));
+    }
+}
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequestTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/CommitLocalTransactionRequestTest.java
new file mode 100644 (file)
index 0000000..4675c59
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * 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.ActorSystem;
+import akka.testkit.TestProbe;
+import com.google.common.base.MoreObjects;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+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;
+import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
+
+public class CommitLocalTransactionRequestTest extends AbstractTransactionRequestTest<CommitLocalTransactionRequest> {
+
+    private static final FrontendIdentifier FRONTEND = FrontendIdentifier.create(
+            MemberName.forName("test"), FrontendType.forName("one"));
+    private static final ClientIdentifier CLIENT = ClientIdentifier.create(FRONTEND, 0);
+    private static final LocalHistoryIdentifier HISTORY = new LocalHistoryIdentifier(CLIENT, 0);
+    private static final TransactionIdentifier TRANSACTION = new TransactionIdentifier(HISTORY, 0);
+
+    private static final ActorSystem SYSTEM = ActorSystem.create("test");
+    private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
+
+    private static final DataTreeModification MODIFICATION = Mockito.mock(DataTreeModification.class);
+    private static final boolean COORDINATED = Boolean.TRUE;
+
+    private static final CommitLocalTransactionRequest OBJECT = new CommitLocalTransactionRequest(
+            TRANSACTION, 0, ACTOR_REF, MODIFICATION, COORDINATED);
+
+    @Override
+    CommitLocalTransactionRequest object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void getModificationTest() {
+        Assert.assertEquals(MODIFICATION, OBJECT.getModification());
+    }
+
+    @Test
+    public void isCoordinatedTest() {
+        Assert.assertEquals(COORDINATED, OBJECT.isCoordinated());
+    }
+
+    @Test
+    public void addToStringAttributesTest() {
+        final MoreObjects.ToStringHelper result = OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
+        Assert.assertTrue(result.toString().contains("coordinated=" + COORDINATED));
+    }
+}
\ No newline at end of file