2 * Copyright (c) 2015 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;
11 import static org.mockito.Matchers.any;
12 import static org.mockito.Mockito.mock;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
16 import java.util.Arrays;
17 import java.util.HashMap;
18 import java.util.HashSet;
20 import java.util.concurrent.ExecutorService;
22 import org.junit.Before;
23 import org.junit.Test;
24 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
25 import org.opendaylight.controller.md.sal.binding.api.DataChangeListener;
26 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
27 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
28 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
29 import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.policy.subject.feature.instances.ActionInstance;
31 import org.opendaylight.yangtools.concepts.ListenerRegistration;
32 import org.opendaylight.yangtools.yang.binding.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
35 public class SfcManagerTest {
37 private SfcManager manager;
39 private DataBroker dataBroker;
40 private RpcProviderRegistry rpcRegistry;
41 private ExecutorService executor;
42 private ListenerRegistration<DataChangeListener> actionListener;
44 private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> actionInstanceNotification;
45 private InstanceIdentifier<DataObject> pathIdentifier;
46 private ActionInstance dataObject;
47 private HashMap<InstanceIdentifier<?>, DataObject> dataMap;
48 private Set<InstanceIdentifier<?>> dataSet;
50 @SuppressWarnings("unchecked")
52 public void initialise() {
53 dataBroker = mock(DataBroker.class);
54 rpcRegistry = mock(RpcProviderRegistry.class);
55 executor = mock(ExecutorService.class);
56 actionListener = mock(ListenerRegistration.class);
57 actionInstanceNotification = mock(AsyncDataChangeEvent.class);
58 pathIdentifier = mock(InstanceIdentifier.class);
59 dataObject = mock(ActionInstance.class);
62 dataBroker.registerDataChangeListener(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
63 any(DataChangeListener.class), any(DataChangeScope.class))).thenReturn(actionListener);
64 dataMap = new HashMap<InstanceIdentifier<?>, DataObject>();
65 dataMap.put(pathIdentifier, dataObject);
66 dataSet = new HashSet<InstanceIdentifier<?>>(Arrays.asList(pathIdentifier));
68 manager = new SfcManager(dataBroker, rpcRegistry, executor);
72 public void constructorTest() throws Exception {
74 verify(actionListener).close();
78 public void onDataChangedTestAdd() {
79 when(actionInstanceNotification.getCreatedData()).thenReturn(dataMap);
80 manager.onDataChanged(actionInstanceNotification);
81 verify(executor).execute(any(Runnable.class));
85 public void onDataChangedTestDelete() {
86 when(actionInstanceNotification.getRemovedPaths()).thenReturn(dataSet);
87 when(actionInstanceNotification.getOriginalData()).thenReturn(dataMap);
88 manager.onDataChanged(actionInstanceNotification);
89 verify(executor).execute(any(Runnable.class));
93 public void onDataChangedTestChange() {
94 when(actionInstanceNotification.getOriginalData()).thenReturn(dataMap);
95 when(actionInstanceNotification.getUpdatedData()).thenReturn(dataMap);
96 manager.onDataChanged(actionInstanceNotification);
97 verify(executor).execute(any(Runnable.class));