83f62411f264d26f8d1fcefaea3d91b189353195
[mdsal.git] / dom / mdsal-dom-spi / src / test / java / org / opendaylight / mdsal / dom / spi / shard / DelegatingReadableCursorOperationTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. 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.mdsal.dom.spi.shard;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.mock;
15 import static org.mockito.Mockito.verify;
16
17 import java.util.Optional;
18 import org.junit.After;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
21 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshotCursor;
22
23 public class DelegatingReadableCursorOperationTest extends DelegatingReadableCursorOperation {
24
25     private static final DataTreeSnapshotCursor MOCK_CURSOR_SNAPSHOT = mock(DataTreeSnapshotCursor.class);
26
27     @Test
28     public void basicTest() throws Exception {
29         final Optional<NormalizedNode<?, ?>> nodeOptional = Optional.empty();
30         doReturn(nodeOptional).when(MOCK_CURSOR_SNAPSHOT).readNode(TestUtils.PATH_ARGUMENT);
31         doNothing().when(MOCK_CURSOR_SNAPSHOT).exit();
32         doNothing().when(MOCK_CURSOR_SNAPSHOT).enter(TestUtils.PATH_ARGUMENT);
33         doReturn("test").when(TestUtils.PATH_ARGUMENT).toString();
34
35         assertFalse(readNode(TestUtils.PATH_ARGUMENT).isPresent());
36         verify(MOCK_CURSOR_SNAPSHOT).readNode(TestUtils.PATH_ARGUMENT);
37
38         exit();
39         verify(MOCK_CURSOR_SNAPSHOT).exit();
40
41         assertEquals(this, enter(TestUtils.PATH_ARGUMENT));
42         verify(MOCK_CURSOR_SNAPSHOT).enter(TestUtils.PATH_ARGUMENT);
43     }
44
45     @Override
46     protected DataTreeSnapshotCursor delegate() {
47         return MOCK_CURSOR_SNAPSHOT;
48     }
49
50     @After
51     public void reset() {
52         TestUtils.resetMocks();
53     }
54 }