6ced09682e409aa8ec2a5cb1ebae7e1f7cd59918
[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 static org.junit.Assert.assertEquals;
11
12 import java.util.ArrayList;
13 import java.util.List;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.RpcError;
17 import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
18
19 public class RpcErrorsExceptionTest {
20     private static final String ERROR_MESSAGE = "Test error message.";
21
22     private List<RpcError> rpcErrors;
23     private RpcErrorsException exception;
24
25     @Before
26     public void setUp() {
27         final RpcError rpcError = RpcResultBuilder.newError(
28                 RpcError.ErrorType.RPC, "error", "error message");
29         final RpcError rpcWarning = RpcResultBuilder.newWarning(
30                 RpcError.ErrorType.RPC, "warning", "warning message");
31
32         rpcErrors = new ArrayList<>();
33         rpcErrors.add(rpcError);
34         rpcErrors.add(rpcWarning);
35
36         exception = new RpcErrorsException(ERROR_MESSAGE, rpcErrors);
37     }
38
39     @Test
40     public void testGetMessage() {
41         assertEquals(ERROR_MESSAGE, exception.getMessage());
42     }
43
44     @Test
45     public void testGetRpcErrors() {
46         final List<RpcError> actualErrors = (List<RpcError>) exception.getRpcErrors();
47         assertEquals(rpcErrors.size(), actualErrors.size());
48
49         for (int i = 0; i < actualErrors.size(); i++) {
50             final RpcError expected = rpcErrors.get(i);
51             final RpcError actual = actualErrors.get(i);
52
53             assertEquals(expected.getApplicationTag(), actual.getApplicationTag());
54             assertEquals(expected.getSeverity(), actual.getSeverity());
55             assertEquals(expected.getMessage(), actual.getMessage());
56             assertEquals(expected.getErrorType(), actual.getErrorType());
57             assertEquals(expected.getCause(), actual.getCause());
58             assertEquals(expected.getInfo(), actual.getInfo());
59             assertEquals(expected.getTag(), actual.getTag());
60         }
61     }
62 }