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.Mockito.mock;
14 import static org.mockito.Mockito.times;
15 import static org.mockito.Mockito.verify;
17 import java.util.ArrayList;
18 import java.util.Collection;
19 import java.util.HashMap;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.mockito.Matchers;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
26 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
27 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
28 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
29 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestData;
30 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.port.rev130925.queues.Queue;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
40 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
41 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsData;
42 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.FlowCapableNodeConnectorQueueStatisticsDataBuilder;
43 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.QueueStatisticsUpdate;
44 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatistics;
45 import org.opendaylight.yang.gen.v1.urn.opendaylight.queue.statistics.rev131216.flow.capable.node.connector.queue.statistics.FlowCapableNodeConnectorQueueStatisticsBuilder;
46 import org.opendaylight.yangtools.yang.binding.DataObject;
47 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
52 public class QueueStatNotificationSupplierImplTest {
54 private static final String FLOW_NODE_ID = "openflow:111";
55 private static final String FLOW_CODE_CONNECTOR_ID = "test-con-111";
56 private QueueStatNotificationSupplierImpl notifSupplierImpl;
57 private NotificationProviderService notifProviderService;
58 private DataBroker dataBroker;
61 public void initalization() {
62 notifProviderService = mock(NotificationProviderService.class);
63 dataBroker = mock(DataBroker.class);
64 notifSupplierImpl = new QueueStatNotificationSupplierImpl(notifProviderService, dataBroker);
65 TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
68 @Test(expected = NullPointerException.class)
69 public void testNullChangeEvent() {
70 notifSupplierImpl.onDataTreeChanged(null);
73 @Test(expected = NullPointerException.class)
74 public void testNullableChangeEvent() {
75 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
79 public void testEmptyChangeEvent() {
80 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
84 public void testCreate() {
85 final QueueStatisticsUpdate notification = notifSupplierImpl.createNotification(createTestQueueStat(),
86 createTestQueueStatPath());
87 assertNotNull(notification);
88 assertEquals(FLOW_NODE_ID, notification.getId().getValue());
89 assertEquals(FLOW_CODE_CONNECTOR_ID, notification.getNodeConnector().get(0).getId().getValue());
93 public void testCreateChangeEvent() {
94 final TestData testData = new TestData(createTestQueueStatPath(),null,createTestQueueStat(),
95 DataObjectModification.ModificationType.WRITE);
96 Collection<DataTreeModification<FlowCapableNodeConnectorQueueStatisticsData>> collection = new ArrayList<>();
97 collection.add(testData);
98 notifSupplierImpl.onDataTreeChanged(collection);
99 verify(notifProviderService, times(1)).publish(Matchers.any(QueueStatisticsUpdate.class));
102 @Test(expected = IllegalArgumentException.class)
103 public void testCreateFromNullNodeConnector() {
104 notifSupplierImpl.createNotification(null, createTestQueueStatPath());
107 @Test(expected = IllegalArgumentException.class)
108 public void testCreateFromNullPath() {
109 notifSupplierImpl.createNotification(createTestQueueStat(), null);
112 @Test(expected = IllegalArgumentException.class)
113 public void testUpdateFromNullNodeConnector() {
114 notifSupplierImpl.createNotification(null, createTestQueueStatPath());
117 @Test(expected = IllegalArgumentException.class)
118 public void testUpdateFromNullPath() {
119 notifSupplierImpl.createNotification(createTestQueueStat(), null);
122 private static InstanceIdentifier<FlowCapableNodeConnectorQueueStatisticsData> createTestQueueStatPath() {
123 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID)))
124 .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(FLOW_CODE_CONNECTOR_ID)))
125 .augmentation(FlowCapableNodeConnector.class).child(Queue.class)
126 .augmentation(FlowCapableNodeConnectorQueueStatisticsData.class);
129 private static FlowCapableNodeConnectorQueueStatisticsData createTestQueueStat() {
130 final FlowCapableNodeConnectorQueueStatisticsDataBuilder builder = new FlowCapableNodeConnectorQueueStatisticsDataBuilder();
131 final FlowCapableNodeConnectorQueueStatisticsBuilder value = new FlowCapableNodeConnectorQueueStatisticsBuilder();
132 builder.setFlowCapableNodeConnectorQueueStatistics(value.build());
133 return builder.build();