Clean up ClientBackedReadTransactionTest
[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 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;
15
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;
27
28 @RunWith(MockitoJUnitRunner.StrictStubs.class)
29 public class ClientBackedReadTransactionTest extends ClientBackedTransactionTest<ClientBackedReadTransaction> {
30     private ClientBackedReadTransaction object;
31
32     @Mock
33     private NormalizedNode data;
34     @Mock
35     private ClientActorContext clientContext;
36     @Mock
37     private ClientSnapshot delegate;
38
39     @Override
40     ClientBackedReadTransaction object() {
41         return object;
42     }
43
44     @Before
45     public void setUp() {
46         doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
47
48         doReturn(immediateTrueFluentFuture()).when(delegate).exists(YangInstanceIdentifier.empty());
49         doReturn(immediateFluentFuture(Optional.of(data))).when(delegate).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(YangInstanceIdentifier.empty());
57         final Optional<NormalizedNode> resultData = result.get();
58         assertTrue(resultData.isPresent());
59         assertEquals(data, resultData.get());
60     }
61
62     @Test
63     public void testExists() throws Exception {
64         final ListenableFuture<Boolean> result = object().exists(YangInstanceIdentifier.empty());
65         assertEquals(Boolean.TRUE, result.get());
66     }
67 }