Migrate from YangInstanceIdentifier.EMPTY
[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.mockito.Mock;
21 import org.mockito.MockitoAnnotations;
22 import org.opendaylight.controller.cluster.databroker.actors.dds.ClientTransaction;
23 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26
27 public class ClientBackedReadWriteTransactionTest
28         extends ClientBackedTransactionTest<ClientBackedReadWriteTransaction> {
29     private ClientBackedReadWriteTransaction object;
30
31     @Mock
32     private ClientTransaction delegate;
33     @Mock
34     private NormalizedNode<?, ?> data;
35     @Mock
36     private DOMStoreThreePhaseCommitCohort readyCohort;
37
38     @Override
39     ClientBackedReadWriteTransaction object() {
40         return object;
41     }
42
43     @Before
44     public void setUp() {
45         MockitoAnnotations.initMocks(this);
46
47         doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
48         doReturn(readyCohort).when(delegate).ready();
49
50         doReturn(immediateTrueFluentFuture()).when(delegate).exists(YangInstanceIdentifier.empty());
51         doReturn(immediateFluentFuture(Optional.of(data))).when(delegate).read(YangInstanceIdentifier.empty());
52
53         object = new ClientBackedReadWriteTransaction(delegate, null);
54     }
55
56     @Test
57     public void testRead() throws Exception {
58         final FluentFuture<Optional<NormalizedNode<?, ?>>> result = object().read(YangInstanceIdentifier.empty());
59         final Optional<NormalizedNode<?, ?>> resultData = result.get();
60         assertTrue(resultData.isPresent());
61         assertEquals(data, resultData.get());
62     }
63
64     @Test
65     public void testExists() throws Exception {
66         assertEquals(Boolean.TRUE, object().exists(YangInstanceIdentifier.empty()).get());
67     }
68 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.