From: Ivan Hrasko Date: Fri, 3 Mar 2017 14:34:56 +0000 (+0100) Subject: Unit tests for AbstractRequestProxy derived classes X-Git-Tag: release/carbon~187 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=f052c433a17a69c45642f9d8d246c6340fbaffab Unit tests for AbstractRequestProxy derived classes Change-Id: Id7eb9c30a147496dcb765843d4eb3463402c0df5 Signed-off-by: Ivan Hrasko --- 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 index 0000000000..2ebc7263d7 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ConnectClientRequestProxyV1Test.java @@ -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 { + 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 index 0000000000..1a85d221d6 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1EmptyModificationsTest.java @@ -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 { + 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 index 0000000000..8218ea592d --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionRequestProxyV1NotEmptyModificationsTest.java @@ -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 { + 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 index 0000000000..e4c40ccc7c --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortRequestProxyV1Test.java @@ -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 { + 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 index 0000000000..b90438e0c0 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionDoCommitRequestProxyV1Test.java @@ -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 { + 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 index 0000000000..693b05d986 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitRequestProxyV1Test.java @@ -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 { + 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 index 0000000000..c106ad5c15 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeRequestProxyV1Test.java @@ -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 { + 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 index 0000000000..3aceaa6e01 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/concepts/AbstractRequestProxyTest.java @@ -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 { + 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