--- /dev/null
+/*
+ * 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);
+}
*/
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());
- }
}
--- /dev/null
+/*
+ * 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());
+ }
+}
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
--- /dev/null
+/*
+ * 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);
+ }
+}
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
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
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
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
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
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
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
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