1 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
3 import static org.mockito.Matchers.any;
4 import static org.mockito.Mockito.mock;
5 import static org.mockito.Mockito.never;
6 import static org.mockito.Mockito.times;
7 import static org.mockito.Mockito.verify;
8 import static org.mockito.Mockito.when;
10 import java.util.HashMap;
11 import java.util.HashSet;
15 import org.junit.Before;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25 public class EndpointManagerListenerTest {
27 private InstanceIdentifier<DataObject> endpointId;
28 private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
29 private EndpointManager endpointManager;
30 private EndpointManagerListener endpointManagerListener;
32 @SuppressWarnings("unchecked")
35 endpointId = mock(InstanceIdentifier.class);
36 change = mock(AsyncDataChangeEvent.class);
37 endpointManager = mock(EndpointManager.class);
38 endpointId = mock(InstanceIdentifier.class);
39 DataBroker dataProvider = mock(DataBroker.class);
40 endpointManagerListener = new EndpointManagerListener(dataProvider, endpointManager);
41 Set<InstanceIdentifier<?>> removedPaths = new HashSet<>();
42 removedPaths.add(endpointId);
43 when(change.getRemovedPaths()).thenReturn(removedPaths);
47 public void testOnDataChangeEndpoint() {
48 DataObject endpoint = mock(Endpoint.class);
50 Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
51 testData.put(endpointId, endpoint);
52 when(change.getCreatedData()).thenReturn(testData);
53 when(change.getOriginalData()).thenReturn(testData);
54 when(change.getUpdatedData()).thenReturn(testData);
56 endpointManagerListener.onDataChanged(change);
57 verify(endpointManager, times(3)).processEndpoint(any(Endpoint.class), any(Endpoint.class));
58 verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
62 public void testOnDataChangeEndpointL3() {
63 DataObject endpoint = mock(EndpointL3.class);
64 Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
65 testData.put(endpointId, endpoint);
67 when(change.getCreatedData()).thenReturn(testData);
68 when(change.getOriginalData()).thenReturn(testData);
69 when(change.getUpdatedData()).thenReturn(testData);
71 endpointManagerListener.onDataChanged(change);
72 verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
73 verify(endpointManager, times(3)).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
77 public void testOnDataChangeEndpointL3Prefix() {
78 DataObject endpoint = mock(EndpointL3Prefix.class);
79 Map<InstanceIdentifier<?>, DataObject> testData = new HashMap<>();
80 testData.put(endpointId, endpoint);
82 when(change.getCreatedData()).thenReturn(testData);
83 when(change.getOriginalData()).thenReturn(testData);
84 when(change.getUpdatedData()).thenReturn(testData);
86 endpointManagerListener.onDataChanged(change);
87 verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
88 verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));