Complete implementation of DataChangeListenerRegistration and related classes
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / DataChangeListenerRegistrationProxyTest.java
1 package org.opendaylight.controller.cluster.datastore;
2
3 import akka.actor.ActorRef;
4 import akka.actor.Props;
5 import junit.framework.Assert;
6 import org.junit.Test;
7 import org.opendaylight.controller.cluster.datastore.messages.CloseDataChangeListenerRegistration;
8 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
9 import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
10 import org.opendaylight.controller.cluster.datastore.utils.MessageCollectorActor;
11 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
12 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeListener;
13 import org.opendaylight.yangtools.yang.data.api.InstanceIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
15
16 import java.util.List;
17
18 public class DataChangeListenerRegistrationProxyTest extends AbstractActorTest{
19
20     private static class MockDataChangeListener implements
21         AsyncDataChangeListener<InstanceIdentifier, NormalizedNode<?, ?>> {
22
23         @Override public void onDataChanged(
24             AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> change) {
25             throw new UnsupportedOperationException("onDataChanged");
26         }
27     }
28
29     @Test
30     public void testGetInstance() throws Exception {
31         final Props props = Props.create(MessageCollectorActor.class);
32         final ActorRef actorRef = getSystem().actorOf(props);
33
34         MockDataChangeListener listener =
35             new MockDataChangeListener();
36         DataChangeListenerRegistrationProxy proxy =
37             new DataChangeListenerRegistrationProxy(
38                 getSystem().actorSelection(actorRef.path()),
39                 listener);
40
41         Assert.assertEquals(listener, proxy.getInstance());
42
43     }
44
45     @Test
46     public void testClose() throws Exception {
47         final Props props = Props.create(MessageCollectorActor.class);
48         final ActorRef actorRef = getSystem().actorOf(props);
49
50         DataChangeListenerRegistrationProxy proxy =
51             new DataChangeListenerRegistrationProxy(
52                 getSystem().actorSelection(actorRef.path()),
53                 new MockDataChangeListener());
54
55         proxy.close();
56
57         //Check if it was received by the remote actor
58         ActorContext
59             testContext = new ActorContext(getSystem(), getSystem().actorOf(Props.create(DoNothingActor.class)));
60         Object messages = testContext
61             .executeLocalOperation(actorRef, "messages",
62                 ActorContext.ASK_DURATION);
63
64         Assert.assertNotNull(messages);
65
66         Assert.assertTrue(messages instanceof List);
67
68         List<Object> listMessages = (List<Object>) messages;
69
70         Assert.assertEquals(1, listMessages.size());
71
72         Assert.assertTrue(listMessages.get(0) instanceof CloseDataChangeListenerRegistration);
73     }
74 }

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