2 * Copyright (c) 2016 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
8 package org.opendaylight.openflowplugin.applications.frsync.impl;
10 import org.junit.Before;
11 import org.junit.Test;
12 import org.junit.runner.RunWith;
13 import org.mockito.Matchers;
14 import org.mockito.Mock;
15 import org.mockito.Mockito;
16 import org.mockito.invocation.InvocationOnMock;
17 import org.mockito.runners.MockitoJUnitRunner;
18 import org.mockito.stubbing.Answer;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.DataTreeChangeListener;
21 import org.opendaylight.controller.md.sal.binding.api.DataTreeIdentifier;
22 import org.opendaylight.controller.sal.binding.api.BindingAwareBroker;
23 import org.opendaylight.controller.sal.binding.api.RpcConsumerRegistry;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.transaction.rev150304.FlowCapableTransactionService;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.table.service.rev131026.SalTableService;
30 import org.opendaylight.yangtools.yang.binding.RpcService;
33 * Test for {@link ForwardingRulesSyncProvider}.
35 @RunWith(MockitoJUnitRunner.class)
36 public class ForwardingRulesSyncProviderTest {
38 private ForwardingRulesSyncProvider provider;
40 private DataBroker dataBroker;
42 private RpcConsumerRegistry rpcRegistry;
44 private BindingAwareBroker broker;
46 private BindingAwareBroker.ProviderContext providerContext;
49 public void setUp() throws Exception {
50 Mockito.when(rpcRegistry.getRpcService(Matchers.<Class<? extends RpcService>>any()))
51 .thenAnswer(new Answer<RpcService>() {
53 public RpcService answer(final InvocationOnMock invocation) throws Throwable {
54 Class<? extends RpcService> serviceType = (Class<? extends RpcService>) invocation.getArguments()[0];
55 return Mockito.mock(serviceType);
59 provider = new ForwardingRulesSyncProvider(broker, dataBroker, rpcRegistry);
61 Mockito.verify(rpcRegistry).getRpcService(SalFlowService.class);
62 Mockito.verify(rpcRegistry).getRpcService(SalGroupService.class);
63 Mockito.verify(rpcRegistry).getRpcService(SalMeterService.class);
64 Mockito.verify(rpcRegistry).getRpcService(SalTableService.class);
65 Mockito.verify(rpcRegistry).getRpcService(FlowCapableTransactionService.class);
67 Mockito.verify(broker).registerProvider(provider);
71 public void testOnSessionInitiated() throws Exception {
72 provider.onSessionInitiated(providerContext);
74 Mockito.verify(dataBroker, Mockito.times(2)).registerDataTreeChangeListener(
75 Matchers.<DataTreeIdentifier<FlowCapableNode>>any(),
76 Matchers.<DataTreeChangeListener<FlowCapableNode>>any());