2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.statistics;
\r
11 import static org.mockito.Mockito.mock;
\r
12 import static org.mockito.Mockito.spy;
\r
13 import static org.mockito.Mockito.times;
\r
14 import static org.mockito.Mockito.verify;
\r
15 import static org.mockito.Mockito.when;
\r
17 import java.util.Set;
\r
18 import java.util.concurrent.ScheduledExecutorService;
\r
20 import com.google.common.collect.ImmutableSet;
\r
21 import org.junit.Before;
\r
22 import org.junit.Test;
\r
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
\r
24 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
\r
25 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
\r
26 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
\r
27 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
\r
28 import org.opendaylight.groupbasedpolicy.api.StatisticsManager;
\r
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig;
\r
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.sflow.values.SflowClientSettings;
\r
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
\r
33 public class SflowClientSettingsListenerTest {
\r
35 private SflowClientSettingsListener listener;
\r
36 private DataObjectModification<SflowClientSettings> rootNode;
\r
37 private Set<DataTreeModification<SflowClientSettings>> changes;
\r
39 private InstanceIdentifier<SflowClientSettings> rootIdentifier;
\r
41 @SuppressWarnings("unchecked")
\r
43 public void init() {
\r
44 DataBroker dataProvider = mock(DataBroker.class);
\r
46 StatisticsManager ofStatisticsManager = mock(StatisticsManager.class);
\r
47 ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
\r
48 listener = spy(new SflowClientSettingsListener(dataProvider, executor, ofStatisticsManager));
\r
50 SflowClientSettings sflowClientSettings = mock(SflowClientSettings.class);
\r
52 rootNode = mock(DataObjectModification.class);
\r
53 rootIdentifier = InstanceIdentifier.builder(OfOverlayConfig.class).child(SflowClientSettings.class).build();
\r
54 DataTreeIdentifier<SflowClientSettings> rootPath =
\r
55 new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
\r
57 DataTreeModification<SflowClientSettings> change = mock(DataTreeModification.class);
\r
59 when(change.getRootNode()).thenReturn(rootNode);
\r
60 when(change.getRootPath()).thenReturn(rootPath);
\r
62 changes = ImmutableSet.of(change);
\r
64 when(rootNode.getDataBefore()).thenReturn(sflowClientSettings);
\r
65 when(rootNode.getDataAfter()).thenReturn(sflowClientSettings);
\r
69 public void testOnWrite() {
\r
70 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
\r
72 listener.onDataTreeChanged(changes);
\r
74 verify(listener).onWrite(rootNode, rootIdentifier);
\r
78 public void testOnDelete() {
\r
79 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
\r
81 listener.onDataTreeChanged(changes);
\r
83 verify(listener).onDelete(rootNode, rootIdentifier);
\r
87 public void testOnSubtreeModified() {
\r
88 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
\r
90 // first call will initialize uninitialized dependencies;
\r
91 // second call will call #close on them
\r
92 listener.onDataTreeChanged(changes);
\r
93 listener.onDataTreeChanged(changes);
\r
94 verify(listener, times(2)).onSubtreeModified(rootNode, rootIdentifier);
\r