2 * Copyright (c) 2017 Pantheon Technologies s.r.o. and others. All rights reserved.
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
8 package org.opendaylight.controller.remote.rpc;
10 import static org.junit.Assert.assertEquals;
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;
21 public class RpcErrorsExceptionTest {
22 private static final String ERROR_MESSAGE = "Test error message.";
24 private List<RpcError> rpcErrors;
25 private RpcErrorsException exception;
29 final RpcError rpcError = RpcResultBuilder.newError(ErrorType.RPC, new ErrorTag("error"), "error message");
30 final RpcError rpcWarning = RpcResultBuilder.newWarning(ErrorType.RPC, new ErrorTag("warning"),
33 rpcErrors = new ArrayList<>();
34 rpcErrors.add(rpcError);
35 rpcErrors.add(rpcWarning);
37 exception = new RpcErrorsException(ERROR_MESSAGE, rpcErrors);
41 public void testGetMessage() {
42 assertEquals(ERROR_MESSAGE, exception.getMessage());
46 public void testGetRpcErrors() {
47 final List<RpcError> actualErrors = (List<RpcError>) exception.getRpcErrors();
48 assertEquals(rpcErrors.size(), actualErrors.size());
50 for (int i = 0; i < actualErrors.size(); i++) {
51 final RpcError expected = rpcErrors.get(i);
52 final RpcError actual = actualErrors.get(i);
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());