From dfb4d7bb16a7a1991461684eafec39c2f692f4a4 Mon Sep 17 00:00:00 2001 From: Martin Bobak Date: Thu, 20 Aug 2015 23:45:07 +0200 Subject: [PATCH] BUG-4117: add support of Old Notif. for Statistics - keep backward old notification compatibility for FlowCapableNode subnode's statistics Note: Original commit https://git.opendaylight.org/gerrit/#/c/25965/ has to be broken to a chain of smaller commits Change-Id: Ie1f5ce8b078a90da84878e8a9be68f042567d5ea Signed-off-by: Martin Bobak Signed-off-by: Vaclav Demcak --- .../supplier/OldNotifProviderImpl.java | 17 ++- .../stat/FlowTableStatNotifSupplierImpl.java | 72 +++++++++++ .../item/stat/GroupStatNotifSupplierImpl.java | 66 ++++++++++ .../item/stat/MeterStatNotifSupplierImpl.java | 66 ++++++++++ .../FlowTableStatNotifSupplierImplTest.java | 119 ++++++++++++++++++ .../stat/GroupStatNotifSupplierImplTest.java | 119 ++++++++++++++++++ .../stat/MeterStatNotifSupplierImplTest.java | 119 ++++++++++++++++++ 7 files changed, 577 insertions(+), 1 deletion(-) create mode 100644 applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImpl.java create mode 100644 applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImpl.java create mode 100644 applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImpl.java create mode 100644 applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImplTest.java create mode 100644 applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImplTest.java create mode 100644 applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImplTest.java diff --git a/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/OldNotifProviderImpl.java b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/OldNotifProviderImpl.java index 29b847016a..884f4e218f 100644 --- a/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/OldNotifProviderImpl.java +++ b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/OldNotifProviderImpl.java @@ -21,6 +21,9 @@ import org.opendaylight.openflowplugin.applications.old.notification.supplier.im import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.GroupNotificationSupplierImpl; import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.MeterNotificationSupplierImpl; import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat.FlowStatNotifSupplierImpl; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat.FlowTableStatNotifSupplierImpl; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat.GroupStatNotifSupplierImpl; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat.MeterStatNotifSupplierImpl; import org.opendaylight.openflowplugin.applications.old.notification.supplier.tools.OldNotifProviderConfig; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector; @@ -31,9 +34,13 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.Flow import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowUpdated; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowsStatisticsUpdate; import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupAdded; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupRemoved; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.GroupUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics; import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved; import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated; @@ -42,6 +49,8 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpd import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterAdded; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterRemoved; import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.MeterUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics; /** * Provider Implementation @@ -60,6 +69,9 @@ public class OldNotifProviderImpl implements OldNotifProvider { private OldNotifSupplierForItem meterSupp; private OldNotifSupplierForItem groupSupp; private OldNotifSupplierForItemStat flowStatSupp; + private OldNotifSupplierForItemStat flowTableStatSupp; + private OldNotifSupplierForItemStat meterStatSupp; + private OldNotifSupplierForItemStat groupStatSupp; /** * Provider constructor set all needed final parameters @@ -83,9 +95,12 @@ public class OldNotifProviderImpl implements OldNotifProvider { meterSupp = config.isMeterSupport() ? new MeterNotificationSupplierImpl(nps, db) : null; groupSupp = config.isGroupSupport() ? new GroupNotificationSupplierImpl(nps, db) : null; flowStatSupp = config.isFlowStatSupport() ? new FlowStatNotifSupplierImpl(nps, db) : null; + flowTableStatSupp = config.isFlowTableStatSupport() ? new FlowTableStatNotifSupplierImpl(nps, db) : null; + meterStatSupp = config.isMeterStatSupport() ? new MeterStatNotifSupplierImpl(nps, db) : null; + groupStatSupp = config.isGroupStatSupport() ? new GroupStatNotifSupplierImpl(nps, db) : null; supplierList = new ArrayList<>(Arrays.asList(nodeSupp, connectorSupp, flowSupp, meterSupp, groupSupp, - flowStatSupp)); + flowStatSupp, flowTableStatSupp, meterStatSupp, groupStatSupp)); } @Override diff --git a/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImpl.java b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImpl.java new file mode 100644 index 0000000000..2f15965f93 --- /dev/null +++ b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImpl.java @@ -0,0 +1,72 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat; + +import com.google.common.base.Preconditions; +import java.util.Collections; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdateBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.and.statistics.map.FlowTableAndStatisticsMapKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.table.types.rev131026.TableId; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Implementation define a contract between {@link FlowTableStatistics} data object + * and {@link FlowTableStatisticsUpdate} notification. + */ +public class FlowTableStatNotifSupplierImpl extends + AbstractNotifSupplierForItemStat { + + private static final InstanceIdentifier wildCardedInstanceIdent = + getNodeWildII().augmentation(FlowCapableNode.class).child(Table.class) + .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class); + + /** + * Constructor register supplier as DataChangeLister and create wildCarded InstanceIdentifier. + * + * @param notifProviderService - {@link NotificationProviderService} + * @param db - {@link DataBroker} + */ + public FlowTableStatNotifSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) { + super(notifProviderService, db, FlowTableStatistics.class); + } + + @Override + public InstanceIdentifier getWildCardPath() { + return wildCardedInstanceIdent; + } + + @Override + public FlowTableStatisticsUpdate createNotification(final FlowTableStatistics o, + final InstanceIdentifier path) { + Preconditions.checkArgument(o != null); + Preconditions.checkArgument(path != null); + + final FlowTableAndStatisticsMapBuilder ftsmBuilder = new FlowTableAndStatisticsMapBuilder(o); + ftsmBuilder.setKey(new FlowTableAndStatisticsMapKey(new TableId(path.firstKeyOf(Table.class, TableKey.class).getId()))); + + final FlowTableStatisticsUpdateBuilder builder = new FlowTableStatisticsUpdateBuilder(); + builder.setId(getNodeId(path)); + builder.setMoreReplies(Boolean.FALSE); + // NOTE : fix if it needs, but we have to ask DataStore for the NodeConnector list + builder.setNodeConnector(Collections. emptyList()); + builder.setFlowTableAndStatisticsMap(Collections.singletonList(ftsmBuilder.build())); + return builder.build(); + } +} + diff --git a/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImpl.java b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImpl.java new file mode 100644 index 0000000000..268c03a817 --- /dev/null +++ b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat; + +import com.google.common.base.Preconditions; +import java.util.Collections; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdatedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.group.statistics.reply.GroupStatsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Implementation define a contract between {@link GroupStatistics} data object + * and {@link GroupStatisticsUpdated} notification. + */ +public class GroupStatNotifSupplierImpl extends + AbstractNotifSupplierForItemStat { + + private static final InstanceIdentifier wildCardedInstanceIdent = + getNodeWildII().augmentation(FlowCapableNode.class).child(Group.class) + .augmentation(NodeGroupStatistics.class).child(GroupStatistics.class); + + /** + * Constructor register supplier as DataChangeLister and create wildCarded InstanceIdentifier. + * + * @param notifProviderService - {@link NotificationProviderService} + * @param db - {@link DataBroker} + */ + public GroupStatNotifSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) { + super(notifProviderService, db, GroupStatistics.class); + } + + @Override + public InstanceIdentifier getWildCardPath() { + return wildCardedInstanceIdent; + } + + @Override + public GroupStatisticsUpdated createNotification(final GroupStatistics o, + final InstanceIdentifier path) { + Preconditions.checkArgument(o != null); + Preconditions.checkArgument(path != null); + + final GroupStatisticsUpdatedBuilder builder = new GroupStatisticsUpdatedBuilder(); + builder.setId(getNodeId(path)); + builder.setMoreReplies(Boolean.FALSE); + // TODO : fix if it needs, but we have to ask DataStore for the NodeConnector list + builder.setNodeConnector(Collections.emptyList()); + builder.setGroupStats(Collections.singletonList(new GroupStatsBuilder(o).build())); + return builder.build(); + } +} + diff --git a/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImpl.java b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImpl.java new file mode 100644 index 0000000000..32a52dcc01 --- /dev/null +++ b/applications/old-notification-supplier/src/main/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImpl.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat; + +import com.google.common.base.Preconditions; +import java.util.Collections; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdatedBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.meter.statistics.reply.MeterStatsBuilder; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +/** + * Implementation define a contract between {@link MeterStatistics} data object + * and {@link MeterStatisticsUpdated} notification. + */ +public class MeterStatNotifSupplierImpl extends + AbstractNotifSupplierForItemStat { + + private static final InstanceIdentifier wildCardedInstanceIdent = + getNodeWildII().augmentation(FlowCapableNode.class).child(Meter.class) + .augmentation(NodeMeterStatistics.class).child(MeterStatistics.class); + + /** + * Constructor register supplier as DataChangeLister and create wildCarded InstanceIdentifier. + * + * @param notifProviderService - {@link NotificationProviderService} + * @param db - {@link DataBroker} + */ + public MeterStatNotifSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) { + super(notifProviderService, db, MeterStatistics.class); + } + + @Override + public InstanceIdentifier getWildCardPath() { + return wildCardedInstanceIdent; + } + + @Override + public MeterStatisticsUpdated createNotification(final MeterStatistics o, + final InstanceIdentifier path) { + Preconditions.checkArgument(o != null); + Preconditions.checkArgument(path != null); + + final MeterStatisticsUpdatedBuilder builder = new MeterStatisticsUpdatedBuilder(); + builder.setId(getNodeId(path)); + builder.setMoreReplies(Boolean.FALSE); + // TODO : fix if it needs, but we have to ask DataStore for the NodeConnector list + builder.setNodeConnector(Collections. emptyList()); + builder.setMeterStats(Collections.singletonList(new MeterStatsBuilder(o).build())); + return builder.build(); + } +} + diff --git a/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImplTest.java b/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImplTest.java new file mode 100644 index 0000000000..662883c3ac --- /dev/null +++ b/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/FlowTableStatNotifSupplierImplTest.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Matchers; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.helper.TestChangeEventBuildHelper; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.helper.TestSupplierVerifyHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsData; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.FlowTableStatisticsUpdate; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.table.statistics.rev131215.flow.table.statistics.FlowTableStatisticsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class FlowTableStatNotifSupplierImplTest { + + private static final String FLOW_NODE_ID = "test-111"; + private static final Short FLOW_TABLE_ID = 111; + private static final String FLOW_ID = "test-flow-111"; + private FlowTableStatNotifSupplierImpl notifSupplierImpl; + private NotificationProviderService notifProviderService; + private DataBroker dataBroker; + + @Before + public void initalization() { + notifProviderService = mock(NotificationProviderService.class); + dataBroker = mock(DataBroker.class); + notifSupplierImpl = new FlowTableStatNotifSupplierImpl(notifProviderService, dataBroker); + TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker); + } + + @Test(expected = IllegalArgumentException.class) + public void testNullChangeEvent() { + notifSupplierImpl.onDataChanged(null); + } + + @Test + public void testNullableChangeEvent() { + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent()); + } + + @Test + public void testEmptyChangeEvent() { + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent()); + } + + @Test + public void testCreate() { + final FlowTableStatisticsUpdate notification = notifSupplierImpl.createNotification(createTestFlowTableStat(), + createTestFlowTableStatPath()); + assertNotNull(notification); + assertEquals(FLOW_NODE_ID, notification.getId().getValue()); + } + + @Test + public void testCreateChangeEvent() { + final Map, DataObject> createdData = new HashMap<>(); + createdData.put(createTestFlowTableStatPath(), createTestFlowTableStat()); + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null)); + verify(notifProviderService, times(1)).publish(Matchers.any(FlowTableStatisticsUpdate.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFromNullNodeConnector() { + notifSupplierImpl.createNotification(null, createTestFlowTableStatPath()); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFromNullPath() { + notifSupplierImpl.createNotification(createTestFlowTableStat(), null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUpdateFromNullNodeConnector() { + notifSupplierImpl.createNotification(null, createTestFlowTableStatPath()); + } + + @Test(expected = IllegalArgumentException.class) + public void testUpdateFromNullPath() { + notifSupplierImpl.createNotification(createTestFlowTableStat(), null); + } + + private static InstanceIdentifier createTestFlowTableStatPath() { + return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID))) + .augmentation(FlowCapableNode.class).child(Table.class, new TableKey(FLOW_TABLE_ID)) + .augmentation(FlowTableStatisticsData.class).child(FlowTableStatistics.class); + } + + private static FlowTableStatistics createTestFlowTableStat() { + final FlowTableStatisticsBuilder builder = new FlowTableStatisticsBuilder(); + return builder.build(); + } +} + diff --git a/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImplTest.java b/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImplTest.java new file mode 100644 index 0000000000..bcbbc48371 --- /dev/null +++ b/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/GroupStatNotifSupplierImplTest.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Matchers; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.helper.TestChangeEventBuildHelper; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.helper.TestSupplierVerifyHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group; +import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class GroupStatNotifSupplierImplTest { + + private static final String FLOW_NODE_ID = "test-111"; + private static final Long FLOW_TABLE_ID = 111L; + private GroupStatNotifSupplierImpl notifSupplierImpl; + private NotificationProviderService notifProviderService; + private DataBroker dataBroker; + + @Before + public void initalization() { + notifProviderService = mock(NotificationProviderService.class); + dataBroker = mock(DataBroker.class); + notifSupplierImpl = new GroupStatNotifSupplierImpl(notifProviderService, dataBroker); + TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker); + } + + @Test(expected = IllegalArgumentException.class) + public void testNullChangeEvent() { + notifSupplierImpl.onDataChanged(null); + } + + @Test + public void testNullableChangeEvent() { + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent()); + } + + @Test + public void testEmptyChangeEvent() { + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent()); + } + + @Test + public void testCreate() { + final GroupStatisticsUpdated notification = notifSupplierImpl.createNotification(createTestGroupStat(), + createTestGroupStatPath()); + assertNotNull(notification); + assertEquals(FLOW_NODE_ID, notification.getId().getValue()); + } + + @Test + public void testCreateChangeEvent() { + final Map, DataObject> createdData = new HashMap<>(); + createdData.put(createTestGroupStatPath(), createTestGroupStat()); + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null)); + verify(notifProviderService, times(1)).publish(Matchers.any(GroupStatisticsUpdated.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFromNullNodeConnector() { + notifSupplierImpl.createNotification(null, createTestGroupStatPath()); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFromNullPath() { + notifSupplierImpl.createNotification(createTestGroupStat(), null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUpdateFromNullNodeConnector() { + notifSupplierImpl.createNotification(null, createTestGroupStatPath()); + } + + @Test(expected = IllegalArgumentException.class) + public void testUpdateFromNullPath() { + notifSupplierImpl.createNotification(createTestGroupStat(), null); + } + + private static InstanceIdentifier createTestGroupStatPath() { + return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID))) + .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(FLOW_TABLE_ID))) + .augmentation(NodeGroupStatistics.class).child(GroupStatistics.class); + } + + private static GroupStatistics createTestGroupStat() { + final GroupStatisticsBuilder builder = new GroupStatisticsBuilder(); + return builder.build(); + } +} + diff --git a/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImplTest.java b/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImplTest.java new file mode 100644 index 0000000000..789f6ac5bf --- /dev/null +++ b/applications/old-notification-supplier/src/test/java/org/opendaylight/openflowplugin/applications/old/notification/supplier/impl/item/stat/MeterStatNotifSupplierImplTest.java @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ + +package org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.item.stat; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; +import static org.mockito.Mockito.verify; + +import java.util.HashMap; +import java.util.Map; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Matchers; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.sal.binding.api.NotificationProviderService; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.helper.TestChangeEventBuildHelper; +import org.opendaylight.openflowplugin.applications.old.notification.supplier.impl.helper.TestSupplierVerifyHelper; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.Meter; +import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.meters.MeterKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; +import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.MeterStatisticsUpdated; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.NodeMeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatistics; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.statistics.rev131111.nodes.node.meter.MeterStatisticsBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterId; +import org.opendaylight.yangtools.yang.binding.DataObject; +import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; + +public class MeterStatNotifSupplierImplTest { + + private static final String FLOW_NODE_ID = "test-111"; + private static final Long FLOW_METER_ID = 111L; + private MeterStatNotifSupplierImpl notifSupplierImpl; + private NotificationProviderService notifProviderService; + private DataBroker dataBroker; + + @Before + public void initalization() { + notifProviderService = mock(NotificationProviderService.class); + dataBroker = mock(DataBroker.class); + notifSupplierImpl = new MeterStatNotifSupplierImpl(notifProviderService, dataBroker); + TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker); + } + + @Test(expected = IllegalArgumentException.class) + public void testNullChangeEvent() { + notifSupplierImpl.onDataChanged(null); + } + + @Test + public void testNullableChangeEvent() { + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent()); + } + + @Test + public void testEmptyChangeEvent() { + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent()); + } + + @Test + public void testCreate() { + final MeterStatisticsUpdated notification = notifSupplierImpl.createNotification(createTestMeterStat(), + createTestMeterStatPath()); + assertNotNull(notification); + assertEquals(FLOW_NODE_ID, notification.getId().getValue()); + } + + @Test + public void testCreateChangeEvent() { + final Map, DataObject> createdData = new HashMap<>(); + createdData.put(createTestMeterStatPath(), createTestMeterStat()); + notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null)); + verify(notifProviderService, times(1)).publish(Matchers.any(MeterStatisticsUpdated.class)); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFromNullNodeConnector() { + notifSupplierImpl.createNotification(null, createTestMeterStatPath()); + } + + @Test(expected = IllegalArgumentException.class) + public void testCreateFromNullPath() { + notifSupplierImpl.createNotification(createTestMeterStat(), null); + } + + @Test(expected = IllegalArgumentException.class) + public void testUpdateFromNullNodeConnector() { + notifSupplierImpl.createNotification(null, createTestMeterStatPath()); + } + + @Test(expected = IllegalArgumentException.class) + public void testUpdateFromNullPath() { + notifSupplierImpl.createNotification(createTestMeterStat(), null); + } + + private static InstanceIdentifier createTestMeterStatPath() { + return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID))) + .augmentation(FlowCapableNode.class).child(Meter.class, new MeterKey(new MeterId(FLOW_METER_ID))) + .augmentation(NodeMeterStatistics.class).child(MeterStatistics.class); + } + + private static MeterStatistics createTestMeterStat() { + final MeterStatisticsBuilder builder = new MeterStatisticsBuilder(); + return builder.build(); + } +} + -- 2.36.6