return ensureProxy(path, this::createProxy);
}
- public final CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
+ public CheckedFuture<Boolean, ReadFailedException> exists(final YangInstanceIdentifier path) {
return ensureSnapshotProxy(path).exists(path);
}
- public final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
+ public CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> read(
final YangInstanceIdentifier path) {
return ensureSnapshotProxy(path).read(path);
}
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies 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.controller.cluster.databroker;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.cluster.access.client.ClientActorContext;
+import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+public class ClientBackedReadTransactionTest extends ClientBackedTransactionTest<ClientBackedReadTransaction> {
+ private ClientBackedReadTransaction object;
+
+ @Mock
+ private NormalizedNode data;
+ @Mock
+ private ClientActorContext clientContext;
+ @Mock
+ private ClientSnapshot delegate;
+
+ @Override
+ ClientBackedReadTransaction object() throws Exception {
+ return object;
+ }
+
+ @Before
+ @SuppressWarnings("unchecked")
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ Mockito.doReturn(CLIENT_ID).when(clientContext).getIdentifier();
+ Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
+
+ Mockito.doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate)
+ .exists(YangInstanceIdentifier.EMPTY);
+ Mockito.doReturn(Futures.immediateCheckedFuture(Optional.of(data))).when(delegate)
+ .read(YangInstanceIdentifier.EMPTY);
+
+ object = new ClientBackedReadTransaction(delegate, null);
+ }
+
+ @Test
+ public void testRead() throws Exception {
+ final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> result = object().read(
+ YangInstanceIdentifier.EMPTY);
+ final Optional<NormalizedNode<?, ?>> resultData = result.get();
+ Assert.assertTrue(resultData.isPresent());
+ Assert.assertEquals(data, resultData.get());
+ }
+
+ @Test
+ public void testExists() throws Exception {
+ final CheckedFuture<Boolean, ReadFailedException> result = object().exists(YangInstanceIdentifier.EMPTY);
+ Assert.assertTrue(result.get());
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies 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.controller.cluster.databroker;
+
+import com.google.common.base.Optional;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
+import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+public class ClientBackedReadWriteTransactionTest
+ extends ClientBackedTransactionTest<ClientBackedReadWriteTransaction> {
+ private ClientBackedReadWriteTransaction object;
+
+ @Mock
+ private ClientTransaction delegate;
+ @Mock
+ private NormalizedNode data;
+ @Mock
+ private DOMStoreThreePhaseCommitCohort readyCohort;
+
+ @Override
+ ClientBackedReadWriteTransaction object() throws Exception {
+ return object;
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
+ Mockito.doReturn(readyCohort).when(delegate).ready();
+
+ Mockito.doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate)
+ .exists(YangInstanceIdentifier.EMPTY);
+ Mockito.doReturn(Futures.immediateCheckedFuture(Optional.of(data))).when(delegate)
+ .read(YangInstanceIdentifier.EMPTY);
+
+ object = new ClientBackedReadWriteTransaction(delegate);
+ }
+
+ @Test
+ public void testRead() throws Exception {
+ final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> result = object().read(
+ YangInstanceIdentifier.EMPTY);
+ final Optional<NormalizedNode<?, ?>> resultData = result.get();
+ Assert.assertTrue(resultData.isPresent());
+ Assert.assertEquals(data, resultData.get());
+ }
+
+ @Test
+ public void testExists() throws Exception {
+ Assert.assertTrue(object().exists(YangInstanceIdentifier.EMPTY).get());
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies 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.controller.cluster.databroker;
+
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.cluster.access.concepts.ClientIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.FrontendIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.FrontendType;
+import org.opendaylight.controller.cluster.access.concepts.LocalHistoryIdentifier;
+import org.opendaylight.controller.cluster.access.concepts.MemberName;
+import org.opendaylight.controller.cluster.access.concepts.TransactionIdentifier;
+import org.opendaylight.controller.cluster.databroker.actors.dds.AbstractClientHandle;
+
+public abstract class ClientBackedTransactionTest<T extends ClientBackedTransaction<?>> {
+ private static FrontendIdentifier FRONTEND_ID = FrontendIdentifier.create(
+ MemberName.forName("member"), FrontendType.forName("frontend"));
+ protected static final ClientIdentifier CLIENT_ID = ClientIdentifier.create(FRONTEND_ID, 0);
+
+ private static LocalHistoryIdentifier HISTORY_ID = new LocalHistoryIdentifier(CLIENT_ID, 0);
+ protected static final TransactionIdentifier TRANSACTION_ID = new TransactionIdentifier(HISTORY_ID, 0);
+
+ abstract T object() throws Exception;
+
+ @Test
+ public void testClose() throws Exception {
+ final AbstractClientHandle<?> delegate = object().delegate();
+ object().close();
+ Mockito.verify(delegate).abort();
+ }
+}
\ No newline at end of file
--- /dev/null
+/*
+ * Copyright (c) 2017 Pantheon Technologies 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.controller.cluster.databroker;
+
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.Mockito;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
+import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+public class ClientBackedWriteTransactionTest extends ClientBackedTransactionTest<ClientBackedWriteTransaction> {
+ private ClientBackedWriteTransaction object;
+
+ @Mock
+ private ClientTransaction delegate;
+ @Mock
+ private NormalizedNode data;
+ @Mock
+ private YangInstanceIdentifier path;
+ @Mock
+ private DOMStoreThreePhaseCommitCohort readyCohort;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
+ Mockito.doReturn(readyCohort).when(delegate).ready();
+
+ object = new ClientBackedWriteTransaction(delegate);
+ }
+
+ @Override
+ ClientBackedWriteTransaction object() throws Exception {
+ return object;
+ }
+
+ @Test
+ public void testWrite() throws Exception {
+ object().write(path, data);
+ Mockito.verify(delegate).write(path, data);
+ }
+
+ @Test
+ public void testMerge() throws Exception {
+ object().merge(path, data);
+ Mockito.verify(delegate).merge(path, data);
+ }
+
+ @Test
+ public void testDelete() throws Exception {
+ object().delete(path);
+ Mockito.verify(delegate).delete(path);
+ }
+
+ @Test
+ public void testReady() throws Exception {
+ final org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort result = object().ready();
+ Assert.assertNotNull(result);
+ Mockito.verify(delegate).ready();
+ }
+}
\ No newline at end of file