2 * Copyright (c) 2016 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.groupbasedpolicy.renderer.ofoverlay.statistics;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.spy;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15 import static org.mockito.Mockito.when;
18 import java.util.concurrent.ScheduledExecutorService;
20 import com.google.common.collect.ImmutableSet;
21 import org.junit.Before;
22 import org.junit.Test;
23 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
24 import org.opendaylight.controller.md.sal.binding.api.DataObjectModification;
25 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
26 import org.opendaylight.controller.md.sal.binding.api.DataTreeModification;
27 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
28 import org.opendaylight.groupbasedpolicy.api.StatisticsManager;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.OfOverlayConfig;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.ofoverlay.rev140528.sflow.values.SflowClientSettings;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 public class SflowClientSettingsListenerTest {
35 private SflowClientSettingsListener listener;
36 private DataObjectModification<SflowClientSettings> rootNode;
37 private Set<DataTreeModification<SflowClientSettings>> changes;
39 private InstanceIdentifier<SflowClientSettings> rootIdentifier;
41 @SuppressWarnings("unchecked")
44 DataBroker dataProvider = mock(DataBroker.class);
46 StatisticsManager ofStatisticsManager = mock(StatisticsManager.class);
47 ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
48 listener = spy(new SflowClientSettingsListener(dataProvider, executor, ofStatisticsManager));
50 SflowClientSettings sflowClientSettings = mock(SflowClientSettings.class);
52 rootNode = mock(DataObjectModification.class);
53 rootIdentifier = InstanceIdentifier.builder(OfOverlayConfig.class).child(SflowClientSettings.class).build();
54 DataTreeIdentifier<SflowClientSettings> rootPath =
55 new DataTreeIdentifier<>(LogicalDatastoreType.CONFIGURATION, rootIdentifier);
57 DataTreeModification<SflowClientSettings> change = mock(DataTreeModification.class);
59 when(change.getRootNode()).thenReturn(rootNode);
60 when(change.getRootPath()).thenReturn(rootPath);
62 changes = ImmutableSet.of(change);
64 when(rootNode.getDataBefore()).thenReturn(sflowClientSettings);
65 when(rootNode.getDataAfter()).thenReturn(sflowClientSettings);
69 public void testOnWrite() {
70 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
72 listener.onDataTreeChanged(changes);
74 verify(listener).onWrite(rootNode, rootIdentifier);
78 public void testOnDelete() {
79 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
81 listener.onDataTreeChanged(changes);
83 verify(listener).onDelete(rootNode, rootIdentifier);
87 public void testOnSubtreeModified() {
88 when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
90 // first call will initialize uninitialized dependencies;
91 // second call will call #close on them
92 listener.onDataTreeChanged(changes);
93 listener.onDataTreeChanged(changes);
94 verify(listener, times(2)).onSubtreeModified(rootNode, rootIdentifier);