BUG-4117: notification supplier - rename
[openflowplugin.git] / applications / notification-supplier / src / test / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / item / stat / GroupStatNotificationSupplierImplTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.openflowplugin.applications.notification.supplier.impl.item.stat;
10
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;
16
17 import java.util.HashMap;
18 import java.util.Map;
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.group.statistics.rev131111.GroupStatisticsUpdated;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.NodeGroupStatistics;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatistics;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.statistics.rev131111.group.statistics.GroupStatisticsBuilder;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupId;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.GroupKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
37 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
38 import org.opendaylight.yangtools.yang.binding.DataObject;
39 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
40
41 public class GroupStatNotificationSupplierImplTest {
42
43     private static final String FLOW_NODE_ID = "test-111";
44     private static final Long FLOW_TABLE_ID = 111L;
45     private GroupStatNotificationSupplierImpl notifSupplierImpl;
46     private NotificationProviderService notifProviderService;
47     private DataBroker dataBroker;
48
49     @Before
50     public void initalization() {
51         notifProviderService = mock(NotificationProviderService.class);
52         dataBroker = mock(DataBroker.class);
53         notifSupplierImpl = new GroupStatNotificationSupplierImpl(notifProviderService, dataBroker);
54         TestSupplierVerifyHelper.verifyDataChangeRegistration(dataBroker);
55     }
56
57     @Test(expected = IllegalArgumentException.class)
58     public void testNullChangeEvent() {
59         notifSupplierImpl.onDataChanged(null);
60     }
61
62     @Test
63     public void testNullableChangeEvent() {
64         notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
65     }
66
67     @Test
68     public void testEmptyChangeEvent() {
69         notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createEmptyTestDataEvent());
70     }
71
72     @Test
73     public void testCreate() {
74         final GroupStatisticsUpdated notification = notifSupplierImpl.createNotification(createTestGroupStat(),
75                 createTestGroupStatPath());
76         assertNotNull(notification);
77         assertEquals(FLOW_NODE_ID, notification.getId().getValue());
78     }
79
80     @Test
81     public void testCreateChangeEvent() {
82         final Map<InstanceIdentifier<?>, DataObject> createdData = new HashMap<>();
83         createdData.put(createTestGroupStatPath(), createTestGroupStat());
84         notifSupplierImpl.onDataChanged(TestChangeEventBuildHelper.createTestDataEvent(createdData, null, null));
85         verify(notifProviderService, times(1)).publish(Matchers.any(GroupStatisticsUpdated.class));
86     }
87
88     @Test(expected = IllegalArgumentException.class)
89     public void testCreateFromNullNodeConnector() {
90         notifSupplierImpl.createNotification(null, createTestGroupStatPath());
91     }
92
93     @Test(expected = IllegalArgumentException.class)
94     public void testCreateFromNullPath() {
95         notifSupplierImpl.createNotification(createTestGroupStat(), null);
96     }
97
98     @Test(expected = IllegalArgumentException.class)
99     public void testUpdateFromNullNodeConnector() {
100         notifSupplierImpl.createNotification(null, createTestGroupStatPath());
101     }
102
103     @Test(expected = IllegalArgumentException.class)
104     public void testUpdateFromNullPath() {
105         notifSupplierImpl.createNotification(createTestGroupStat(), null);
106     }
107
108     private static InstanceIdentifier<GroupStatistics> createTestGroupStatPath() {
109         return InstanceIdentifier.create(Nodes.class).child(Node.class, new NodeKey(new NodeId(FLOW_NODE_ID)))
110                 .augmentation(FlowCapableNode.class).child(Group.class, new GroupKey(new GroupId(FLOW_TABLE_ID)))
111                 .augmentation(NodeGroupStatistics.class).child(GroupStatistics.class);
112     }
113
114     private static GroupStatistics createTestGroupStat() {
115         final GroupStatisticsBuilder builder = new GroupStatisticsBuilder();
116         return builder.build();
117     }
118 }
119