Remove DOMDataTreeProducer-related classes
[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.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
17
18 import com.google.common.util.concurrent.FluentFuture;
19 import java.util.Collections;
20 import org.junit.Before;
21 import org.junit.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.mdsal.binding.api.DataBroker;
24 import org.opendaylight.mdsal.binding.api.DataObjectModification;
25 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
26 import org.opendaylight.mdsal.binding.api.DataTreeModification;
27 import org.opendaylight.mdsal.binding.api.ReadTransaction;
28 import org.opendaylight.mdsal.binding.api.WriteTransaction;
29 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
30 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventaggregator.rev141202.NotificationPattern;
31 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.EventSourceService;
32 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicInput;
33 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicOutputBuilder;
34 import org.opendaylight.yang.gen.v1.urn.cisco.params.xml.ns.yang.messagebus.eventsource.rev141202.JoinTopicStatus;
35 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.NodeId;
36 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.Node;
37 import org.opendaylight.yang.gen.v1.urn.tbd.params.xml.ns.yang.network.topology.rev131021.network.topology.topology.NodeKey;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
41
42 @Deprecated(forRemoval = true)
43 public class EventSourceTopicTest {
44
45     EventSourceTopic eventSourceTopic;
46     DataBroker dataBrokerMock;
47     EventSourceService eventSourceServiceMock;
48     EventSourceTopology eventSourceTopologyMock;
49
50     @BeforeClass
51     public static void initTestClass() {
52     }
53
54     @Before
55     public void setUp() {
56         final NotificationPattern notificationPattern = new NotificationPattern("value1");
57         eventSourceServiceMock = mock(EventSourceService.class);
58         doReturn(RpcResultBuilder.success(new JoinTopicOutputBuilder().setStatus(JoinTopicStatus.Up).build())
59                 .buildFuture()).when(eventSourceServiceMock).joinTopic(any(JoinTopicInput.class));
60
61         eventSourceTopologyMock = mock(EventSourceTopology.class);
62         dataBrokerMock = mock(DataBroker.class);
63         doReturn(eventSourceServiceMock).when(eventSourceTopologyMock).getEventSourceService();
64         doReturn(dataBrokerMock).when(eventSourceTopologyMock).getDataBroker();
65
66         WriteTransaction writeTransactionMock = mock(WriteTransaction.class);
67         doReturn(writeTransactionMock).when(dataBrokerMock).newWriteOnlyTransaction();
68         doNothing().when(writeTransactionMock).mergeParentStructurePut(any(LogicalDatastoreType.class),
69                 any(InstanceIdentifier.class), any(DataObject.class));
70         FluentFuture checkedFutureWriteMock = mock(FluentFuture.class);
71         doReturn(checkedFutureWriteMock).when(writeTransactionMock).commit();
72
73         ReadTransaction readOnlyTransactionMock = mock(ReadTransaction.class);
74         doReturn(readOnlyTransactionMock).when(dataBrokerMock).newReadOnlyTransaction();
75         FluentFuture checkedFutureReadMock = mock(FluentFuture.class);
76         doReturn(checkedFutureReadMock).when(readOnlyTransactionMock).read(LogicalDatastoreType.OPERATIONAL,
77                 EventSourceTopology.EVENT_SOURCE_TOPOLOGY_PATH);
78         eventSourceTopic = EventSourceTopic.create(notificationPattern, "nodeIdPattern1", eventSourceTopologyMock);
79     }
80
81     @Test
82     public void createModuleTest() {
83         assertNotNull("Instance has not been created correctly.", eventSourceTopic);
84     }
85
86     @Test
87     public void getTopicIdTest() {
88         assertNotNull("Topic has not been created correctly.", eventSourceTopic.getTopicId());
89     }
90
91     @SuppressWarnings("unchecked")
92     @Test
93     public void onDataTreeChangedTest() {
94         InstanceIdentifier<Node> instanceIdentifierMock = mock(InstanceIdentifier.class);
95         DataTreeModification<Node> mockDataTreeModification = mock(DataTreeModification.class);
96         DataObjectModification<Node> mockModification = mock(DataObjectModification.class);
97         doReturn(mockModification).when(mockDataTreeModification).getRootNode();
98         doReturn(DataTreeIdentifier.create(LogicalDatastoreType.OPERATIONAL, instanceIdentifierMock))
99                 .when(mockDataTreeModification).getRootPath();
100         doReturn(DataObjectModification.ModificationType.WRITE).when(mockModification).getModificationType();
101
102         Node dataObjectNodeMock = mock(Node.class);
103         doReturn(getNodeKey("testNodeId01")).when(dataObjectNodeMock).key();
104         NodeId nodeIdMock = mock(NodeId.class);
105         doReturn(nodeIdMock).when(dataObjectNodeMock).getNodeId();
106         doReturn("nodeIdPattern1").when(nodeIdMock).getValue();
107
108         doReturn(dataObjectNodeMock).when(mockModification).getDataAfter();
109
110         eventSourceTopic.onDataTreeChanged(Collections.singletonList(mockDataTreeModification));
111         verify(dataObjectNodeMock).getNodeId();
112         verify(nodeIdMock).getValue();
113     }
114
115     @Test
116     public void notifyNodeTest() {
117         InstanceIdentifier instanceIdentifierMock = mock(InstanceIdentifier.class);
118         eventSourceTopic.notifyNode(instanceIdentifierMock);
119         verify(eventSourceServiceMock, times(1)).joinTopic(any(JoinTopicInput.class));
120     }
121
122     public NodeKey getNodeKey(final String nodeId) {
123         return new NodeKey(new NodeId(nodeId));
124     }
125 }

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