2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.controller.cluster.access.commands;
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
13 import akka.actor.ActorRef;
14 import akka.actor.ActorSelection;
15 import akka.actor.ActorSystem;
16 import akka.actor.ExtendedActorSystem;
17 import akka.serialization.JavaSerializer;
18 import akka.testkit.TestProbe;
19 import com.google.common.base.MoreObjects;
20 import com.google.common.collect.ImmutableList;
21 import java.util.List;
22 import java.util.Optional;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.opendaylight.controller.cluster.access.ABIVersion;
26 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
27 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
28 import org.opendaylight.yangtools.yang.data.tree.api.ReadOnlyDataTree;
29 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
31 public class ConnectClientSuccessTest extends AbstractRequestSuccessTest<ConnectClientSuccess> {
32 private static final DataTree TREE = new InMemoryDataTreeFactory().create(
33 DataTreeConfiguration.DEFAULT_OPERATIONAL);
34 private static final ActorSystem SYSTEM = ActorSystem.create("test");
35 private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
36 private static final int ACTOR_REF_SIZE = ACTOR_REF.path().toSerializationFormat().length();
37 private static final ActorSelection ACTOR_SELECTION = ActorSelection.apply(ACTOR_REF, "foo");
38 private static final List<ActorSelection> ALTERNATES = ImmutableList.of(ACTOR_SELECTION);
39 private static final int MAX_MESSAGES = 10;
40 private static final ConnectClientSuccess OBJECT = new ConnectClientSuccess(CLIENT_IDENTIFIER, 0, ACTOR_REF,
41 ALTERNATES, TREE, MAX_MESSAGES);
43 public ConnectClientSuccessTest() {
44 super(OBJECT, 146 + ACTOR_REF_SIZE, 432 + ACTOR_REF_SIZE);
49 JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
53 public void testGetAlternates() {
54 final var alternates = OBJECT.getAlternates();
55 assertArrayEquals(ALTERNATES.toArray(), alternates.toArray());
59 public void testGetBackend() {
60 final ActorRef actorRef = OBJECT.getBackend();
61 assertEquals(ACTOR_REF, actorRef);
65 public void testGetDataTree() {
66 final ReadOnlyDataTree tree = OBJECT.getDataTree().orElseThrow();
67 assertEquals(TREE, tree);
71 public void testGetMaxMessages() {
72 assertEquals(MAX_MESSAGES, OBJECT.getMaxMessages());
76 public void cloneAsVersionTest() {
77 final var clone = OBJECT.cloneAsVersion(ABIVersion.MAGNESIUM);
78 assertEquals(OBJECT.getSequence(), clone.getSequence());
79 assertEquals(OBJECT.getTarget(), clone.getTarget());
80 assertEquals(OBJECT.getAlternates(), clone.getAlternates());
81 assertEquals(OBJECT.getBackend(), clone.getBackend());
82 assertEquals(OBJECT.getDataTree(), clone.getDataTree());
83 assertEquals(OBJECT.getMaxMessages(), clone.getMaxMessages());
87 public void addToStringAttributes() {
88 // Just verify it doesn't throw an exception.
89 OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
93 protected void doAdditionalAssertions(final ConnectClientSuccess deserialize) {
94 assertEquals(OBJECT.getAlternates().size(), deserialize.getAlternates().size());
95 assertEquals(OBJECT.getBackend(), deserialize.getBackend());
96 assertEquals(Optional.empty(), deserialize.getDataTree());
97 assertEquals(OBJECT.getMaxMessages(), deserialize.getMaxMessages());