OPNFLWPLUG-858/Bug 7826
[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.stubbing.Answer;
15 import org.opendaylight.controller.md.sal.binding.api.NotificationPublishService;
16 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
17 import org.opendaylight.openflowplugin.api.openflow.statistics.ofpspecific.EventIdentifier;
18 import org.opendaylight.openflowplugin.impl.rpc.AbstractRequestContext;
19 import org.opendaylight.yangtools.yang.common.RpcResult;
20
21 public abstract class AbstractSingleStatsServiceTest extends AbstractStatsServiceTest {
22
23     @Mock
24     protected NotificationPublishService notificationPublishService;
25
26     protected RequestContext<Object> rqContext;
27
28     protected RpcResult<Object> rpcResult;
29
30     @Override
31     public void init() throws Exception {
32         super.init();
33         rqContext = new AbstractRequestContext<Object>(42L) {
34             @Override
35             public void close() {
36                 //NOOP
37             }
38         };
39         final Answer closeRequestFutureAnswer = invocation -> {
40             rqContext.setResult(rpcResult);
41             rqContext.close();
42             return null;
43         };
44
45         Mockito.when(rqContextStack.<Object>createRequestContext()).thenReturn(rqContext);
46         Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector).endCollecting(null);
47         Mockito.doAnswer(closeRequestFutureAnswer).when(multiMsgCollector)
48                 .endCollecting(Matchers.any(EventIdentifier.class));
49     }
50 }