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