Fix fileEncoding violations for checkstyle
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / statistics / SflowClientSettingsListenerTest.java
1 /*
2  * Copyright (c) 2016 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.groupbasedpolicy.renderer.ofoverlay.statistics;
10
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;
16
17 import java.util.Set;
18 import java.util.concurrent.ScheduledExecutorService;
19
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;
32
33 public class SflowClientSettingsListenerTest {
34
35     private SflowClientSettingsListener listener;
36     private DataObjectModification<SflowClientSettings> rootNode;
37     private Set<DataTreeModification<SflowClientSettings>> changes;
38
39     private InstanceIdentifier<SflowClientSettings> rootIdentifier;
40
41     @SuppressWarnings("unchecked")
42     @Before
43     public void init() {
44         DataBroker dataProvider = mock(DataBroker.class);
45
46         StatisticsManager ofStatisticsManager = mock(StatisticsManager.class);
47         ScheduledExecutorService executor = mock(ScheduledExecutorService.class);
48         listener = spy(new SflowClientSettingsListener(dataProvider, executor, ofStatisticsManager));
49
50         SflowClientSettings sflowClientSettings = mock(SflowClientSettings.class);
51
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);
56
57         DataTreeModification<SflowClientSettings> change = mock(DataTreeModification.class);
58
59         when(change.getRootNode()).thenReturn(rootNode);
60         when(change.getRootPath()).thenReturn(rootPath);
61
62         changes = ImmutableSet.of(change);
63
64         when(rootNode.getDataBefore()).thenReturn(sflowClientSettings);
65         when(rootNode.getDataAfter()).thenReturn(sflowClientSettings);
66     }
67
68     @Test
69     public void testOnWrite() {
70         when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.WRITE);
71
72         listener.onDataTreeChanged(changes);
73
74         verify(listener).onWrite(rootNode, rootIdentifier);
75     }
76
77     @Test
78     public void testOnDelete() {
79         when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.DELETE);
80
81         listener.onDataTreeChanged(changes);
82
83         verify(listener).onDelete(rootNode, rootIdentifier);
84     }
85
86     @Test
87     public void testOnSubtreeModified() {
88         when(rootNode.getModificationType()).thenReturn(DataObjectModification.ModificationType.SUBTREE_MODIFIED);
89
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);
95     }
96
97 }