<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <scope>test</scope>
+ </dependency>
</dependencies>
<scm>
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.Assert.assertEquals;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import javax.annotation.Nonnull;
+import org.junit.Test;
+import org.opendaylight.mdsal.common.api.clustering.CandidateAlreadyRegisteredException;
+import org.opendaylight.mdsal.common.api.clustering.GenericEntity;
+import org.opendaylight.yangtools.concepts.Path;
+import org.opendaylight.yangtools.yang.common.RpcError;
+
+public class BasicExceptionTests {
+
+ private static final RpcError RPC_ERROR = mock(RpcError.class);
+
+ @Test(expected = TransactionCommitFailedException.class)
+ public void transactionCommitFailedExceptionTest() throws Exception {
+ throw new TransactionCommitFailedException("test", RPC_ERROR);
+ }
+
+ @Test(expected = TransactionCommitDeadlockException.class)
+ public void transactionCommitDeadlockExceptionTest() throws Exception {
+ throw new TransactionCommitDeadlockException(TransactionCommitDeadlockException.DEADLOCK_EXCEPTION_SUPPLIER
+ .get().getMessage(), RPC_ERROR);
+ }
+
+ @Test(expected = TransactionChainClosedException.class)
+ public void transactionChainClosedExceptionTest() throws Exception {
+ throw new TransactionChainClosedException("test");
+ }
+
+ @Test(expected = TransactionChainClosedException.class)
+ public void transactionChainClosedExceptionWithNullCauseTest() throws Exception {
+ throw new TransactionChainClosedException("test", null);
+ }
+
+ @Test(expected = ReadFailedException.class)
+ public void readFailedExceptionTest() throws Exception {
+ throw new ReadFailedException("test", RPC_ERROR);
+ }
+
+ @Test(expected = ReadFailedException.class)
+ public void readFailedExceptionWithThrowableTest() throws Exception {
+
+ throw new ReadFailedException("test", ReadFailedException.MAPPER.apply(
+ new NullPointerException()).getCause(), RPC_ERROR);
+ }
+
+ @Test(expected = OptimisticLockFailedException.class)
+ public void optimisticLockFailedExceptionTest() throws Exception {
+ throw new OptimisticLockFailedException("test");
+ }
+
+ @Test(expected = DataStoreUnavailableException.class)
+ public void dataStoreUnavailableExceptionTest() throws Exception {
+ throw new DataStoreUnavailableException("test", null);
+ }
+
+ @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;
+ }
+
+ @Test(expected = CandidateAlreadyRegisteredException.class)
+ public void candidateAlreadyRegisteredExceptionTest() throws Exception {
+ final GenericEntity genericEntity = mock(GenericEntity.class);
+ doReturn("testEntity").when(genericEntity).toString();
+ CandidateAlreadyRegisteredException candidateAlreadyRegisteredException =
+ new CandidateAlreadyRegisteredException(genericEntity);
+ assertEquals(genericEntity, candidateAlreadyRegisteredException.getEntity());
+
+ throw candidateAlreadyRegisteredException;
+ }
+
+ private final class TestClass implements Path {
+ @Override
+ public boolean contains(@Nonnull Path other) {
+ return false;
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.Assert.assertFalse;
+
+import org.junit.Test;
+
+public class LogicalDatastoreTypeTest {
+
+ @Test
+ public void basicTest() {
+ assertFalse(LogicalDatastoreType.CONFIGURATION.equals(LogicalDatastoreType.OPERATIONAL));
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.Assert.assertEquals;
+import static org.opendaylight.mdsal.common.api.PostPreCommitStep.NOOP_COMMIT_FUTURE;
+
+import org.junit.Test;
+
+public 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());
+ }
+
+ @Test
+ public void canCommitTest() throws Exception {
+ final PostPreCommitStep postPreCommitStep = PostPreCommitStep.NOOP;
+
+ assertEquals(ThreePhaseCommitStep.NOOP_ABORT_FUTURE ,postPreCommitStep.abort());
+ assertEquals(NOOP_COMMIT_FUTURE, postPreCommitStep.commit());
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.clustering;
+
+import static org.junit.Assert.assertNotNull;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+
+public class AbstractGenericEntityOwnershipCandidateRegistrationTest
+ extends AbstractGenericEntityOwnershipCandidateRegistration {
+
+ @Test
+ public void basicTest() {
+ assertNotNull(this);
+ }
+
+ public AbstractGenericEntityOwnershipCandidateRegistrationTest() {
+ super(mock(GenericEntity.class));
+ }
+
+ @Override
+ protected void removeRegistration() {
+ //NOOP
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.clustering;
+
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+
+public class AbstractGenericEntityOwnershipListenerRegistrationTest
+ extends AbstractGenericEntityOwnershipListenerRegistration {
+
+ @Test
+ public void basicTest() throws Exception {
+ assertTrue(this.getEntityType().contains("testEntity"));
+ }
+
+ public AbstractGenericEntityOwnershipListenerRegistrationTest() {
+ super(mock(GenericEntityOwnershipListener.class), "testEntity");
+ }
+
+ @Override
+ protected void removeRegistration() {
+ // NOOP
+ }
+}
\ No newline at end of file
package org.opendaylight.mdsal.common.api.clustering;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
import org.junit.Test;
/**
public class EntityOwnershipChangeStateTest {
@Test
- public void testFromWithValid() {
+ public void testFromWithValid() throws Exception {
assertEquals("from(false, true, true)", EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED,
EntityOwnershipChangeState.from(false, true, true));
assertEquals("from(true, false, true)", EntityOwnershipChangeState.LOCAL_OWNERSHIP_LOST_NEW_OWNER,
public void testFromWithInvalidTrueTrueTrue() {
EntityOwnershipChangeState.from(true, true, true);
}
+
+ @Test
+ public void basicTest() throws Exception {
+ EntityOwnershipChangeState entityOwnershipChangeState = EntityOwnershipChangeState.from(false, true, true);
+ assertTrue(entityOwnershipChangeState.hasOwner());
+ assertTrue(entityOwnershipChangeState.isOwner());
+ assertFalse(entityOwnershipChangeState.wasOwner());
+ assertTrue(entityOwnershipChangeState.toString().matches(".*false.*true.*true.*"));
+ }
}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.clustering;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Test;
+
+public class EntityOwnershipStateTest {
+
+ @Test
+ public void fromTest() throws Exception {
+ assertEquals(EntityOwnershipState.NO_OWNER, EntityOwnershipState.from(false, false));
+ assertEquals(EntityOwnershipState.IS_OWNER, EntityOwnershipState.from(true, false));
+ assertEquals(EntityOwnershipState.OWNED_BY_OTHER, EntityOwnershipState.from(false, true));
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.clustering;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+
+import org.junit.Test;
+
+public class GenericEntityOwnershipChangeTest {
+
+ @Test
+ public void basicTest() throws Exception {
+ final GenericEntity genericEntity = mock(GenericEntity.class);
+ doReturn("testEntity").when(genericEntity).toString();
+ final GenericEntityOwnershipChange genericEntityOwnershipChange =
+ new GenericEntityOwnershipChange(genericEntity, EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED);
+
+ assertEquals(genericEntity, genericEntityOwnershipChange.getEntity());
+ assertEquals(EntityOwnershipChangeState.LOCAL_OWNERSHIP_GRANTED, genericEntityOwnershipChange.getState());
+ assertFalse(genericEntityOwnershipChange.inJeopardy());
+ assertTrue(genericEntityOwnershipChange.toString().contains("testEntity"));
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2016 Cisco Systems, Inc. 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.clustering;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+
+import javax.annotation.Nonnull;
+import org.junit.Test;
+import org.opendaylight.yangtools.concepts.Path;
+
+public class GenericEntityTest {
+
+ @Test
+ public void basicTest() throws Exception {
+ final TestClass testClass = new TestClass();
+ final GenericEntity genericEntity = new GenericEntity<>("testType", testClass);
+ final GenericEntity genericEntityDiff = new GenericEntity<>("differentTestType", new TestClassDiff());
+
+ assertEquals(TestClass.class, genericEntity.getIdentifier().getClass());
+ assertEquals("testType", genericEntity.getType());
+ assertTrue(genericEntity.toString().contains("testType"));
+ assertNotEquals(genericEntity.hashCode(), genericEntityDiff.hashCode());
+ assertTrue(genericEntity.equals(genericEntity));
+ assertTrue(genericEntity.equals(new GenericEntity<>("testType", testClass)));
+ assertFalse(genericEntity.equals(genericEntityDiff));
+ assertFalse(genericEntity.equals(new String()));
+ assertFalse(genericEntity.equals(new GenericEntity<>("differentTestType", testClass)));
+ }
+
+ private final class TestClass implements Path {
+ @Override
+ public boolean contains(@Nonnull Path other) {
+ return false;
+ }
+ }
+
+ private final class TestClassDiff implements Path {
+ @Override
+ public boolean contains(@Nonnull Path other) {
+ return false;
+ }
+ }
+}
\ No newline at end of file