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.access.client.ClientActorContext;
20 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
21 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
25 public class ClientBackedReadTransactionTest extends ClientBackedTransactionTest<ClientBackedReadTransaction> {
26 private ClientBackedReadTransaction object;
29 private NormalizedNode data;
31 private ClientActorContext clientContext;
33 private ClientSnapshot delegate;
36 ClientBackedReadTransaction object() throws Exception {
41 @SuppressWarnings("unchecked")
42 public void setUp() throws Exception {
43 MockitoAnnotations.initMocks(this);
45 Mockito.doReturn(CLIENT_ID).when(clientContext).getIdentifier();
46 Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
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 ClientBackedReadTransaction(delegate, null);
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 final CheckedFuture<Boolean, ReadFailedException> result = object().exists(YangInstanceIdentifier.EMPTY);
68 Assert.assertTrue(result.get());