Merge "Cleanup: Remove passing around of DataPersistenceProvider"
[controller.git] / opendaylight / md-sal / messagebus-impl / src / test / java / org / opendaylight / controller / messagebus / app / impl / EventSourceTopicTest.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 package org.opendaylight.controller.messagebus.app.impl;
9
10 import static org.junit.Assert.assertNotNull;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.doReturn;
13 import static org.mockito.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
16
17 import java.util.HashMap;
18 import java.util.Map;
19
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
24 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
25 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService;
26 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
28 import org.opendaylight.yangtools.yang.binding.DataObject;
29 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
30
31 public class EventSourceTopicTest {
32
33     EventSourceTopic eventSourceTopic;
34     org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node dataObjectMock;
35     NodeId nodeIdMock;
36     EventSourceService eventSourceServiceMock;
37
38     @BeforeClass
39     public static void initTestClass() throws IllegalAccessException, InstantiationException {
40     }
41
42     @Before
43     public void setUp() throws Exception {
44         NotificationPattern notificationPattern = new NotificationPattern("value1");
45         eventSourceServiceMock = mock(EventSourceService.class);
46         eventSourceTopic = new EventSourceTopic(notificationPattern, "nodeIdPattern1", eventSourceServiceMock);
47     }
48
49     @Test
50     public void createModuleTest() {
51         assertNotNull("Instance has not been created correctly.", eventSourceTopic);
52     }
53
54     @Test
55     public void getTopicIdTest() {
56         assertNotNull("Topic has not been created correctly.", eventSourceTopic.getTopicId());
57     }
58
59     @Test
60     public void onDataChangedTest() {
61         AsyncDataChangeEvent asyncDataChangeEventMock = mock(AsyncDataChangeEvent.class);
62         onDataChangedTestHelper(asyncDataChangeEventMock);
63         eventSourceTopic.onDataChanged(asyncDataChangeEventMock);
64         verify(dataObjectMock, times(1)).getId();
65         verify(nodeIdMock, times(1)).getValue();
66     }
67
68     private void onDataChangedTestHelper(AsyncDataChangeEvent asyncDataChangeEventMock){
69         Map<InstanceIdentifier<?>, DataObject> map = new HashMap<>();
70         InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class);
71         dataObjectMock = mock(org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node.class);
72         map.put(instanceIdentifierMock, dataObjectMock);
73         doReturn(map).when(asyncDataChangeEventMock).getUpdatedData();
74
75         nodeIdMock = mock(NodeId.class);
76         doReturn(nodeIdMock).when(dataObjectMock).getId();
77         doReturn("nodeIdPattern1").when(nodeIdMock).getValue();
78     }
79
80     @Test
81     public void notifyNodeTest() {
82         InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class);
83         eventSourceTopic.notifyNode(instanceIdentifierMock);
84         verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class));
85     }
86
87 }

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