db2ecf1782bf436feb83aa27694bc169baea0fdc
[groupbasedpolicy.git] / renderers / ofoverlay / src / test / java / org / opendaylight / groupbasedpolicy / renderer / ofoverlay / endpoint / EndpointManagerListenerTest.java
1 /*
2  * Copyright (c) 2015 Pantheon Technologies s.r.o. 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 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
9
10 import static org.mockito.Matchers.any;
11 import static org.mockito.Mockito.mock;
12 import static org.mockito.Mockito.never;
13 import static org.mockito.Mockito.times;
14 import static org.mockito.Mockito.verify;
15
16 import org.junit.Before;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
19 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
20 import org.opendaylight.groupbasedpolicy.renderer.ofoverlay.test.DataChangeListenerTester;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.Endpoint;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.endpoint.rev140421.endpoints.EndpointL3Prefix;
24 import org.opendaylight.yangtools.yang.binding.DataObject;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 public class EndpointManagerListenerTest {
28
29     private InstanceIdentifier<DataObject> endpointId;
30     private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
31     private EndpointManager endpointManager;
32     private DataChangeListenerTester tester;
33
34     @SuppressWarnings("unchecked")
35     @Before
36     public void init() {
37         endpointId = mock(InstanceIdentifier.class);
38         endpointManager = mock(EndpointManager.class);
39         DataBroker dataProvider = mock(DataBroker.class);
40
41         EndpointManagerListener endpointManagerListener = new EndpointManagerListener(dataProvider, endpointManager);
42         tester = new DataChangeListenerTester(endpointManagerListener);
43         tester.setRemovedPath(endpointId);
44     }
45
46     @Test
47     public void testOnDataChangeEndpoint() {
48         DataObject endpoint = mock(Endpoint.class);
49         tester.setDataObject(endpointId, endpoint);
50
51         tester.callOnDataChanged();
52
53         verify(endpointManager, times(3)).processEndpoint(any(Endpoint.class), any(Endpoint.class));
54         verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
55     }
56
57     @Test
58     public void testOnDataChangeEndpointL3() {
59         DataObject endpoint = mock(EndpointL3.class);
60         tester.setDataObject(endpointId, endpoint);
61
62         tester.callOnDataChanged();
63
64         verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
65         verify(endpointManager, times(3)).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
66     }
67
68     @Test
69     public void testOnDataChangeEndpointL3Prefix() {
70         DataObject endpoint = mock(EndpointL3Prefix.class);
71         tester.setDataObject(endpointId, endpoint);
72
73         tester.callOnDataChanged();
74
75         verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
76         verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
77     }
78
79 }