2 * Copyright (c) 2014, 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.cluster.datastore;
11 import akka.actor.ActorRef;
12 import akka.actor.Props;
13 import java.util.HashMap;
14 import java.util.HashSet;
15 import java.util.List;
18 import org.junit.Assert;
19 import org.junit.Test;
20 import org.opendaylight.controller.cluster.datastore.messages.DataChanged;
21 import org.opendaylight.controller.cluster.datastore.utils.ActorContext;
22 import org.opendaylight.controller.cluster.datastore.utils.DoNothingActor;
23 import org.opendaylight.controller.cluster.datastore.utils.MessageCollectorActor;
24 import org.opendaylight.controller.cluster.datastore.utils.MockClusterWrapper;
25 import org.opendaylight.controller.cluster.datastore.utils.MockConfiguration;
26 import org.opendaylight.controller.md.cluster.datastore.model.CompositeModel;
27 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
29 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
30 public class DataChangeListenerProxyTest extends AbstractActorTest {
32 private static class MockDataChangedEvent implements AsyncDataChangeEvent<YangInstanceIdentifier, NormalizedNode<?, ?>> {
33 Map<YangInstanceIdentifier,NormalizedNode<?,?>> createdData = new HashMap<>();
34 Map<YangInstanceIdentifier,NormalizedNode<?,?>> updatedData = new HashMap<>();
35 Map<YangInstanceIdentifier,NormalizedNode<?,?>> originalData = new HashMap<>();
40 public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getCreatedData() {
41 createdData.put(YangInstanceIdentifier.builder().build(), CompositeModel.createDocumentOne(CompositeModel.createTestContext()));
46 public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getUpdatedData() {
47 updatedData.put(YangInstanceIdentifier.builder().build(), CompositeModel.createTestContainer());
53 public Set<YangInstanceIdentifier> getRemovedPaths() {
54 Set<YangInstanceIdentifier>ids = new HashSet<>();
55 ids.add( CompositeModel.TEST_PATH);
60 public Map<YangInstanceIdentifier, NormalizedNode<?, ?>> getOriginalData() {
61 originalData.put(YangInstanceIdentifier.builder().build(), CompositeModel.createFamily());
65 @Override public NormalizedNode<?, ?> getOriginalSubtree() {
66 return CompositeModel.createFamily() ;
69 @Override public NormalizedNode<?, ?> getUpdatedSubtree() {
70 return CompositeModel.createTestContainer();
76 public void testOnDataChanged() throws Exception {
77 final Props props = Props.create(MessageCollectorActor.class);
78 final ActorRef actorRef = getSystem().actorOf(props);
80 DataChangeListenerProxy dataChangeListenerProxy = new DataChangeListenerProxy(
81 getSystem().actorSelection(actorRef.path()));
83 dataChangeListenerProxy.onDataChanged(new MockDataChangedEvent());
85 //Check if it was received by the remote actor
87 testContext = new ActorContext(getSystem(), getSystem().actorOf(Props.create(DoNothingActor.class)), new MockClusterWrapper(), new MockConfiguration());
88 Object messages = testContext
89 .executeOperation(actorRef, "messages");
91 Assert.assertNotNull(messages);
93 Assert.assertTrue(messages instanceof List);
95 List<?> listMessages = (List<?>) messages;
97 Assert.assertEquals(1, listMessages.size());
99 Assert.assertTrue(listMessages.get(0).getClass().equals(DataChanged.class));