89c0519992b2c7830640ff2ceae7e4d80266b20b
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / ClientBackedReadTransactionTest.java
1 /*
2  * Copyright (c) 2017 Pantheon Technologies s.r.o. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.controller.cluster.databroker;
9
10 import com.google.common.util.concurrent.Futures;
11 import com.google.common.util.concurrent.ListenableFuture;
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.access.client.ClientActorContext;
20 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientSnapshot;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23
24 public class ClientBackedReadTransactionTest extends ClientBackedTransactionTest<ClientBackedReadTransaction> {
25     private ClientBackedReadTransaction object;
26
27     @Mock
28     private NormalizedNode<?, ?> data;
29     @Mock
30     private ClientActorContext clientContext;
31     @Mock
32     private ClientSnapshot delegate;
33
34     @Override
35     ClientBackedReadTransaction object() {
36         return object;
37     }
38
39     @Before
40     public void setUp() {
41         MockitoAnnotations.initMocks(this);
42
43         Mockito.doReturn(CLIENT_ID).when(clientContext).getIdentifier();
44         Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
45
46         Mockito.doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate)
47                 .exists(YangInstanceIdentifier.EMPTY);
48         Mockito.doReturn(Futures.immediateCheckedFuture(Optional.of(data))).when(delegate)
49                 .read(YangInstanceIdentifier.EMPTY);
50
51         object = new ClientBackedReadTransaction(delegate, null, null);
52     }
53
54     @Test
55     public void testRead() throws Exception {
56         final ListenableFuture<Optional<NormalizedNode<?, ?>>> result = object().read(
57                 YangInstanceIdentifier.EMPTY);
58         final Optional<NormalizedNode<?, ?>> resultData = result.get();
59         Assert.assertTrue(resultData.isPresent());
60         Assert.assertEquals(data, resultData.get());
61     }
62
63     @Test
64     public void testExists() throws Exception {
65         final ListenableFuture<Boolean> result = object().exists(YangInstanceIdentifier.EMPTY);
66         Assert.assertTrue(result.get());
67     }
68 }