BUG-8372: fix abort message confusion
[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.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;
24
25 public class ClientBackedReadTransactionTest extends ClientBackedTransactionTest<ClientBackedReadTransaction> {
26     private ClientBackedReadTransaction object;
27
28     @Mock
29     private NormalizedNode<?, ?> data;
30     @Mock
31     private ClientActorContext clientContext;
32     @Mock
33     private ClientSnapshot delegate;
34
35     @Override
36     ClientBackedReadTransaction object() throws Exception {
37         return object;
38     }
39
40     @Before
41     public void setUp() throws Exception {
42         MockitoAnnotations.initMocks(this);
43
44         Mockito.doReturn(CLIENT_ID).when(clientContext).getIdentifier();
45         Mockito.doReturn(TRANSACTION_ID).when(delegate).getIdentifier();
46
47         Mockito.doReturn(Futures.immediateCheckedFuture(Boolean.TRUE)).when(delegate)
48                 .exists(YangInstanceIdentifier.EMPTY);
49         Mockito.doReturn(Futures.immediateCheckedFuture(Optional.of(data))).when(delegate)
50                 .read(YangInstanceIdentifier.EMPTY);
51
52         object = new ClientBackedReadTransaction(delegate, null);
53     }
54
55     @Test
56     public void testRead() throws Exception {
57         final CheckedFuture<Optional<NormalizedNode<?, ?>>, ReadFailedException> result = object().read(
58                 YangInstanceIdentifier.EMPTY);
59         final Optional<NormalizedNode<?, ?>> resultData = result.get();
60         Assert.assertTrue(resultData.isPresent());
61         Assert.assertEquals(data, resultData.get());
62     }
63
64     @Test
65     public void testExists() throws Exception {
66         final CheckedFuture<Boolean, ReadFailedException> result = object().exists(YangInstanceIdentifier.EMPTY);
67         Assert.assertTrue(result.get());
68     }
69 }