From 2e84511f911d19570cd4e8d1462f8394479c72d8 Mon Sep 17 00:00:00 2001 From: Ivan Hrasko Date: Tue, 7 Mar 2017 10:42:22 +0100 Subject: [PATCH] Unit tests for TransactionSuccess derived classes Change-Id: I4f5a27d86875f53d1dee28350c16af79fd97eef0 Signed-off-by: Ivan Hrasko --- .../AbstractTransactionSuccessTest.java | 26 +++++++++++ .../CommitLocalTransactionRequestTest.java | 2 +- .../ExistsTransactionSuccessTest.java | 44 ++++++++++++++++++ .../ModifyTransactionSuccessTest.java | 32 +++++++++++++ .../commands/ReadTransactionSuccessTest.java | 45 +++++++++++++++++++ .../commands/TransactionAbortSuccessTest.java | 30 +++++++++++++ .../TransactionCanCommitSuccessTest.java | 30 +++++++++++++ .../TransactionCommitSuccessTest.java | 30 +++++++++++++ .../TransactionPreCommitSuccessTest.java | 30 +++++++++++++ .../TransactionPurgeResponseTest.java | 30 +++++++++++++ 10 files changed, 298 insertions(+), 1 deletion(-) create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccessTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessTest.java create mode 100644 opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessTest.java create mode 100644 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/AbstractTransactionSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessTest.java new file mode 100644 index 0000000000..e762912b95 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/AbstractTransactionSuccessTest.java @@ -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.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 { + 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); + + protected static final TransactionIdentifier TRANSACTION_IDENTIFIER = new TransactionIdentifier( + HISTORY_IDENTIFIER, 0); +} 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 index 209766aac7..646a7c5f8a 100644 --- 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 @@ -28,7 +28,7 @@ public class CommitLocalTransactionRequestTest private static final TransactionIdentifier TRANSACTION = new TransactionIdentifier(HISTORY, 0); private static final DataTreeModification MODIFICATION = Mockito.mock(DataTreeModification.class); - private static final boolean COORDINATED = Boolean.TRUE; + private static final boolean COORDINATED = true; private static final CommitLocalTransactionRequest OBJECT = new CommitLocalTransactionRequest( TRANSACTION, 0, ACTOR_REF, MODIFICATION, COORDINATED); diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccessTest.java new file mode 100644 index 0000000000..027613f93d --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ExistsTransactionSuccessTest.java @@ -0,0 +1,44 @@ +/* + * 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.base.MoreObjects; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.controller.cluster.access.ABIVersion; + +public class ExistsTransactionSuccessTest extends AbstractTransactionSuccessTest { + private static final boolean EXISTS = true; + + private static final ExistsTransactionSuccess OBJECT = new ExistsTransactionSuccess( + TRANSACTION_IDENTIFIER, 0, EXISTS); + + @Test + public void getExists() throws Exception { + final boolean result = OBJECT.getExists(); + Assert.assertEquals(EXISTS, result); + } + + @Test + public void externalizableProxy() throws Exception { + final ExistsTransactionSuccessProxyV1 proxy = OBJECT.externalizableProxy(ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final ExistsTransactionSuccess 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("exists=" + EXISTS)); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessTest.java new file mode 100644 index 0000000000..0961493efd --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ModifyTransactionSuccessTest.java @@ -0,0 +1,32 @@ +/* + * 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 ModifyTransactionSuccessTest extends AbstractTransactionSuccessTest { + private static final ModifyTransactionSuccess OBJECT = new ModifyTransactionSuccess( + TRANSACTION_IDENTIFIER, 0); + + @Test + public void externalizableProxy() throws Exception { + final AbstractTransactionSuccessProxy proxy = OBJECT.externalizableProxy( + ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final ModifyTransactionSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON); + Assert.assertEquals(OBJECT.getVersion(), clone.getVersion()); + Assert.assertEquals(OBJECT.getSequence(), clone.getSequence()); + Assert.assertEquals(OBJECT.getTarget(), clone.getTarget()); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessTest.java new file mode 100644 index 0000000000..55f665a87e --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/ReadTransactionSuccessTest.java @@ -0,0 +1,45 @@ +/* + * 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.base.Optional; +import org.junit.Assert; +import org.junit.Test; +import org.opendaylight.controller.cluster.access.ABIVersion; +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 ReadTransactionSuccessTest extends AbstractTransactionSuccessTest { + private static final NormalizedNode NODE = Builders.containerBuilder().withNodeIdentifier( + YangInstanceIdentifier.NodeIdentifier.create(QName.create("namespace", "localName"))).build(); + + private static final ReadTransactionSuccess OBJECT = new ReadTransactionSuccess( + TRANSACTION_IDENTIFIER, 0, Optional.of(NODE)); + + @Test + public void getData() throws Exception { + final Optional> result = OBJECT.getData(); + Assert.assertTrue(result.isPresent()); + Assert.assertEquals(NODE.getValue(), result.get().getValue()); + } + + @Test + public void externalizableProxy() throws Exception { + final AbstractTransactionSuccessProxy proxy = OBJECT.externalizableProxy( + ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final ReadTransactionSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON); + Assert.assertEquals(OBJECT, clone); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessTest.java new file mode 100644 index 0000000000..b86e42ca93 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionAbortSuccessTest.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.ABIVersion; + +public class TransactionAbortSuccessTest extends AbstractTransactionSuccessTest { + private static final TransactionAbortSuccess OBJECT = new TransactionAbortSuccess( + TRANSACTION_IDENTIFIER, 0); + + @Test + public void externalizableProxy() throws Exception { + final AbstractTransactionSuccessProxy proxy = OBJECT.externalizableProxy( + ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final TransactionAbortSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON); + Assert.assertEquals(OBJECT, clone); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessTest.java new file mode 100644 index 0000000000..bf2677d581 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCanCommitSuccessTest.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.ABIVersion; + +public class TransactionCanCommitSuccessTest extends AbstractTransactionSuccessTest { + private static final TransactionCanCommitSuccess OBJECT = new TransactionCanCommitSuccess( + TRANSACTION_IDENTIFIER, 0); + + @Test + public void externalizableProxy() throws Exception { + final AbstractTransactionSuccessProxy proxy = OBJECT.externalizableProxy( + ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final TransactionCanCommitSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON); + Assert.assertEquals(OBJECT, clone); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessTest.java new file mode 100644 index 0000000000..363707f557 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionCommitSuccessTest.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.ABIVersion; + +public class TransactionCommitSuccessTest extends AbstractTransactionSuccessTest { + private static final TransactionCommitSuccess OBJECT = new TransactionCommitSuccess( + TRANSACTION_IDENTIFIER, 0); + + @Test + public void externalizableProxy() throws Exception { + final AbstractTransactionSuccessProxy proxy = OBJECT.externalizableProxy( + ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final TransactionCommitSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON); + Assert.assertEquals(OBJECT, clone); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessTest.java new file mode 100644 index 0000000000..fc426fc3ed --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPreCommitSuccessTest.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.ABIVersion; + +public class TransactionPreCommitSuccessTest extends AbstractTransactionSuccessTest { + private static final TransactionPreCommitSuccess OBJECT = new TransactionPreCommitSuccess( + TRANSACTION_IDENTIFIER, 0); + + @Test + public void externalizableProxy() throws Exception { + final AbstractTransactionSuccessProxy proxy = OBJECT.externalizableProxy( + ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final TransactionPreCommitSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON); + Assert.assertEquals(OBJECT, clone); + } +} \ No newline at end of file diff --git a/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseTest.java b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseTest.java new file mode 100644 index 0000000000..c190e61a01 --- /dev/null +++ b/opendaylight/md-sal/cds-access-api/src/test/java/org/opendaylight/controller/cluster/access/commands/TransactionPurgeResponseTest.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.ABIVersion; + +public class TransactionPurgeResponseTest extends AbstractTransactionSuccessTest { + private static final TransactionPurgeResponse OBJECT = new TransactionPurgeResponse( + TRANSACTION_IDENTIFIER, 0); + + @Test + public void externalizableProxy() throws Exception { + final AbstractTransactionSuccessProxy proxy = OBJECT.externalizableProxy( + ABIVersion.BORON); + Assert.assertNotNull(proxy); + } + + @Test + public void cloneAsVersion() throws Exception { + final TransactionPurgeResponse clone = OBJECT.cloneAsVersion(ABIVersion.BORON); + Assert.assertEquals(OBJECT, clone); + } +} \ No newline at end of file -- 2.36.6