2 * Copyright (c) 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
8 package org.opendaylight.controller.messagebus.app.impl;
10 import org.junit.Before;
11 import org.junit.BeforeClass;
12 import org.junit.Test;
13 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
14 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
15 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService;
16 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
18 import org.opendaylight.yangtools.yang.binding.DataObject;
19 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import java.util.HashMap;
24 import static org.junit.Assert.assertNotNull;
25 import static org.mockito.Mockito.mock;
26 import static org.mockito.Mockito.times;
27 import static org.mockito.Mockito.verify;
28 import static org.mockito.Mockito.doReturn;
29 import static org.mockito.Mockito.any;
31 public class EventSourceTopicTest {
33 EventSourceTopic eventSourceTopic;
34 org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node dataObjectMock;
36 EventSourceService eventSourceServiceMock;
39 public static void initTestClass() throws IllegalAccessException, InstantiationException {
43 public void setUp() throws Exception {
44 NotificationPattern notificationPattern = new NotificationPattern("value1");
45 eventSourceServiceMock = mock(EventSourceService.class);
46 eventSourceTopic = new EventSourceTopic(notificationPattern, "nodeIdPattern1", eventSourceServiceMock);
50 public void createModuleTest() {
51 assertNotNull("Instance has not been created correctly.", eventSourceTopic);
55 public void getTopicIdTest() {
56 assertNotNull("Topic has not been created correctly.", eventSourceTopic.getTopicId());
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();
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();
75 nodeIdMock = mock(NodeId.class);
76 doReturn(nodeIdMock).when(dataObjectMock).getId();
77 doReturn("0").when(nodeIdMock).getValue();
81 public void notifyNodeTest() {
82 InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class);
83 eventSourceTopic.notifyNode(instanceIdentifierMock);
84 verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class));