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.groupbasedpolicy.resolver.PolicyResolver;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.groupbasedpolicy.policy.rev140421.tenants.tenant.subject.feature.instances.ActionInstance;
32 import org.opendaylight.yangtools.concepts.ListenerRegistration;
33 import org.opendaylight.yangtools.yang.binding.DataObject;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
36 public class SfcManagerTest {
38 private SfcManager manager;
40 private DataBroker dataBroker;
41 private PolicyResolver policyResolver;
42 private RpcProviderRegistry rpcRegistry;
43 private ExecutorService executor;
44 private ListenerRegistration<DataChangeListener> actionListener;
46 private AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> actionInstanceNotification;
47 private InstanceIdentifier<DataObject> pathIdentifier;
48 private ActionInstance dataObject;
49 private HashMap<InstanceIdentifier<?>, DataObject> dataMap;
50 private Set<InstanceIdentifier<?>> dataSet;
52 @SuppressWarnings("unchecked")
54 public void initialise() {
55 dataBroker = mock(DataBroker.class);
56 policyResolver = mock(PolicyResolver.class);
57 rpcRegistry = mock(RpcProviderRegistry.class);
58 executor = mock(ExecutorService.class);
59 actionListener = mock(ListenerRegistration.class);
60 actionInstanceNotification = mock(AsyncDataChangeEvent.class);
61 pathIdentifier = mock(InstanceIdentifier.class);
62 dataObject = mock(ActionInstance.class);
65 dataBroker.registerDataChangeListener(any(LogicalDatastoreType.class), any(InstanceIdentifier.class),
66 any(DataChangeListener.class), any(DataChangeScope.class))).thenReturn(actionListener);
67 dataMap = new HashMap<InstanceIdentifier<?>, DataObject>();
68 dataMap.put(pathIdentifier, dataObject);
69 dataSet = new HashSet<InstanceIdentifier<?>>(Arrays.asList(pathIdentifier));
71 manager = new SfcManager(dataBroker, policyResolver, rpcRegistry, executor);
75 public void constructorTest() throws Exception {
77 verify(actionListener).close();
81 public void onDataChangedTestAdd() {
82 when(actionInstanceNotification.getCreatedData()).thenReturn(dataMap);
83 manager.onDataChanged(actionInstanceNotification);
84 verify(executor).execute(any(Runnable.class));
88 public void onDataChangedTestDelete() {
89 when(actionInstanceNotification.getRemovedPaths()).thenReturn(dataSet);
90 when(actionInstanceNotification.getOriginalData()).thenReturn(dataMap);
91 manager.onDataChanged(actionInstanceNotification);
92 verify(executor).execute(any(Runnable.class));
96 public void onDataChangedTestChange() {
97 when(actionInstanceNotification.getOriginalData()).thenReturn(dataMap);
98 when(actionInstanceNotification.getUpdatedData()).thenReturn(dataMap);
99 manager.onDataChanged(actionInstanceNotification);
100 verify(executor).execute(any(Runnable.class));