5dfabce0066ce04758dc3a4e8b83ce4624af4d9b
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / messages / RegisterChangeListenerTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.controller.cluster.datastore.messages;
10
11 import static junit.framework.TestCase.assertEquals;
12 import akka.actor.Actor;
13 import akka.serialization.Serialization;
14 import akka.testkit.TestActorRef;
15 import org.junit.After;
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.cluster.datastore.AbstractActorTest;
19 import org.opendaylight.controller.cluster.raft.TestActorFactory;
20 import org.opendaylight.controller.cluster.raft.utils.MessageCollectorActor;
21 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
22 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
23 import org.opendaylight.controller.protobuff.messages.common.NormalizedNodeMessages;
24 import org.opendaylight.controller.protobuff.messages.registration.ListenerRegistrationMessages;
25
26 public class RegisterChangeListenerTest extends AbstractActorTest {
27
28     private TestActorFactory factory;
29
30     @Before
31     public void setUp(){
32         factory = new TestActorFactory(getSystem());
33     }
34
35     @After
36     public void shutDown(){
37         factory.close();
38     }
39
40     @Test
41     public void testToSerializable(){
42         TestActorRef<Actor> testActor = factory.createTestActor(MessageCollectorActor.props());
43         RegisterChangeListener registerChangeListener = new RegisterChangeListener(TestModel.TEST_PATH, testActor
44                 , AsyncDataBroker.DataChangeScope.BASE);
45
46         ListenerRegistrationMessages.RegisterChangeListener serialized
47                 = registerChangeListener.toSerializable();
48
49         NormalizedNodeMessages.InstanceIdentifier path = serialized.getInstanceIdentifierPath();
50
51         assertEquals("urn:opendaylight:params:xml:ns:yang:controller:md:sal:dom:store:test", path.getCode(0));
52         assertEquals(Serialization.serializedActorPath(testActor), serialized.getDataChangeListenerActorPath());
53         assertEquals(AsyncDataBroker.DataChangeScope.BASE.ordinal(), serialized.getDataChangeScope());
54
55     }
56
57     @Test
58     public void testFromSerializable(){
59         TestActorRef<Actor> testActor = factory.createTestActor(MessageCollectorActor.props());
60         RegisterChangeListener registerChangeListener = new RegisterChangeListener(TestModel.TEST_PATH, testActor
61                 , AsyncDataBroker.DataChangeScope.SUBTREE);
62
63         ListenerRegistrationMessages.RegisterChangeListener serialized
64                 = registerChangeListener.toSerializable();
65
66
67         RegisterChangeListener fromSerialized = RegisterChangeListener.fromSerializable(getSystem(), serialized);
68
69         assertEquals(TestModel.TEST_PATH, registerChangeListener.getPath());
70         assertEquals(testActor.path().toString(), fromSerialized.getDataChangeListenerPath().toString());
71         assertEquals(AsyncDataBroker.DataChangeScope.SUBTREE, fromSerialized.getScope());
72
73
74     }
75 }

©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.