db9d689ea9a47e5256c4bacadae54a28e36ec96b
[openflowjava.git] / openflow-protocol-impl / src / test / java / org / opendaylight / openflowjava / protocol / impl / connection / SimpleRpcListenerTest.java
1 /*\r
2  * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
3  *\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
7  */\r
8 \r
9 package org.opendaylight.openflowjava.protocol.impl.connection;\r
10 \r
11 import static org.junit.Assert.fail;\r
12 \r
13 import java.util.Collections;\r
14 import java.util.concurrent.ExecutionException;\r
15 \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
21 \r
22 import com.google.common.util.concurrent.SettableFuture;\r
23 \r
24 /**\r
25  * @author michal.polkorab\r
26  *\r
27  */\r
28 public class SimpleRpcListenerTest {\r
29 \r
30     /**\r
31      * Test SimpleRpcListener creation\r
32      */\r
33     @Test\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
38     }\r
39 \r
40     /**\r
41      * Test rpc success\r
42      */\r
43     @Test\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
49         try {\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
55         }\r
56     }\r
57 }