-/*\r
- * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-\r
-package org.opendaylight.openflowjava.protocol.impl.core.connection;\r
-\r
-import static org.junit.Assert.fail;\r
-import static org.mockito.Mockito.times;\r
-import static org.mockito.Mockito.verify;\r
-import static org.mockito.Mockito.when;\r
-import io.netty.util.concurrent.Future;\r
-\r
-import java.util.Collections;\r
-import java.util.concurrent.ExecutionException;\r
-\r
-import org.junit.Assert;\r
-import org.junit.Before;\r
-import org.junit.Test;\r
-import org.mockito.Mock;\r
-import org.mockito.MockitoAnnotations;\r
-import org.opendaylight.controller.sal.common.util.Rpcs;\r
-import org.opendaylight.openflowjava.protocol.impl.core.connection.SimpleRpcListener;\r
-import org.opendaylight.yangtools.yang.common.RpcError;\r
-import org.opendaylight.yangtools.yang.common.RpcResult;\r
-\r
-import com.google.common.util.concurrent.SettableFuture;\r
-\r
-/**\r
- * @author michal.polkorab\r
- *\r
- */\r
-public class SimpleRpcListenerTest {\r
-\r
- @Mock Future<Void> future;\r
-\r
- /**\r
- * Initializes mocks\r
- */\r
- @Before\r
- public void startUp() {\r
- MockitoAnnotations.initMocks(this);\r
- }\r
-\r
- /**\r
- * Test SimpleRpcListener creation\r
- */\r
- @Test\r
- public void test() {\r
- SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");\r
- Assert.assertEquals("Wrong message", "MESSAGE", listener.takeMessage());\r
- Assert.assertEquals("Wrong message", listener, listener.takeListener());\r
- }\r
-\r
- /**\r
- * Test rpc success\r
- */\r
- @Test\r
- public void testSuccessfulRpc() {\r
- SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");\r
- listener.operationSuccessful();\r
- SettableFuture<RpcResult<?>> result = SettableFuture.create();\r
- result.set(Rpcs.getRpcResult(true, null, Collections.<RpcError>emptyList()));\r
- try {\r
- Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());\r
- Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());\r
- Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());\r
- } catch (InterruptedException | ExecutionException e) {\r
- fail("Problem accessing result");\r
- }\r
- }\r
-\r
- /**\r
- * Test rpc success\r
- */\r
- @Test\r
- public void testOperationComplete() {\r
- when(future.isSuccess()).thenReturn(false);\r
- SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");\r
- listener.operationComplete(future);\r
- verify(future, times(1)).cause();\r
- try {\r
- Assert.assertEquals("Wrong result", 1, listener.getResult().get().getErrors().size());\r
- } catch (InterruptedException | ExecutionException e) {\r
- Assert.fail();\r
- }\r
- }\r
-\r
- /**\r
- * Test rpc success\r
- */\r
- @Test\r
- public void testOperationComplete2() {\r
- when(future.isSuccess()).thenReturn(true);\r
- SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");\r
- listener.operationComplete(future);\r
- verify(future, times(0)).cause();\r
- try {\r
- Assert.assertEquals("Wrong result", 0, listener.getResult().get().getErrors().size());\r
- Assert.assertEquals("Wrong result", true, listener.getResult().get().isSuccessful());\r
- } catch (InterruptedException | ExecutionException e) {\r
- Assert.fail();\r
- }\r
- }\r
+/*
+ * Copyright (c) 2014 Pantheon Technologies s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+
+package org.opendaylight.openflowjava.protocol.impl.core.connection;
+
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+import io.netty.util.concurrent.Future;
+
+import java.util.Collections;
+import java.util.concurrent.ExecutionException;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.sal.common.util.Rpcs;
+import org.opendaylight.openflowjava.protocol.impl.core.connection.SimpleRpcListener;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+import com.google.common.util.concurrent.SettableFuture;
+
+/**
+ * @author michal.polkorab
+ *
+ */
+public class SimpleRpcListenerTest {
+
+ @Mock Future<Void> future;
+
+ /**
+ * Initializes mocks
+ */
+ @Before
+ public void startUp() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ /**
+ * Test SimpleRpcListener creation
+ */
+ @Test
+ public void test() {
+ SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
+ Assert.assertEquals("Wrong message", "MESSAGE", listener.takeMessage());
+ Assert.assertEquals("Wrong message", listener, listener.takeListener());
+ }
+
+ /**
+ * Test rpc success
+ */
+ @Test
+ public void testSuccessfulRpc() {
+ SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
+ listener.operationSuccessful();
+ SettableFuture<RpcResult<?>> result = SettableFuture.create();
+ result.set(Rpcs.getRpcResult(true, null, Collections.<RpcError>emptyList()));
+ try {
+ Assert.assertEquals("Wrong result", result.get().getErrors(), listener.getResult().get().getErrors());
+ Assert.assertEquals("Wrong result", result.get().getResult(), listener.getResult().get().getResult());
+ Assert.assertEquals("Wrong result", result.get().isSuccessful(), listener.getResult().get().isSuccessful());
+ } catch (InterruptedException | ExecutionException e) {
+ fail("Problem accessing result");
+ }
+ }
+
+ /**
+ * Test rpc success
+ */
+ @Test
+ public void testOperationComplete() {
+ when(future.isSuccess()).thenReturn(false);
+ SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
+ listener.operationComplete(future);
+ verify(future, times(1)).cause();
+ try {
+ Assert.assertEquals("Wrong result", 1, listener.getResult().get().getErrors().size());
+ } catch (InterruptedException | ExecutionException e) {
+ Assert.fail();
+ }
+ }
+
+ /**
+ * Test rpc success
+ */
+ @Test
+ public void testOperationComplete2() {
+ when(future.isSuccess()).thenReturn(true);
+ SimpleRpcListener listener = new SimpleRpcListener("MESSAGE", "Failed to send message");
+ listener.operationComplete(future);
+ verify(future, times(0)).cause();
+ try {
+ Assert.assertEquals("Wrong result", 0, listener.getResult().get().getErrors().size());
+ Assert.assertEquals("Wrong result", true, listener.getResult().get().isSuccessful());
+ } catch (InterruptedException | ExecutionException e) {
+ Assert.fail();
+ }
+ }
}
\ No newline at end of file