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.util.concurrent.FluentFuture;
11 import com.google.common.util.concurrent.Futures;
12 import java.util.Optional;
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.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
24 public class ClientBackedReadWriteTransactionTest
25 extends ClientBackedTransactionTest<ClientBackedReadWriteTransaction> {
26 private ClientBackedReadWriteTransaction object;
29 private ClientTransaction delegate;
31 private NormalizedNode<?, ?> data;
33 private DOMStoreThreePhaseCommitCohort readyCohort;
36 ClientBackedReadWriteTransaction object() {
42 MockitoAnnotations.initMocks(this);
44 Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
45 Mockito.doReturn(readyCohort).when(delegate).ready();
47 Mockito.doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate)
48 .exists(YangInstanceIdentifier.EMPTY);
49 Mockito.doReturn(Futures.immediateCheckedFuture(Optional.of(data))).when(delegate)
50 .read(YangInstanceIdentifier.EMPTY);
52 object = new ClientBackedReadWriteTransaction(delegate, null);
56 public void testRead() throws Exception {
57 final FluentFuture<Optional<NormalizedNode<?, ?>>> result = object().read(YangInstanceIdentifier.EMPTY);
58 final Optional<NormalizedNode<?, ?>> resultData = result.get();
59 Assert.assertTrue(resultData.isPresent());
60 Assert.assertEquals(data, resultData.get());
64 public void testExists() throws Exception {
65 Assert.assertTrue(object().exists(YangInstanceIdentifier.EMPTY).get());