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.Futures;
15 import com.google.common.util.concurrent.ListenableFuture;
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.access.client.ClientActorContext;
22 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 public class ClientBackedReadTransactionTest extends ClientBackedTransactionTest<ClientBackedReadTransaction> {
27 private ClientBackedReadTransaction object;
30 private NormalizedNode<?, ?> data;
32 private ClientActorContext clientContext;
34 private ClientSnapshot delegate;
37 ClientBackedReadTransaction object() {
43 MockitoAnnotations.initMocks(this);
45 doReturn(CLIENT_ID).when(clientContext).getIdentifier();
46 doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
48 doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate).exists(YangInstanceIdentifier.EMPTY);
49 doReturn(Futures.immediateCheckedFuture(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());