390dc7019d910ff9a8c7c38274c931b233a3d0b5
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / databroker / actors / dds / ClientSnapshotTest.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.actors.dds;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.mockito.Mockito.verify;
13 import static org.mockito.Mockito.when;
14 import static org.opendaylight.controller.cluster.databroker.actors.dds.TestUtils.getWithTimeout;
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.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22
23 public class ClientSnapshotTest extends AbstractClientHandleTest<ClientSnapshot> {
24
25     private static final YangInstanceIdentifier PATH = YangInstanceIdentifier.empty();
26
27     @Before
28     @Override
29     public void setUp() throws Exception {
30         super.setUp();
31         when(getDataTreeSnapshot().readNode(PATH)).thenReturn(Optional.empty());
32     }
33
34     @Override
35     protected ClientSnapshot createHandle(final AbstractClientHistory parent) {
36         return parent.takeSnapshot();
37     }
38
39     @Override
40     protected void doHandleOperation(final ClientSnapshot snapshot) {
41         snapshot.read(PATH);
42     }
43
44     @Test
45     public void testExists() throws Exception {
46         final ListenableFuture<Boolean> exists = getHandle().exists(PATH);
47         verify(getDataTreeSnapshot()).readNode(PATH);
48         assertEquals(Boolean.FALSE, getWithTimeout(exists));
49     }
50
51     @Test
52     public void testRead() throws Exception {
53         final ListenableFuture<Optional<NormalizedNode<?, ?>>> exists = getHandle().read(PATH);
54         verify(getDataTreeSnapshot()).readNode(PATH);
55         assertFalse(getWithTimeout(exists).isPresent());
56     }
57
58 }