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.doReturn;
12 import static org.mockito.Mockito.mock;
14 import javax.annotation.Nonnull;
15 import org.junit.Test;
16 import org.opendaylight.mdsal.common.api.clustering.CandidateAlreadyRegisteredException;
17 import org.opendaylight.mdsal.common.api.clustering.GenericEntity;
18 import org.opendaylight.yangtools.concepts.Path;
19 import org.opendaylight.yangtools.yang.common.RpcError;
21 public class BasicExceptionTests {
23 private static final RpcError RPC_ERROR = mock(RpcError.class);
25 @Test(expected = TransactionCommitFailedException.class)
26 public void transactionCommitFailedExceptionTest() throws Exception {
27 throw new TransactionCommitFailedException("test", RPC_ERROR);
30 @Test(expected = TransactionCommitDeadlockException.class)
31 public void transactionCommitDeadlockExceptionTest() throws Exception {
32 throw new TransactionCommitDeadlockException(TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER
33 .get().getMessage(), RPC_ERROR);
36 @Test(expected = TransactionChainClosedException.class)
37 public void transactionChainClosedExceptionTest() throws Exception {
38 throw new TransactionChainClosedException("test");
41 @Test(expected = TransactionChainClosedException.class)
42 public void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
43 throw new TransactionChainClosedException("test", null);
46 @Test(expected = ReadFailedException.class)
47 public void readFailedExceptionTest() throws Exception {
48 throw new ReadFailedException("test", RPC_ERROR);
51 @Test(expected = ReadFailedException.class)
52 public void readFailedExceptionWithThrowableTest() throws Exception {
54 throw new ReadFailedException("test", ReadFailedException.MAPPER.apply(
55 new NullPointerException()).getCause(), RPC_ERROR);
58 @Test(expected = OptimisticLockFailedException.class)
59 public void optimisticLockFailedExceptionTest() throws Exception {
60 throw new OptimisticLockFailedException("test");
63 @Test(expected = DataStoreUnavailableException.class)
64 public void dataStoreUnavailableExceptionTest() throws Exception {
65 throw new DataStoreUnavailableException("test", null);
68 @Test(expected = DataValidationFailedException.class)
69 public void dataValidationFailedExceptionTest() throws Exception {
70 final TestClass testClass = new TestClass();
71 final DataValidationFailedException dataValidationFailedException =
72 new DataValidationFailedException(TestClass.class, testClass, "test");
74 assertEquals(testClass, dataValidationFailedException.getPath());
75 assertEquals(TestClass.class, dataValidationFailedException.getPathType());
77 throw dataValidationFailedException;
80 @Test(expected = CandidateAlreadyRegisteredException.class)
81 public void candidateAlreadyRegisteredExceptionTest() throws Exception {
82 final GenericEntity genericEntity = mock(GenericEntity.class);
83 doReturn("testEntity").when(genericEntity).toString();
84 CandidateAlreadyRegisteredException candidateAlreadyRegisteredException =
85 new CandidateAlreadyRegisteredException(genericEntity);
86 assertEquals(genericEntity, candidateAlreadyRegisteredException.getEntity());
88 throw candidateAlreadyRegisteredException;
91 private final class TestClass implements Path {
93 public boolean contains(@Nonnull Path other) {