2 * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.common.api;
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.mock;
12 import javax.annotation.Nonnull;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.concepts.Path;
15 import org.opendaylight.yangtools.yang.common.RpcError;
17 public class BasicExceptionTests {
19 private static final RpcError RPC_ERROR = mock(RpcError.class);
21 @Test(expected = TransactionCommitFailedException.class)
22 public void transactionCommitFailedExceptionTest() throws Exception {
23 throw new TransactionCommitFailedException("test", RPC_ERROR);
26 @Test(expected = TransactionCommitDeadlockException.class)
27 public void transactionCommitDeadlockExceptionTest() throws Exception {
28 throw new TransactionCommitDeadlockException(TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER
29 .get().getMessage(), RPC_ERROR);
32 @Test(expected = TransactionChainClosedException.class)
33 public void transactionChainClosedExceptionTest() throws Exception {
34 throw new TransactionChainClosedException("test");
37 @Test(expected = TransactionChainClosedException.class)
38 public void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
39 throw new TransactionChainClosedException("test", null);
42 @Test(expected = ReadFailedException.class)
43 public void readFailedExceptionTest() throws Exception {
44 throw new ReadFailedException("test", RPC_ERROR);
47 @Test(expected = ReadFailedException.class)
48 public void readFailedExceptionWithThrowableTest() throws Exception {
50 throw new ReadFailedException("test", ReadFailedException.MAPPER.apply(
51 new NullPointerException()).getCause(), RPC_ERROR);
54 @Test(expected = OptimisticLockFailedException.class)
55 public void optimisticLockFailedExceptionTest() throws Exception {
56 throw new OptimisticLockFailedException("test");
59 @Test(expected = DataStoreUnavailableException.class)
60 public void dataStoreUnavailableExceptionTest() throws Exception {
61 throw new DataStoreUnavailableException("test", null);
64 @Test(expected = DataValidationFailedException.class)
65 public void dataValidationFailedExceptionTest() throws Exception {
66 final TestClass testClass = new TestClass();
67 final DataValidationFailedException dataValidationFailedException =
68 new DataValidationFailedException(TestClass.class, testClass, "test");
70 assertEquals(testClass, dataValidationFailedException.getPath());
71 assertEquals(TestClass.class, dataValidationFailedException.getPathType());
73 throw dataValidationFailedException;
76 private final class TestClass implements Path {
78 public boolean contains(@Nonnull final Path other) {