2 * Copyright (c) 2015 Pantheon Technologies s.r.o. 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
8 package org.opendaylight.groupbasedpolicy.renderer.ofoverlay.endpoint;
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;
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;
27 public class EndpointManagerListenerTest {
29 private InstanceIdentifier<DataObject> endpointId;
30 private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> change;
31 private EndpointManager endpointManager;
32 private DataChangeListenerTester tester;
34 @SuppressWarnings("unchecked")
37 endpointId = mock(InstanceIdentifier.class);
38 endpointManager = mock(EndpointManager.class);
39 DataBroker dataProvider = mock(DataBroker.class);
41 EndpointManagerListener endpointManagerListener = new EndpointManagerListener(dataProvider, endpointManager);
42 tester = new DataChangeListenerTester(endpointManagerListener);
43 tester.setRemovedPath(endpointId);
47 public void testOnDataChangeEndpoint() {
48 DataObject endpoint = mock(Endpoint.class);
49 tester.setDataObject(endpointId, endpoint);
51 tester.callOnDataChanged();
53 verify(endpointManager, times(3)).processEndpoint(any(Endpoint.class), any(Endpoint.class));
54 verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
58 public void testOnDataChangeEndpointL3() {
59 DataObject endpoint = mock(EndpointL3.class);
60 tester.setDataObject(endpointId, endpoint);
62 tester.callOnDataChanged();
64 verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
65 verify(endpointManager, times(3)).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));
69 public void testOnDataChangeEndpointL3Prefix() {
70 DataObject endpoint = mock(EndpointL3Prefix.class);
71 tester.setDataObject(endpointId, endpoint);
73 tester.callOnDataChanged();
75 verify(endpointManager, never()).processEndpoint(any(Endpoint.class), any(Endpoint.class));
76 verify(endpointManager, never()).processL3Endpoint(any(EndpointL3.class), any(EndpointL3.class));