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 static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.Mockito.doReturn;
14 import com.google.common.util.concurrent.FluentFuture;
15 import com.google.common.util.concurrent.Futures;
16 import java.util.Optional;
17 import org.junit.Before;
18 import org.junit.Test;
19 import org.mockito.Mock;
20 import org.mockito.MockitoAnnotations;
21 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
22 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 public class ClientBackedReadWriteTransactionTest
27 extends ClientBackedTransactionTest<ClientBackedReadWriteTransaction> {
28 private ClientBackedReadWriteTransaction object;
31 private ClientTransaction delegate;
33 private NormalizedNode<?, ?> data;
35 private DOMStoreThreePhaseCommitCohort readyCohort;
38 ClientBackedReadWriteTransaction object() {
44 MockitoAnnotations.initMocks(this);
46 doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
47 doReturn(readyCohort).when(delegate).ready();
49 doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate).exists(YangInstanceIdentifier.EMPTY);
50 doReturn(Futures.immediateCheckedFuture(Optional.of(data))).when(delegate).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 assertTrue(resultData.isPresent());
60 assertEquals(data, resultData.get());
64 public void testExists() throws Exception {
65 assertEquals(Boolean.TRUE, object().exists(YangInstanceIdentifier.EMPTY).get());