Do not leak DataTree from backend actor
[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 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.DataTreeConfiguration;
27 import org.opendaylight.yangtools.yang.data.api.schema.tree.ReadOnlyDataTree;
28 import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
29
30 public class ConnectClientSuccessTest extends AbstractRequestSuccessTest<ConnectClientSuccess> {
31
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 ActorSelection ACTOR_SELECTION =  ActorSelection.apply(ACTOR_REF, "foo");
37     private static final List<ActorSelection> ALTERNATES = ImmutableList.of(ACTOR_SELECTION);
38     private static final int MAX_MESSAGES = 10;
39     private static final ConnectClientSuccess OBJECT = new ConnectClientSuccess(
40             CLIENT_IDENTIFIER, 0, ACTOR_REF, ALTERNATES, TREE, MAX_MESSAGES);
41
42     @Override
43     protected ConnectClientSuccess object() {
44         return OBJECT;
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         Assert.assertArrayEquals(ALTERNATES.toArray(), alternates.toArray());
56     }
57
58     @Test
59     public void testGetBackend() {
60         final ActorRef actorRef = OBJECT.getBackend();
61         Assert.assertEquals(ACTOR_REF, actorRef);
62     }
63
64     @Test
65     public void testGetDataTree() {
66         final ReadOnlyDataTree tree = OBJECT.getDataTree().get();
67         Assert.assertEquals(TREE, tree);
68     }
69
70     @Test
71     public void testGetMaxMessages() {
72         final int maxMessages = OBJECT.getMaxMessages();
73         Assert.assertEquals(MAX_MESSAGES, maxMessages);
74     }
75
76     @Test
77     public void cloneAsVersionTest() {
78         final ConnectClientSuccess clone = OBJECT.cloneAsVersion(ABIVersion.BORON);
79         Assert.assertEquals(OBJECT, clone);
80     }
81
82     @Test
83     public void addToStringAttributes() {
84         // Just verify it doesn't throw an exception.
85         OBJECT.addToStringAttributes(MoreObjects.toStringHelper(OBJECT));
86     }
87
88     @Override
89     protected void doAdditionalAssertions(final Object deserialize) {
90         Assert.assertTrue(deserialize instanceof ConnectClientSuccess);
91         Assert.assertEquals(OBJECT.getAlternates().size(), ((ConnectClientSuccess) deserialize).getAlternates().size());
92         Assert.assertEquals(OBJECT.getBackend(), ((ConnectClientSuccess) deserialize).getBackend());
93         Assert.assertEquals(Optional.empty(), ((ConnectClientSuccess) deserialize).getDataTree());
94         Assert.assertEquals(OBJECT.getMaxMessages(), ((ConnectClientSuccess) deserialize).getMaxMessages());
95     }
96 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.