atomic-storage: remove type dependency at segment level I/O
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / ClientBackedReadWriteTransactionTest.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.FluentFuture;
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.databroker.actors.dds.ClientTransaction;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26
27 @RunWith(MockitoJUnitRunner.StrictStubs.class)
28 public class ClientBackedReadWriteTransactionTest
29         extends ClientBackedTransactionTest<ClientBackedReadWriteTransaction> {
30     private ClientBackedReadWriteTransaction object;
31
32     @Mock
33     private ClientTransaction delegate;
34     @Mock
35     private NormalizedNode data;
36
37     @Override
38     ClientBackedReadWriteTransaction object() {
39         return object;
40     }
41
42     @Before
43     public void setUp() {
44         doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
45
46         doReturn(immediateTrueFluentFuture()).when(delegate).exists(YangInstanceIdentifier.empty());
47         doReturn(immediateFluentFuture(Optional.of(data))).when(delegate).read(YangInstanceIdentifier.empty());
48
49         object = new ClientBackedReadWriteTransaction(delegate, null);
50     }
51
52     @Test
53     public void testRead() throws Exception {
54         final FluentFuture<Optional<NormalizedNode>> result = object().read(YangInstanceIdentifier.empty());
55         final Optional<NormalizedNode> resultData = result.get();
56         assertTrue(resultData.isPresent());
57         assertEquals(data, resultData.get());
58     }
59
60     @Test
61     public void testExists() throws Exception {
62         assertEquals(Boolean.TRUE, object().exists(YangInstanceIdentifier.empty()).get());
63     }
64 }