Add support for reusable streaming
[controller.git] / opendaylight / md-sal / sal-remoterpc-connector / src / test / java / org / opendaylight / controller / remote / rpc / RpcErrorsExceptionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.remote.rpc;
9
10 import java.util.ArrayList;
11 import java.util.List;
12 import org.junit.Assert;
13 import org.junit.Before;
14 import org.junit.Test;
15 import org.opendaylight.yangtools.yang.common.RpcError;
16 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
17
18 public class RpcErrorsExceptionTest {
19     private static final String ERROR_MESSAGE = "Test error message.";
20
21     private List<RpcError> rpcErrors;
22     private RpcErrorsException exception;
23
24     @Before
25     public void setUp() {
26         final RpcError rpcError = RpcResultBuilder.newError(
27                 RpcError.ErrorType.RPC, "error", "error message");
28         final RpcError rpcWarning = RpcResultBuilder.newWarning(
29                 RpcError.ErrorType.RPC, "warning", "warning message");
30
31         rpcErrors = new ArrayList<>();
32         rpcErrors.add(rpcError);
33         rpcErrors.add(rpcWarning);
34
35         exception = new RpcErrorsException(ERROR_MESSAGE, rpcErrors);
36     }
37
38     @Test
39     public void testGetMessage() {
40         Assert.assertEquals(ERROR_MESSAGE, exception.getMessage());
41     }
42
43     @Test
44     public void testGetRpcErrors() {
45         final List<RpcError> actualErrors = (List<RpcError>) exception.getRpcErrors();
46         Assert.assertEquals(rpcErrors.size(), actualErrors.size());
47
48         for (int i = 0; i < actualErrors.size(); i++) {
49             Assert.assertEquals(rpcErrors.get(i).getApplicationTag(), actualErrors.get(i).getApplicationTag());
50             Assert.assertEquals(rpcErrors.get(i).getSeverity(), actualErrors.get(i).getSeverity());
51             Assert.assertEquals(rpcErrors.get(i).getMessage(), actualErrors.get(i).getMessage());
52             Assert.assertEquals(rpcErrors.get(i).getErrorType(), actualErrors.get(i).getErrorType());
53             Assert.assertEquals(rpcErrors.get(i).getCause(), actualErrors.get(i).getCause());
54             Assert.assertEquals(rpcErrors.get(i).getInfo(), actualErrors.get(i).getInfo());
55             Assert.assertEquals(rpcErrors.get(i).getTag(), actualErrors.get(i).getTag());
56         }
57     }
58 }