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