OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / openflowplugin-impl / src / test / java / org / opendaylight / openflowplugin / impl / services / util / RequestContextUtilTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.services.util;
10
11 import static org.mockito.ArgumentMatchers.any;
12 import static org.mockito.Mockito.doThrow;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.verifyNoMoreInteractions;
15
16 import org.junit.After;
17 import org.junit.Test;
18 import org.junit.runner.RunWith;
19 import org.mockito.Mock;
20 import org.mockito.runners.MockitoJUnitRunner;
21 import org.opendaylight.openflowplugin.api.openflow.device.RequestContext;
22
23 @RunWith(MockitoJUnitRunner.class)
24 public class RequestContextUtilTest {
25     @Mock
26     private RequestContext<Void> requestContext;
27
28     @After
29     public void tearDown() throws Exception {
30         verifyNoMoreInteractions(requestContext);
31     }
32
33     @Test
34     public void closeRequestContextWithRpcError() throws Exception {
35         final String errorMessage = "Test error";
36         RequestContextUtil.closeRequestContextWithRpcError(
37                 requestContext,
38                 errorMessage);
39
40         verify(requestContext).setResult(any());
41         verify(requestContext).getFuture();
42         verify(requestContext).close();
43     }
44
45     @Test
46     public void closeRequestContext() throws Exception {
47         doThrow(new IllegalStateException()).when(requestContext).close();
48         RequestContextUtil.closeRequestContext(requestContext);
49         verify(requestContext).close();
50     }
51
52 }