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