Remove DataChangeListener protobuff messages
[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, false);
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         assertEquals(false, serialized.getRegisterOnAllInstances());
55
56     }
57
58     @Test
59     public void testFromSerializable(){
60         TestActorRef<Actor> testActor = factory.createTestActor(MessageCollectorActor.props());
61         RegisterChangeListener registerChangeListener = new RegisterChangeListener(TestModel.TEST_PATH, testActor
62                 , AsyncDataBroker.DataChangeScope.SUBTREE, true);
63
64         ListenerRegistrationMessages.RegisterChangeListener serialized
65                 = registerChangeListener.toSerializable();
66
67
68         RegisterChangeListener fromSerialized = RegisterChangeListener.fromSerializable(getSystem(), serialized);
69
70         assertEquals(TestModel.TEST_PATH, registerChangeListener.getPath());
71         assertEquals(testActor.path().toString(), fromSerialized.getDataChangeListenerPath().toString());
72         assertEquals(AsyncDataBroker.DataChangeScope.SUBTREE, fromSerialized.getScope());
73         assertEquals(true, fromSerialized.isRegisterOnAllInstances());
74
75     }
76 }

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