82d51e86a7eef966011650c5500b6abd4cc4cb5f
[controller.git] / opendaylight / md-sal / cds-access-api / src / test / java / org / opendaylight / controller / cluster / access / commands / ConnectClientSuccessTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.access.commands;
9
10 import static org.junit.Assert.assertArrayEquals;
11 import static org.junit.Assert.assertEquals;
12
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.Collection;
22 import java.util.List;
23 import java.util.Optional;
24 import org.junit.Before;
25 import org.junit.Test;
26 import org.opendaylight.controller.cluster.access.ABIVersion;
27 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
28 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
29 import org.opendaylight.yangtools.yang.data.tree.api.ReadOnlyDataTree;
30 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
31
32 public class ConnectClientSuccessTest extends AbstractRequestSuccessTest<ConnectClientSuccess> {
33     private static final DataTree TREE = new InMemoryDataTreeFactory().create(
34         DataTreeConfiguration.DEFAULT_OPERATIONAL);
35     private static final ActorSystem SYSTEM = ActorSystem.create("test");
36     private static final ActorRef ACTOR_REF = TestProbe.apply(SYSTEM).ref();
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(
41             CLIENT_IDENTIFIER, 0, ACTOR_REF, ALTERNATES, TREE, MAX_MESSAGES);
42
43     public ConnectClientSuccessTest() {
44         super(OBJECT, 432 + ACTOR_REF.path().toSerializationFormat().length());
45     }
46
47     @Before
48     public void setUp() {
49         JavaSerializer.currentSystem().value_$eq((ExtendedActorSystem) SYSTEM);
50     }
51
52     @Test
53     public void testGetAlternates() {
54         final Collection<ActorSelection> alternates = OBJECT.getAlternates();
55         assertArrayEquals(ALTERNATES.toArray(), alternates.toArray());
56     }
57
58     @Test
59     public void testGetBackend() {
60         final ActorRef actorRef = OBJECT.getBackend();
61         assertEquals(ACTOR_REF, actorRef);
62     }
63
64     @Test
65     public void testGetDataTree() {
66         final ReadOnlyDataTree tree = OBJECT.getDataTree().get();
67         assertEquals(TREE, tree);
68     }
69
70     @Test
71     public void testGetMaxMessages() {
72         assertEquals(MAX_MESSAGES, OBJECT.getMaxMessages());
73     }
74
75     @Test
76     public void cloneAsVersionTest() {
77         final ConnectClientSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
78         assertEquals(OBJECT, clone);
79     }
80
81     @Test
82     public void addToStringAttributes() {
83         // Just verify it doesn't throw an exception.
84         OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
85     }
86
87     @Override
88     protected void doAdditionalAssertions(final ConnectClientSuccess deserialize) {
89         assertEquals(OBJECT.getAlternates().size(), deserialize.getAlternates().size());
90         assertEquals(OBJECT.getBackend(), deserialize.getBackend());
91         assertEquals(Optional.empty(), deserialize.getDataTree());
92         assertEquals(OBJECT.getMaxMessages(), deserialize.getMaxMessages());
93     }
94 }