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.controller.md.sal.binding.api.DataBroker;
23 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
24 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
25 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
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.FlowCapableNode;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.GroupStatisticsUpdated;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
38 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
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.yangtools.yang.binding.InstanceIdentifier;
43 public class GroupStatNotificationSupplierImplTest {
45 private static final String FLOW_NODE_ID = "openflow:111";
46 private static final Long FLOW_TABLE_ID = 111L;
47 private GroupStatNotificationSupplierImpl notifSupplierImpl;
48 private NotificationProviderService notifProviderService;
49 private DataBroker dataBroker;
52 public void initalization() {
53 notifProviderService = mock(NotificationProviderService.class);
54 dataBroker = mock(DataBroker.class);
55 notifSupplierImpl = new GroupStatNotificationSupplierImpl(notifProviderService, dataBroker);
56 TestSupplierVerifyHelper.verifyDataTreeChangeListenerRegistration(dataBroker);
59 @Test(expected = NullPointerException.class)
60 public void testNullChangeEvent() {
61 notifSupplierImpl.onDataTreeChanged(null);
64 @Test(expected = NullPointerException.class)
65 public void testNullableChangeEvent() {
66 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createNullTestDataTreeEvent());
70 public void testEmptyChangeEvent() {
71 notifSupplierImpl.onDataTreeChanged(TestChangeEventBuildHelper.createEmptyTestDataTreeEvent());
75 public void testCreate() {
76 final GroupStatisticsUpdated notification = notifSupplierImpl
77 .createNotification(createTestGroupStat(), createTestGroupStatPath());
78 assertNotNull(notification);
79 assertEquals(FLOW_NODE_ID, notification.getId().getValue());
83 public void testCreateChangeEvent() {
84 final TestData testData = new TestData(createTestGroupStatPath(), null, createTestGroupStat(),
85 DataObjectModification.ModificationType.WRITE);
86 Collection<DataTreeModification<GroupStatistics>> collection = new ArrayList<>();
87 collection.add(testData);
88 notifSupplierImpl.onDataTreeChanged(collection);
89 verify(notifProviderService, times(1)).publish(any(GroupStatisticsUpdated.class));
92 @Test(expected = IllegalArgumentException.class)
93 public void testCreateFromNullNodeConnector() {
94 notifSupplierImpl.createNotification(null, createTestGroupStatPath());
97 @Test(expected = IllegalArgumentException.class)
98 public void testCreateFromNullPath() {
99 notifSupplierImpl.createNotification(createTestGroupStat(), null);
102 @Test(expected = IllegalArgumentException.class)
103 public void testUpdateFromNullNodeConnector() {
104 notifSupplierImpl.createNotification(null, createTestGroupStatPath());
107 @Test(expected = IllegalArgumentException.class)
108 public void testUpdateFromNullPath() {
109 notifSupplierImpl.createNotification(createTestGroupStat(), null);
112 private static InstanceIdentifier<GroupStatistics> createTestGroupStatPath() {
113 return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID)))
114 .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(FLOW_TABLE_ID)))
115 .augmentation(NodeGroupStatistics.class).child(GroupStatistics.class);
118 private static GroupStatistics createTestGroupStat() {
119 final GroupStatisticsBuilder builder = new GroupStatisticsBuilder();
120 return builder.build();