2 * Copyright (c) 2014 Pantheon Technologies s.r.o. 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
9 package org.opendaylight.openflowjava.protocol.impl.core.connection;
11 import static org.junit.Assert.fail;
12 import static org.mockito.Mockito.times;
13 import static org.mockito.Mockito.verify;
14 import static org.mockito.Mockito.when;
15 import com.google.common.util.concurrent.SettableFuture;
16 import io.netty.util.concurrent.Future;
17 import java.util.concurrent.ExecutionException;
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.mockito.Mock;
22 import org.mockito.MockitoAnnotations;
23 import org.opendaylight.yangtools.yang.common.RpcResult;
24 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
27 * @author michal.polkorab
30 public class SimpleRpcListenerTest {
32 @Mock Future<Void> future;
38 public void startUp() {
39 MockitoAnnotations.initMocks(this);
43 * Test SimpleRpcListener creation
47 SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
48 Assert.assertEquals("Wrong message", "MESSAGE", listener.takeMessage());
49 Assert.assertEquals("Wrong message", listener, listener.takeListener());
56 public void testSuccessfulRpc() {
57 SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
58 listener.operationSuccessful();
59 SettableFuture<RpcResult<?>> result = SettableFuture.create();
60 result.set(RpcResultBuilder.success((Void)null).build());
62 Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());
63 Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());
64 Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());
65 } catch (InterruptedException | ExecutionException e) {
66 fail("Problem accessing result");
74 public void testOperationComplete() {
75 when(future.isSuccess()).thenReturn(false);
76 SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
77 listener.operationComplete(future);
78 verify(future, times(1)).cause();
80 Assert.assertEquals("Wrong result", 1, listener.getResult().get().getErrors().size());
81 } catch (InterruptedException | ExecutionException e) {
90 public void testOperationComplete2() {
91 when(future.isSuccess()).thenReturn(true);
92 SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
93 listener.operationComplete(future);
94 verify(future, times(0)).cause();
96 Assert.assertEquals("Wrong result", 0, listener.getResult().get().getErrors().size());
97 Assert.assertEquals("Wrong result", true, listener.getResult().get().isSuccessful());
98 } catch (InterruptedException | ExecutionException e) {