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.inventory.rev130819.NodeConnectorId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.FlowCapableNodeConnectorStatisticsData;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.NodeConnectorStatisticsUpdate;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatistics;
39 import org.opendaylight.yang.gen.v1.urn.opendaylight.port.statistics.rev131214.flow.capable.node.connector.statistics.FlowCapableNodeConnectorStatisticsBuilder;
40 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
42 public class NodeConnectorStatNotificationSupplierImplTest {
44 private static final String FLOW_NODE_ID = "openflow:111";
45 private static final String FLOW_CODE_CONNECTOR_ID = "test-con-111";
46 private NodeConnectorStatNotificationSupplierImpl notifSupplierImpl;
47 private NotificationPublishService notifProviderService;
48 private DataBroker dataBroker;
51 public void initalization() {
52 notifProviderService = mock(NotificationPublishService.class);
53 dataBroker = mock(DataBroker.class);
54 notifSupplierImpl = new NodeConnectorStatNotificationSupplierImpl(notifProviderService, dataBroker);
55 TestSupplierVerifyHelper.verifyDataTreeChangeListenerRegistration(dataBroker);
58 @Test(expected = NullPointerException.class)
59 public void testNullChangeEvent() {
60 notifSupplierImpl.onDataTreeChanged(null);
63 @Test(expected = NullPointerException.class)
64 public void testNullableChangeEvent() {
65 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
69 public void testEmptyChangeEvent() {
70 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
74 public void testCreate() {
75 final NodeConnectorStatisticsUpdate notification = notifSupplierImpl
76 .createNotification(createTestConnectorStat(), createTestConnectorStatPath());
77 assertNotNull(notification);
78 assertEquals(FLOW_NODE_ID, notification.getId().getValue());
79 assertEquals(FLOW_CODE_CONNECTOR_ID, notification.nonnullNodeConnector().values().iterator().next().getId()
84 public void testCreateChangeEvent() throws InterruptedException {
85 final TestData<FlowCapableNodeConnectorStatistics> testData = new TestData<>(createTestConnectorStatPath(),
86 null, createTestConnectorStat(), DataObjectModification.ModificationType.WRITE);
87 Collection<DataTreeModification<FlowCapableNodeConnectorStatistics>> collection = new ArrayList<>();
88 collection.add(testData);
89 notifSupplierImpl.onDataTreeChanged(collection);
90 verify(notifProviderService, times(1)).putNotification(any(NodeConnectorStatisticsUpdate.class));
93 @Test(expected = IllegalArgumentException.class)
94 public void testCreateFromNullNodeConnector() {
95 notifSupplierImpl.createNotification(null, createTestConnectorStatPath());
98 @Test(expected = IllegalArgumentException.class)
99 public void testCreateFromNullPath() {
100 notifSupplierImpl.createNotification(createTestConnectorStat(), null);
103 @Test(expected = IllegalArgumentException.class)
104 public void testUpdateFromNullNodeConnector() {
105 notifSupplierImpl.createNotification(null, createTestConnectorStatPath());
108 @Test(expected = IllegalArgumentException.class)
109 public void testUpdateFromNullPath() {
110 notifSupplierImpl.createNotification(createTestConnectorStat(), null);
113 private static InstanceIdentifier<FlowCapableNodeConnectorStatistics> createTestConnectorStatPath() {
114 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID)))
115 .child(NodeConnector.class, new NodeConnectorKey(new NodeConnectorId(FLOW_CODE_CONNECTOR_ID)))
116 .augmentation(FlowCapableNodeConnectorStatisticsData.class)
117 .child(FlowCapableNodeConnectorStatistics.class);
120 private static FlowCapableNodeConnectorStatistics createTestConnectorStat() {
121 final FlowCapableNodeConnectorStatisticsBuilder builder = new FlowCapableNodeConnectorStatisticsBuilder();
122 return builder.build();