Unit tests for AbstractRequestProxy derived classes 68/52768/17
authorIvan Hrasko <ivan.hrasko@pantheon.tech>
Fri, 3 Mar 2017 14:34:56 +0000 (15:34 +0100)
committerTom Pantelis <tpanteli@brocade.com>
Wed, 8 Mar 2017 15:25:42 +0000 (15:25 +0000)
Change-Id: Id7eb9c30a147496dcb765843d4eb3463402c0df5
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1Test.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1EmptyModificationsTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1NotEmptyModificationsTest.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1Test.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1Test.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1Test.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1Test.java [new file with mode: 0644]
opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxyTest.java [new file with mode: 0644]

diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1Test.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1Test.java
new file mode 100644 (file)
index 0000000..2ebc726
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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;
+import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxyTest;
+import org.opendaylight.controller.cluster.access.concepts.Request;
+
+public class ConnectClientRequestProxyV1Test extends AbstractRequestProxyTest<ConnectClientRequestProxyV1> {
+    private static final ConnectClientRequest REQUEST = new ConnectClientRequest(
+            CLIENT_IDENTIFIER, ACTOR_REF, ABIVersion.TEST_PAST_VERSION, ABIVersion.TEST_FUTURE_VERSION);
+    private static final ConnectClientRequestProxyV1 OBJECT = new ConnectClientRequestProxyV1(REQUEST);
+
+    @Override
+    public ConnectClientRequestProxyV1 object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void createRequestTest() {
+        final Request request = object().createRequest(CLIENT_IDENTIFIER, 0, ACTOR_REF);
+        Assert.assertNotNull(request);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1EmptyModificationsTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1EmptyModificationsTest.java
new file mode 100644 (file)
index 0000000..1a85d22
--- /dev/null
@@ -0,0 +1,33 @@
+/*
+ * 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 com.google.common.collect.Lists;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxyTest;
+import org.opendaylight.controller.cluster.access.concepts.Request;
+
+public class ModifyTransactionRequestProxyV1EmptyModificationsTest
+        extends AbstractRequestProxyTest<ModifyTransactionRequestProxyV1> {
+    private static final PersistenceProtocol PROTOCOL = PersistenceProtocol.ABORT;
+    private static final ModifyTransactionRequest REQUEST = new ModifyTransactionRequest(
+            TRANSACTION_IDENTIFIER, 0, ACTOR_REF, Lists.newArrayList(), PROTOCOL);
+    private static final ModifyTransactionRequestProxyV1 OBJECT = new ModifyTransactionRequestProxyV1(REQUEST);
+
+    @Override
+    public ModifyTransactionRequestProxyV1 object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void createRequestTest() {
+        final Request request = object().createRequest(TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+        Assert.assertNotNull(request);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1NotEmptyModificationsTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1NotEmptyModificationsTest.java
new file mode 100644 (file)
index 0000000..8218ea5
--- /dev/null
@@ -0,0 +1,41 @@
+/*
+ * 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 com.google.common.collect.Lists;
+import org.junit.Assert;
+import org.junit.Test;
+import org.opendaylight.controller.cluster.access.concepts.AbstractRequestProxyTest;
+import org.opendaylight.controller.cluster.access.concepts.Request;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
+
+public class ModifyTransactionRequestProxyV1NotEmptyModificationsTest
+        extends AbstractRequestProxyTest<ModifyTransactionRequestProxyV1> {
+    private static final PersistenceProtocol PROTOCOL = PersistenceProtocol.ABORT;
+    private static final NormalizedNode<?, ?> NODE = Builders.containerBuilder().withNodeIdentifier(
+            YangInstanceIdentifier.NodeIdentifier.create(QName.create("namespace", "localName"))).build();
+    private static final TransactionModification MODIFICATION = new TransactionWrite(
+            YangInstanceIdentifier.EMPTY, NODE);
+    private static final ModifyTransactionRequest REQUEST = new ModifyTransactionRequest(
+            TRANSACTION_IDENTIFIER, 0, ACTOR_REF, Lists.newArrayList(MODIFICATION), PROTOCOL);
+    private static final ModifyTransactionRequestProxyV1 OBJECT = new ModifyTransactionRequestProxyV1(REQUEST);
+
+    @Override
+    public ModifyTransactionRequestProxyV1 object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void createRequestTest() {
+        final Request request = object().createRequest(TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+        Assert.assertNotNull(request);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1Test.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1Test.java
new file mode 100644 (file)
index 0000000..e4c40cc
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.concepts.AbstractRequestProxyTest;
+import org.opendaylight.controller.cluster.access.concepts.Request;
+
+public class TransactionAbortRequestProxyV1Test extends AbstractRequestProxyTest<TransactionAbortRequestProxyV1> {
+    private static final TransactionAbortRequest REQUEST = new TransactionAbortRequest(
+            TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+    private static final TransactionAbortRequestProxyV1 OBJECT = new TransactionAbortRequestProxyV1(REQUEST);
+
+    @Override
+    public TransactionAbortRequestProxyV1 object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void createRequestTest() {
+        final Request request = object().createRequest(TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+        Assert.assertNotNull(request);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1Test.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1Test.java
new file mode 100644 (file)
index 0000000..b90438e
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.concepts.AbstractRequestProxyTest;
+import org.opendaylight.controller.cluster.access.concepts.Request;
+
+public class TransactionDoCommitRequestProxyV1Test extends AbstractRequestProxyTest<TransactionDoCommitRequestProxyV1> {
+    private static final TransactionDoCommitRequest REQUEST = new TransactionDoCommitRequest(
+            TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+    private static final TransactionDoCommitRequestProxyV1 OBJECT = new TransactionDoCommitRequestProxyV1(REQUEST);
+
+    @Override
+    public TransactionDoCommitRequestProxyV1 object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void createRequestTest() {
+        final Request request = object().createRequest(TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+        Assert.assertNotNull(request);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1Test.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1Test.java
new file mode 100644 (file)
index 0000000..693b05d
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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.concepts.AbstractRequestProxyTest;
+import org.opendaylight.controller.cluster.access.concepts.Request;
+
+public class TransactionPreCommitRequestProxyV1Test
+        extends AbstractRequestProxyTest<TransactionPreCommitRequestProxyV1> {
+    private static final TransactionPreCommitRequest REQUEST = new TransactionPreCommitRequest(
+            TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+    private static final TransactionPreCommitRequestProxyV1 OBJECT = new TransactionPreCommitRequestProxyV1(REQUEST);
+
+    @Override
+    public TransactionPreCommitRequestProxyV1 object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void createRequestTest() {
+        final Request request = object().createRequest(TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+        Assert.assertNotNull(request);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1Test.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1Test.java
new file mode 100644 (file)
index 0000000..c106ad5
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * 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.concepts.AbstractRequestProxyTest;
+import org.opendaylight.controller.cluster.access.concepts.Request;
+
+public class TransactionPurgeRequestProxyV1Test extends AbstractRequestProxyTest<TransactionPurgeRequestProxyV1> {
+    private static final TransactionPurgeRequest REQUEST = new TransactionPurgeRequest(
+            TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+    private static final TransactionPurgeRequestProxyV1 OBJECT = new TransactionPurgeRequestProxyV1(REQUEST);
+
+    @Override
+    public TransactionPurgeRequestProxyV1 object() {
+        return OBJECT;
+    }
+
+    @Test
+    public void createRequestTest() {
+        final Request request = object().createRequest(TRANSACTION_IDENTIFIER, 0, ACTOR_REF);
+        Assert.assertNotNull(request);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxyTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxyTest.java
new file mode 100644 (file)
index 0000000..3aceaa6
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * 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.concepts;
+
+import akka.actor.ActorRef;
+import akka.actor.ActorSystem;
+import akka.actor.ExtendedActorSystem;
+import akka.serialization.JavaSerializer;
+import akka.testkit.TestProbe;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectOutputStream;
+import java.lang.reflect.Constructor;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public abstract class AbstractRequestProxyTest<T extends AbstractRequestProxy> {
+    public abstract T object();
+
+    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);
+
+    private static final LocalHistoryIdentifier HISTORY_IDENTIFIER = new LocalHistoryIdentifier(
+            CLIENT_IDENTIFIER, 0);
+    protected static final TransactionIdentifier TRANSACTION_IDENTIFIER = new TransactionIdentifier(
+            HISTORY_IDENTIFIER, 0);
+
+    private static final ActorSystem SYSTEM = ActorSystem.create("test");
+    protected static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
+
+    @Before
+    public void setUp() {
+        JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
+    }
+
+    @Test
+    public void externalizableTest() throws Exception {
+        final T copy = copy();
+        Assert.assertTrue(copy != null);
+    }
+
+    @SuppressWarnings("unchecked")
+    private T copy() throws Exception {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+            object().writeExternal(oos);
+        }
+
+        try (ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()))) {
+            final Constructor constructor = object().getClass().getConstructor();
+            constructor.setAccessible(true);
+            final T result = (T) constructor.newInstance();
+            result.readExternal(ois);
+            return result;
+        }
+    }
+
+    @Test
+    public void readTargetTest() throws Exception {
+        final ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        try (ObjectOutputStream oos = new ObjectOutputStream(bos)) {
+            object().writeExternal(oos);
+        }
+
+        final ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(bos.toByteArray()));
+        Assert.assertNotNull(object().readTarget(ois));
+    }
+}
\ No newline at end of file

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.