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;
13 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateFluentFuture;
14 import static org.opendaylight.yangtools.util.concurrent.FluentFutures.immediateTrueFluentFuture;
16 import com.google.common.util.concurrent.ListenableFuture;
17 import java.util.Optional;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.junit.runner.RunWith;
21 import org.mockito.Mock;
22 import org.mockito.junit.MockitoJUnitRunner;
23 import org.opendaylight.controller.cluster.access.client.ClientActorContext;
24 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
25 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
28 @RunWith(MockitoJUnitRunner.StrictStubs.class)
29 public class ClientBackedReadTransactionTest extends ClientBackedTransactionTest<ClientBackedReadTransaction> {
30 private ClientBackedReadTransaction object;
33 private NormalizedNode data;
35 private ClientActorContext clientContext;
37 private ClientSnapshot delegate;
40 ClientBackedReadTransaction object() {
46 doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
48 doReturn(immediateTrueFluentFuture()).when(delegate).exists(YangInstanceIdentifier.empty());
49 doReturn(immediateFluentFuture(Optional.of(data))).when(delegate).read(YangInstanceIdentifier.empty());
51 object = new ClientBackedReadTransaction(delegate, null, null);
55 public void testRead() throws Exception {
56 final ListenableFuture<Optional<NormalizedNode>> result = object().read(YangInstanceIdentifier.empty());
57 final Optional<NormalizedNode> resultData = result.get();
58 assertTrue(resultData.isPresent());
59 assertEquals(data, resultData.get());
63 public void testExists() throws Exception {
64 final ListenableFuture<Boolean> result = object().exists(YangInstanceIdentifier.empty());
65 assertEquals(Boolean.TRUE, result.get());