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 akka.actor.ActorRef;
11 import akka.actor.ActorSelection;
12 import akka.actor.ActorSystem;
13 import akka.actor.ExtendedActorSystem;
14 import akka.serialization.JavaSerializer;
15 import akka.testkit.TestProbe;
16 import com.google.common.base.MoreObjects;
17 import com.google.common.collect.ImmutableList;
18 import java.util.Collection;
19 import java.util.List;
20 import java.util.Optional;
21 import org.junit.Assert;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.controller.cluster.access.ABIVersion;
25 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
26 import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
27 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
29 public class ConnectClientSuccessTest extends AbstractRequestSuccessTest<ConnectClientSuccess> {
31 private static final DataTree TREE = InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
32 private static final ActorSystem SYSTEM = ActorSystem.create("test");
33 private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
34 private static final ActorSelection ACTOR_SELECTION = ActorSelection.apply(ACTOR_REF, "foo");
35 private static final List<ActorSelection> ALTERNATES = ImmutableList.of(ACTOR_SELECTION);
36 private static final int MAX_MESSAGES = 10;
37 private static final ConnectClientSuccess OBJECT = new ConnectClientSuccess(
38 CLIENT_IDENTIFIER, 0, ACTOR_REF, ALTERNATES, TREE, MAX_MESSAGES);
41 protected ConnectClientSuccess object() {
47 JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
51 public void testGetAlternates() {
52 final Collection<ActorSelection> alternates = OBJECT.getAlternates();
53 Assert.assertArrayEquals(ALTERNATES.toArray(), alternates.toArray());
57 public void testGetBackend() {
58 final ActorRef actorRef = OBJECT.getBackend();
59 Assert.assertEquals(ACTOR_REF, actorRef);
63 public void testGetDataTree() {
64 final DataTree tree = OBJECT.getDataTree().get();
65 Assert.assertEquals(TREE, tree);
69 public void testGetMaxMessages() {
70 final int maxMessages = OBJECT.getMaxMessages();
71 Assert.assertEquals(MAX_MESSAGES, maxMessages);
75 public void cloneAsVersionTest() throws Exception {
76 final ConnectClientSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
77 Assert.assertEquals(OBJECT, clone);
81 public void addToStringAttributes() {
82 // Just verify it doesn't throw an exception.
83 OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
87 protected void doAdditionalAssertions(final Object deserialize) {
88 Assert.assertTrue(deserialize instanceof ConnectClientSuccess);
89 Assert.assertEquals(OBJECT.getAlternates().size(), ((ConnectClientSuccess) deserialize).getAlternates().size());
90 Assert.assertEquals(OBJECT.getBackend(), ((ConnectClientSuccess) deserialize).getBackend());
91 Assert.assertEquals(Optional.empty(), ((ConnectClientSuccess) deserialize).getDataTree());
92 Assert.assertEquals(OBJECT.getMaxMessages(), ((ConnectClientSuccess) deserialize).getMaxMessages());