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.HashMap;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Matchers;
22 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
24 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestChangeEventBuildHelper;
25 import org.opendaylight.openflowplugin.applications.notification.supplier.impl.helper.TestSupplierVerifyHelper;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
41 public class MeterStatNotificationSupplierImplTest {
43 private static final String FLOW_NODE_ID = "test-111";
44 private static final Long FLOW_METER_ID = 111L;
45 private MeterStatNotificationSupplierImpl notifSupplierImpl;
46 private NotificationProviderService notifProviderService;
47 private DataBroker dataBroker;
50 public void initalization() {
51 notifProviderService = mock(NotificationProviderService.class);
52 dataBroker = mock(DataBroker.class);
53 notifSupplierImpl = new MeterStatNotificationSupplierImpl(notifProviderService, dataBroker);
54 TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
57 @Test(expected = IllegalArgumentException.class)
58 public void testNullChangeEvent() {
59 notifSupplierImpl.onDataChanged(null);
63 public void testNullableChangeEvent() {
64 notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
68 public void testEmptyChangeEvent() {
69 notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
73 public void testCreate() {
74 final MeterStatisticsUpdated notification = notifSupplierImpl.createNotification(createTestMeterStat(),
75 createTestMeterStatPath());
76 assertNotNull(notification);
77 assertEquals(FLOW_NODE_ID, notification.getId().getValue());
81 public void testCreateChangeEvent() {
82 final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
83 createdData.put(createTestMeterStatPath(), createTestMeterStat());
84 notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
85 verify(notifProviderService, times(1)).publish(Matchers.any(MeterStatisticsUpdated.class));
88 @Test(expected = IllegalArgumentException.class)
89 public void testCreateFromNullNodeConnector() {
90 notifSupplierImpl.createNotification(null, createTestMeterStatPath());
93 @Test(expected = IllegalArgumentException.class)
94 public void testCreateFromNullPath() {
95 notifSupplierImpl.createNotification(createTestMeterStat(), null);
98 @Test(expected = IllegalArgumentException.class)
99 public void testUpdateFromNullNodeConnector() {
100 notifSupplierImpl.createNotification(null, createTestMeterStatPath());
103 @Test(expected = IllegalArgumentException.class)
104 public void testUpdateFromNullPath() {
105 notifSupplierImpl.createNotification(createTestMeterStat(), null);
108 private static InstanceIdentifier<MeterStatistics> createTestMeterStatPath() {
109 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID)))
110 .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(new MeterId(FLOW_METER_ID)))
111 .augmentation(NodeMeterStatistics.class).child(MeterStatistics.class);
114 private static MeterStatistics createTestMeterStat() {
115 final MeterStatisticsBuilder builder = new MeterStatisticsBuilder();
116 return builder.build();