RemoteRpcProviderFactory and RpcErrorsException unit tests 03/54303/14
authormatus.kubica <matus.kubica@pantheon.tech>
Tue, 4 Apr 2017 12:04:04 +0000 (14:04 +0200)
committerTom Pantelis <tompantelis@gmail.com>
Sun, 16 Apr 2017 14:00:28 +0000 (14:00 +0000)
Change-Id: Ife8c638d43810baede654cccac22fa8efccae1d0
Signed-off-by: matus.kubica <matus.kubica@pantheon.tech>
Signed-off-by: Ivan Hrasko <ivan.hrasko@pantheon.tech>
opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactoryTest.java [new file with mode: 0644]
opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RpcErrorsExceptionTest.java [new file with mode: 0644]

diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactoryTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RemoteRpcProviderFactoryTest.java
new file mode 100644 (file)
index 0000000..14e0cae
--- /dev/null
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 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.controller.remote.rpc;
+
+import static org.mockito.MockitoAnnotations.initMocks;
+
+import akka.actor.ActorSystem;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcProviderService;
+import org.opendaylight.controller.md.sal.dom.api.DOMRpcService;
+
+public class RemoteRpcProviderFactoryTest {
+
+    @Mock
+    private DOMRpcProviderService providerService;
+    @Mock
+    private DOMRpcService rpcService;
+    @Mock
+    private ActorSystem actorSystem;
+    @Mock
+    private RemoteRpcProviderConfig providerConfig;
+
+    @Before
+    public void setUp() throws Exception {
+        initMocks(this);
+    }
+
+    @Test
+    public void testCreateInstance() throws Exception {
+        Assert.assertNotNull(RemoteRpcProviderFactory
+                .createInstance(providerService, rpcService, actorSystem, providerConfig));
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testCreateInstanceMissingProvideService() throws Exception {
+        RemoteRpcProviderFactory.createInstance(null, rpcService, actorSystem, providerConfig);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testCreateInstanceMissingRpcService() throws Exception {
+        RemoteRpcProviderFactory.createInstance(providerService, null, actorSystem, providerConfig);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testCreateInstanceMissingActorSystem() throws Exception {
+        RemoteRpcProviderFactory.createInstance(providerService, rpcService, null, providerConfig);
+    }
+
+    @Test(expected = NullPointerException.class)
+    public void testCreateInstanceMissingProviderConfig() throws Exception {
+        RemoteRpcProviderFactory.createInstance(providerService, rpcService, actorSystem, null);
+    }
+}
\ No newline at end of file
diff --git a/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RpcErrorsExceptionTest.java b/opendaylight/md-sal/sal-remoterpc-connector/src/test/java/org/opendaylight/controller/remote/rpc/RpcErrorsExceptionTest.java
new file mode 100644 (file)
index 0000000..6735d37
--- /dev/null
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2017 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.controller.remote.rpc;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.RpcError;
+import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
+
+public class RpcErrorsExceptionTest {
+    private static final String ERROR_MESSAGE = "Test error message.";
+
+    private List<RpcError> rpcErrors;
+    private RpcErrorsException exception;
+
+    @Before
+    public void setUp() throws Exception {
+        final RpcError rpcError = RpcResultBuilder.newError(
+                RpcError.ErrorType.RPC, "error", "error message");
+        final RpcError rpcWarning = RpcResultBuilder.newWarning(
+                RpcError.ErrorType.RPC, "warning", "warning message");
+
+        rpcErrors = new ArrayList<>();
+        rpcErrors.add(rpcError);
+        rpcErrors.add(rpcWarning);
+
+        exception = new RpcErrorsException(ERROR_MESSAGE, rpcErrors);
+    }
+
+    @Test
+    public void testGetMessage() {
+        Assert.assertEquals(ERROR_MESSAGE, exception.getMessage());
+    }
+
+    @Test
+    public void testGetRpcErrors() throws Exception {
+        final List<RpcError> actualErrors = (List<RpcError>) exception.getRpcErrors();
+        Assert.assertEquals(rpcErrors.size(), actualErrors.size());
+
+        for (int i = 0; i < actualErrors.size(); i++) {
+            Assert.assertEquals(rpcErrors.get(i).getApplicationTag(), actualErrors.get(i).getApplicationTag());
+            Assert.assertEquals(rpcErrors.get(i).getSeverity(), actualErrors.get(i).getSeverity());
+            Assert.assertEquals(rpcErrors.get(i).getMessage(), actualErrors.get(i).getMessage());
+            Assert.assertEquals(rpcErrors.get(i).getErrorType(), actualErrors.get(i).getErrorType());
+            Assert.assertEquals(rpcErrors.get(i).getCause(), actualErrors.get(i).getCause());
+            Assert.assertEquals(rpcErrors.get(i).getInfo(), actualErrors.get(i).getInfo());
+            Assert.assertEquals(rpcErrors.get(i).getTag(), actualErrors.get(i).getTag());
+        }
+    }
+}
\ No newline at end of file