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
9 package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item.stat;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.mockito.ArgumentMatchers.any;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.times;
16 import static org.mockito.Mockito.verify;
18 import java.util.ArrayList;
19 import java.util.Collection;
20 import org.junit.Before;
21 import org.junit.Test;
22 import org.opendaylight.mdsal.binding.api.DataBroker;
23 import org.opendaylight.mdsal.binding.api.DataObjectModification;
24 import org.opendaylight.mdsal.binding.api.DataTreeModification;
25 import org.opendaylight.mdsal.binding.api.NotificationPublishService;
26 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
27 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
28 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
42 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
44 public class QueueStatNotificationSupplierImplTest {
46 private static final String FLOW_NODE_ID = "openflow:111";
47 private static final String FLOW_CODE_CONNECTOR_ID = "test-con-111";
48 private QueueStatNotificationSupplierImpl notifSupplierImpl;
49 private NotificationPublishService notifProviderService;
50 private DataBroker dataBroker;
53 public void initalization() {
54 notifProviderService = mock(NotificationPublishService.class);
55 dataBroker = mock(DataBroker.class);
56 notifSupplierImpl = new QueueStatNotificationSupplierImpl(notifProviderService, dataBroker);
57 TestSupplierVerifyHelper.verifyDataTreeChangeListenerRegistration(dataBroker);
60 @Test(expected = NullPointerException.class)
61 public void testNullChangeEvent() {
62 notifSupplierImpl.onDataTreeChanged(null);
65 @Test(expected = NullPointerException.class)
66 public void testNullableChangeEvent() {
67 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
71 public void testEmptyChangeEvent() {
72 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
76 public void testCreate() {
77 final QueueStatisticsUpdate notification = notifSupplierImpl
78 .createNotification(createTestQueueStat(), createTestQueueStatPath());
79 assertNotNull(notification);
80 assertEquals(FLOW_NODE_ID, notification.getId().getValue());
81 assertEquals(FLOW_CODE_CONNECTOR_ID, notification.nonnullNodeConnector().values().iterator().next().getId()
86 public void testCreateChangeEvent() throws InterruptedException {
87 final TestData<FlowCapableNodeConnectorQueueStatisticsData> testData = new TestData<>(createTestQueueStatPath(),
88 null, createTestQueueStat(), DataObjectModification.ModificationType.WRITE);
89 Collection<DataTreeModification<FlowCapableNodeConnectorQueueStatisticsData>> collection = new ArrayList<>();
90 collection.add(testData);
91 notifSupplierImpl.onDataTreeChanged(collection);
92 verify(notifProviderService, times(1)).putNotification(any(QueueStatisticsUpdate.class));
95 @Test(expected = IllegalArgumentException.class)
96 public void testCreateFromNullNodeConnector() {
97 notifSupplierImpl.createNotification(null, createTestQueueStatPath());
100 @Test(expected = IllegalArgumentException.class)
101 public void testCreateFromNullPath() {
102 notifSupplierImpl.createNotification(createTestQueueStat(), null);
105 @Test(expected = IllegalArgumentException.class)
106 public void testUpdateFromNullNodeConnector() {
107 notifSupplierImpl.createNotification(null, createTestQueueStatPath());
110 @Test(expected = IllegalArgumentException.class)
111 public void testUpdateFromNullPath() {
112 notifSupplierImpl.createNotification(createTestQueueStat(), null);
115 private static InstanceIdentifier<FlowCapableNodeConnectorQueueStatisticsData> createTestQueueStatPath() {
116 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID)))
117 .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(FLOW_CODE_CONNECTOR_ID)))
118 .augmentation(FlowCapableNodeConnector.class).child(Queue.class)
119 .augmentation(FlowCapableNodeConnectorQueueStatisticsData.class);
122 private static FlowCapableNodeConnectorQueueStatisticsData createTestQueueStat() {
123 final FlowCapableNodeConnectorQueueStatisticsDataBuilder builder
124 = new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
125 final FlowCapableNodeConnectorQueueStatisticsBuilder value
126 = new FlowCapableNodeConnectorQueueStatisticsBuilder();
127 builder.setFlowCapableNodeConnectorQueueStatistics(value.build());
128 return builder.build();