2 * Copyright (c) 2017 Pantheon Technologies s.r.o. 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.controller.cluster.databroker;
10 import com.google.common.base.Optional;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import com.google.common.util.concurrent.Futures;
13 import org.junit.Assert;
14 import org.junit.Before;
15 import org.junit.Test;
16 import org.mockito.Mock;
17 import org.mockito.Mockito;
18 import org.mockito.MockitoAnnotations;
19 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
20 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
21 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 public class ClientBackedReadWriteTransactionTest
26 extends ClientBackedTransactionTest<ClientBackedReadWriteTransaction> {
27 private ClientBackedReadWriteTransaction object;
30 private ClientTransaction delegate;
32 private NormalizedNode data;
34 private DOMStoreThreePhaseCommitCohort readyCohort;
37 ClientBackedReadWriteTransaction object() throws Exception {
42 public void setUp() throws Exception {
43 MockitoAnnotations.initMocks(this);
45 Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
46 Mockito.doReturn(readyCohort).when(delegate).ready();
48 Mockito.doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate)
49 .exists(YangInstanceIdentifier.EMPTY);
50 Mockito.doReturn(Futures.immediateCheckedFuture(Optional.of(data))).when(delegate)
51 .read(YangInstanceIdentifier.EMPTY);
53 object = new ClientBackedReadWriteTransaction(delegate);
57 public void testRead() throws Exception {
58 final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> result = object().read(
59 YangInstanceIdentifier.EMPTY);
60 final Optional<NormalizedNode<?, ?>> resultData = result.get();
61 Assert.assertTrue(resultData.isPresent());
62 Assert.assertEquals(data, resultData.get());
66 public void testExists() throws Exception {
67 Assert.assertTrue(object().exists(YangInstanceIdentifier.EMPTY).get());