Move and split EntityOwnershipService common-api
[mdsal.git] / common / mdsal-common-api / src / test / java / org / opendaylight / mdsal / common / api / BasicExceptionTests.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.common.api;
9
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;
16
17 public class BasicExceptionTests {
18
19     private static final RpcError RPC_ERROR = mock(RpcError.class);
20
21     @Test(expected = TransactionCommitFailedException.class)
22     public void transactionCommitFailedExceptionTest() throws Exception {
23         throw new TransactionCommitFailedException("test", RPC_ERROR);
24     }
25
26     @Test(expected = TransactionCommitDeadlockException.class)
27     public void transactionCommitDeadlockExceptionTest() throws Exception {
28         throw new TransactionCommitDeadlockException(TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER
29                 .get().getMessage(), RPC_ERROR);
30     }
31
32     @Test(expected = TransactionChainClosedException.class)
33     public void transactionChainClosedExceptionTest() throws Exception {
34         throw new TransactionChainClosedException("test");
35     }
36
37     @Test(expected = TransactionChainClosedException.class)
38     public void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
39         throw new TransactionChainClosedException("test", null);
40     }
41
42     @Test(expected = ReadFailedException.class)
43     public void readFailedExceptionTest() throws Exception {
44         throw new ReadFailedException("test", RPC_ERROR);
45     }
46
47     @Test(expected = ReadFailedException.class)
48     public void readFailedExceptionWithThrowableTest() throws Exception {
49
50         throw new ReadFailedException("test", ReadFailedException.MAPPER.apply(
51                 new NullPointerException()).getCause(), RPC_ERROR);
52     }
53
54     @Test(expected = OptimisticLockFailedException.class)
55     public void optimisticLockFailedExceptionTest() throws Exception {
56         throw new OptimisticLockFailedException("test");
57     }
58
59     @Test(expected = DataStoreUnavailableException.class)
60     public void dataStoreUnavailableExceptionTest() throws Exception {
61         throw new DataStoreUnavailableException("test", null);
62     }
63
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");
69
70         assertEquals(testClass, dataValidationFailedException.getPath());
71         assertEquals(TestClass.class, dataValidationFailedException.getPathType());
72
73         throw dataValidationFailedException;
74     }
75
76     private final class TestClass implements Path {
77         @Override
78         public boolean contains(@Nonnull final Path other) {
79             return false;
80         }
81     }
82 }