*/
package org.opendaylight.mdsal.common.api;
-import java.io.Serial;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcResultBuilder;
* updated transaction.
*/
public class OptimisticLockFailedException extends TransactionCommitFailedException {
- @Serial
+ @java.io.Serial
private static final long serialVersionUID = 1L;
public OptimisticLockFailedException(final String message, final Throwable cause) {
*/
package org.opendaylight.mdsal.common.api;
-import java.io.Serial;
import java.util.function.Supplier;
import org.opendaylight.yangtools.yang.common.ErrorTag;
import org.opendaylight.yangtools.yang.common.ErrorType;
* @author Thomas Pantelis
*/
public class TransactionCommitDeadlockException extends TransactionCommitFailedException {
- @Serial
+ @java.io.Serial
private static final long serialVersionUID = 1L;
- private static final String DEADLOCK_MESSAGE = "An attempt to block on a ListenableFuture via a get method from a "
- + "write transaction submit was detected that would result in deadlock. The commit result must be obtained "
- + "asynchronously, e.g. via Futures#addCallback, to avoid deadlock.";
+ private static final String DEADLOCK_MESSAGE = """
+ An attempt to block on a ListenableFuture via a get method from a write transaction submit was detected that \
+ would result in deadlock. The commit result must be obtained asynchronously, e.g. via Futures#addCallback, to \
+ avoid deadlock.""";
private static final RpcError DEADLOCK_RPCERROR =
RpcResultBuilder.newError(ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, DEADLOCK_MESSAGE);
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+
+import org.junit.jupiter.api.Test;
+
+class CommitInfoTest {
+ @Test
+ void testEmpty() {
+ assertSame(EmptyCommitInfo.INSTANCE, CommitInfo.empty());
+ }
+
+ @Test
+ void testEmptyFluentFuture() {
+ assertSame(EmptyCommitInfo.FLUENT_INSTANCE, CommitInfo.emptyFluentFuture());
+ }
+}
*/
package org.opendaylight.mdsal.common.api;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-public class DataStoreUnavailableExceptionTest {
+import org.junit.jupiter.api.Test;
- @Test(expected = DataStoreUnavailableException.class)
- public void dataStoreUnavailableExceptionTest() throws Exception {
- throw new DataStoreUnavailableException("test", null);
+class DataStoreUnavailableExceptionTest {
+ @Test
+ void dataStoreUnavailableExceptionTest() {
+ final var ex = new DataStoreUnavailableException("test", null);
+ assertEquals("test", ex.getMessage());
+ assertNull(ex.getCause());
}
}
\ No newline at end of file
*/
package org.opendaylight.mdsal.common.api;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.concepts.HierarchicalIdentifier;
-public class DataValidationFailedExceptionTest {
-
- @Test(expected = DataValidationFailedException.class)
- public void dataValidationFailedExceptionTest() throws Exception {
- final TestClass testClass = new TestClass();
- final DataValidationFailedException dataValidationFailedException =
- new DataValidationFailedException(TestClass.class, testClass, "test");
-
- assertEquals(testClass, dataValidationFailedException.getPath());
- assertEquals(TestClass.class, dataValidationFailedException.getPathType());
-
- throw dataValidationFailedException;
+class DataValidationFailedExceptionTest {
+ @Test
+ void dataValidationFailedExceptionTest() throws Exception {
+ final var testObj = new TestClass();
+ final var dataValidationFailedException = new DataValidationFailedException(TestClass.class, testObj, "test");
+ assertEquals(testObj, dataValidationFailedException.getPath());
+ assertSame(TestClass.class, dataValidationFailedException.getPathType());
}
private static final class TestClass implements HierarchicalIdentifier<TestClass> {
+ @java.io.Serial
private static final long serialVersionUID = 1L;
@Override
--- /dev/null
+/*
+ * Copyright (c) 2023 PANTHEON.tech, s.r.o. and others. All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.mdsal.common.api;
+
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import com.google.common.util.concurrent.Futures;
+import org.junit.jupiter.api.Test;
+
+class EmptyCommitInfoTest {
+ @Test
+ void testFuture() throws Exception {
+ final var future = EmptyCommitInfo.FLUENT_INSTANCE;
+ assertTrue(future.isDone());
+ assertSame(EmptyCommitInfo.INSTANCE, Futures.getDone(future));
+ }
+}
*/
package org.opendaylight.mdsal.common.api;
-import static org.junit.Assert.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertThrows;
-import org.junit.Test;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.DataInputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.stream.Stream;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
-public class LogicalDatastoreTypeTest {
+class LogicalDatastoreTypeTest {
+ @ParameterizedTest
+ @MethodSource
+ void serialization(final LogicalDatastoreType type, final byte[] expected) throws Exception {
+ final var bout = new ByteArrayOutputStream();
+ try (var out = new DataOutputStream(bout)) {
+ type.writeTo(out);
+ }
+ assertArrayEquals(expected, bout.toByteArray());
+
+ try (var in = new DataInputStream(new ByteArrayInputStream(expected))) {
+ assertSame(type, LogicalDatastoreType.readFrom(in));
+ }
+ }
+
+ static Stream<Object[]> serialization() {
+ return Stream.of(
+ new Object[] { LogicalDatastoreType.OPERATIONAL, new byte[] { 1 }},
+ new Object[] { LogicalDatastoreType.CONFIGURATION, new byte[] { 2 }});
+ }
@Test
- public void basicTest() {
- assertFalse(LogicalDatastoreType.CONFIGURATION.equals(LogicalDatastoreType.OPERATIONAL));
+ void invalidSerialization() throws Exception {
+ try (var in = new DataInputStream(new ByteArrayInputStream(new byte[] { 0 }))) {
+ final var ex = assertThrows(IOException.class, () -> LogicalDatastoreType.readFrom(in));
+ assertEquals("Unknown type 0", ex.getMessage());
+ }
}
+
}
\ No newline at end of file
*/
package org.opendaylight.mdsal.common.api;
-import org.junit.Test;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-public class OptimisticLockFailedExceptionTest {
+import org.junit.jupiter.api.Test;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
- @Test(expected = OptimisticLockFailedException.class)
- public void optimisticLockFailedExceptionTest() throws Exception {
- throw new OptimisticLockFailedException("test");
+class OptimisticLockFailedExceptionTest {
+ @Test
+ void optimisticLockFailedExceptionTest() {
+ final var ex = new OptimisticLockFailedException("test");
+ assertEquals("test", ex.getMessage());
+ final var errors = ex.getErrorList();
+ assertEquals(1, errors.size());
+ final var error = errors.get(0);
+ assertEquals(ErrorType.APPLICATION, error.getErrorType());
+ assertEquals(ErrorTag.RESOURCE_DENIED, error.getTag());
+ assertNull(error.getApplicationTag());
+ assertNull(error.getInfo());
+ assertNull(error.getCause());
}
}
\ No newline at end of file
*/
package org.opendaylight.mdsal.common.api;
-import static org.junit.Assert.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.opendaylight.mdsal.common.api.PostPreCommitStep.NOOP_COMMIT_FUTURE;
-import org.junit.Test;
-
-public class PostCommitStepTest {
+import org.junit.jupiter.api.Test;
+class PostCommitStepTest {
@Test
- public void preCommitTest() throws Exception {
- final PostCanCommitStep postCanCommitStep = PostCanCommitStep.NOOP;
-
- assertEquals(ThreePhaseCommitStep.NOOP_ABORT_FUTURE ,postCanCommitStep.abort());
- assertEquals(PostPreCommitStep.NOOP_FUTURE, postCanCommitStep.preCommit());
+ void preCommitTest() throws Exception {
+ final var noop = PostCanCommitStep.NOOP;
+ assertEquals(ThreePhaseCommitStep.NOOP_ABORT_FUTURE ,noop.abort());
+ assertEquals(PostPreCommitStep.NOOP_FUTURE, noop.preCommit());
}
@Test
- public void canCommitTest() throws Exception {
- final PostPreCommitStep postPreCommitStep = PostPreCommitStep.NOOP;
-
- assertEquals(ThreePhaseCommitStep.NOOP_ABORT_FUTURE ,postPreCommitStep.abort());
- assertEquals(NOOP_COMMIT_FUTURE, postPreCommitStep.commit());
+ void canCommitTest() throws Exception {
+ final var noop = PostPreCommitStep.NOOP;
+ assertEquals(ThreePhaseCommitStep.NOOP_ABORT_FUTURE ,noop.abort());
+ assertEquals(NOOP_COMMIT_FUTURE, noop.commit());
}
}
\ No newline at end of file
*/
package org.opendaylight.mdsal.common.api;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.opendaylight.yangtools.yang.common.ErrorSeverity;
+import org.opendaylight.yangtools.yang.common.ErrorTag;
+import org.opendaylight.yangtools.yang.common.ErrorType;
import org.opendaylight.yangtools.yang.common.RpcError;
-public class ReadFailedExceptionTest {
+@ExtendWith(MockitoExtension.class)
+class ReadFailedExceptionTest {
+ @Mock
+ private RpcError rpcError;
- @Test(expected = ReadFailedException.class)
- public void readFailedExceptionTest() throws Exception {
- throw new ReadFailedException("test", mock(RpcError.class));
+ @Test
+ void readFailedExceptionTest() throws Exception {
+ final var ex = new ReadFailedException("test", rpcError);
+ assertEquals("test", ex.getMessage());
+ assertEquals(List.of(rpcError), ex.getErrorList());
}
- @Test(expected = ReadFailedException.class)
- public void readFailedExceptionWithThrowableTest() throws Exception {
- throw new ReadFailedException("test", ReadFailedException.MAPPER.apply(
- new NullPointerException()).getCause(), mock(RpcError.class));
+ @Test
+ void readFailedExceptionWithThrowableTest() throws Exception {
+ final var npe = new NullPointerException();
+ final var ex = new ReadFailedException("test", ReadFailedException.MAPPER.apply(npe));
+ assertEquals("test", ex.getMessage());
+ final var errors = ex.getErrorList();
+ assertEquals(1, errors.size());
+ final var error = errors.get(0);
+ assertEquals(ErrorSeverity.ERROR, error.getSeverity());
+ assertEquals(ErrorType.APPLICATION, error.getErrorType());
+ assertEquals(ErrorTag.OPERATION_FAILED, error.getTag());
+ assertNull(error.getApplicationTag());
+ assertNull(error.getInfo());
+
+ final var cause = assertInstanceOf(ReadFailedException.class, ex.getCause());
+ assertEquals("read encountered an unexpected failure", cause.getMessage());
+ final var causeErrors = cause.getErrorList();
+ assertEquals(1, causeErrors.size());
+ final var causeError = causeErrors.get(0);
+ assertEquals("read encountered an unexpected failure", causeError.getMessage());
+ assertEquals(ErrorSeverity.ERROR, causeError.getSeverity());
+ assertEquals(ErrorType.APPLICATION, causeError.getErrorType());
+ assertEquals(ErrorTag.OPERATION_FAILED, causeError.getTag());
+ assertNull(causeError.getApplicationTag());
+ assertNull(causeError.getInfo());
+
+ assertSame(npe, causeError.getCause());
}
}
\ No newline at end of file
*/
package org.opendaylight.mdsal.common.api;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
-import org.junit.Test;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.common.RpcError;
-public class TransactionCommitDeadlockExceptionTest {
+@ExtendWith(MockitoExtension.class)
+class TransactionCommitDeadlockExceptionTest {
+ @Mock
+ private RpcError rpcError;
- @Test(expected = TransactionCommitDeadlockException.class)
- public void transactionCommitDeadlockExceptionTest() throws Exception {
- throw new TransactionCommitDeadlockException(TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER
- .get().getMessage(), mock(RpcError.class));
+ @Test
+ void transactionCommitDeadlockExceptionTest() throws Exception {
+ final var message = TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER.get().getMessage();
+ final var ex = new TransactionCommitDeadlockException(message, rpcError);
+ assertSame(message, ex.getMessage());
+ assertNull(ex.getCause());
+ assertEquals(List.of(rpcError), ex.getErrorList());
}
}
\ No newline at end of file
*/
package org.opendaylight.mdsal.common.api;
-import static org.mockito.Mockito.mock;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNull;
-import org.junit.Test;
+import java.util.List;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
import org.opendaylight.yangtools.yang.common.RpcError;
-public class TransactionCommitFailedExceptionTest {
+@ExtendWith(MockitoExtension.class)
+class TransactionCommitFailedExceptionTest {
+ @Mock
+ private RpcError error;
- @Test(expected = TransactionCommitFailedException.class)
- public void transactionCommitFailedExceptionTest() throws Exception {
- throw new TransactionCommitFailedException("test", mock(RpcError.class));
+ @Test
+ void transactionCommitFailedExceptionTest() {
+ final var ex = new TransactionCommitFailedException("test", error);
+ assertEquals("test", ex.getMessage());
+ assertNull(ex.getCause());
+ assertEquals(List.of(error), ex.getErrorList());
}
}
\ No newline at end of file