Merge "BUG-4062: Flows,Groups,Meters not getting deleted during switch flap"
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / statistics / services / AbstractSingleStatsServiceTest.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. 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
9 package org.opendaylight.openflowplugin.impl.statistics.services;
10
11 import org.mockito.Matchers;
12 import org.mockito.Mock;
13 import org.mockito.Mockito;
14 import org.mockito.invocation.InvocationOnMock;
15 import org.mockito.stubbing.Answer;
16 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
17 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
18 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
19 import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
20 import org.opendaylight.yangtools.yang.common.RpcResult;
21
22 /**
23  * Created by mirehak on 9/9/15.
24  */
25 public abstract class AbstractSingleStatsServiceTest extends AbstractStatsServiceTest {
26
27     @Mock
28     protected NotificationPublishService notificationPublishService;
29
30     protected RequestContext<Object> rqContext;
31
32     protected RpcResult<Object> rpcResult;
33
34     @Override
35     public void init() throws Exception {
36         super.init();
37         rqContext = new AbstractRequestContext<Object>(42L) {
38             @Override
39             public void close() {
40                 //NOOP
41             }
42         };
43         final Answer closeRequestFutureAnswer = new Answer() {
44             @Override
45             public Void answer(InvocationOnMock invocation) throws Throwable {
46                 rqContext.setResult(rpcResult);
47                 rqContext.close();
48                 return null;
49             }
50         };
51
52         Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
53         Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting();
54         Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(Matchers.any(EventIdentifier.class));
55     }
56 }