2 * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
\r
4 * This program and the accompanying materials are made available under the
\r
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
\r
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
\r
9 package org.opendaylight.openflowjava.protocol.impl.connection;
\r
11 import static org.junit.Assert.fail;
\r
13 import java.util.Collections;
\r
14 import java.util.concurrent.ExecutionException;
\r
16 import org.junit.Assert;
\r
17 import org.junit.Test;
\r
18 import org.opendaylight.controller.sal.common.util.Rpcs;
\r
19 import org.opendaylight.yangtools.yang.common.RpcError;
\r
20 import org.opendaylight.yangtools.yang.common.RpcResult;
\r
22 import com.google.common.util.concurrent.SettableFuture;
\r
25 * @author michal.polkorab
\r
28 public class SimpleRpcListenerTest {
\r
31 * Test SimpleRpcListener creation
\r
34 public void test() {
\r
35 SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
\r
36 Assert.assertEquals("Wrong message", "MESSAGE", listener.takeMessage());
\r
37 Assert.assertEquals("Wrong message", listener, listener.takeListener());
\r
44 public void testSuccessfulRpc() {
\r
45 SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
\r
46 listener.operationSuccessful();
\r
47 SettableFuture<RpcResult<?>> result = SettableFuture.create();
\r
48 result.set(Rpcs.getRpcResult(true, null, Collections.<RpcError>emptyList()));
\r
50 Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());
\r
51 Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());
\r
52 Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());
\r
53 } catch (InterruptedException | ExecutionException e) {
\r
54 fail("Problem accessing result");
\r