2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.mdsal.dom.spi.shard;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertTrue;
12 import static org.mockito.Mockito.doNothing;
13 import static org.mockito.Mockito.doReturn;
14 import static org.mockito.Mockito.only;
15 import static org.mockito.Mockito.verify;
17 import org.junit.After;
18 import org.junit.Test;
20 public class ForeignShardModificationContextTest {
23 public void basicTest() throws Exception {
24 final ForeignShardModificationContext foreignShardModificationContext =
25 new ForeignShardModificationContext(TestUtils.DOM_DATA_TREE_IDENTIFIER,
26 TestUtils.DOM_DATA_TREE_SHARD_PRODUCER);
27 doReturn("testTransaction").when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).toString();
28 assertFalse(foreignShardModificationContext.isModified());
29 doReturn(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION)
30 .when(TestUtils.DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
31 doReturn(TestUtils.DOM_DATA_TREE_WRITE_CURSOR)
32 .when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(TestUtils.DOM_DATA_TREE_IDENTIFIER);
33 foreignShardModificationContext.getCursor();
34 verify(TestUtils.DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
35 verify(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(TestUtils.DOM_DATA_TREE_IDENTIFIER);
36 assertTrue(foreignShardModificationContext.isModified());
38 doNothing().when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).ready();
39 doNothing().when(TestUtils.DOM_DATA_TREE_WRITE_CURSOR).close();
40 foreignShardModificationContext.ready();
41 verify(TestUtils.DOM_DATA_TREE_WRITE_CURSOR, only()).close();
42 verify(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).ready();
44 doReturn(null).when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
45 foreignShardModificationContext.validate();
46 verify(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).validate();
48 doReturn(null).when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
49 foreignShardModificationContext.prepare();
50 verify(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).prepare();
52 doReturn(null).when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
53 foreignShardModificationContext.submit();
54 verify(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).commit();
58 public void basicTestClose() throws Exception {
59 final ForeignShardModificationContext foreignShardModificationContext =
60 new ForeignShardModificationContext(TestUtils.DOM_DATA_TREE_IDENTIFIER,
61 TestUtils.DOM_DATA_TREE_SHARD_PRODUCER);
62 doReturn(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION)
63 .when(TestUtils.DOM_DATA_TREE_SHARD_PRODUCER).createTransaction();
64 doReturn(TestUtils.DOM_DATA_TREE_WRITE_CURSOR)
65 .when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).createCursor(TestUtils.DOM_DATA_TREE_IDENTIFIER);
66 doNothing().when(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).close();
67 doNothing().when(TestUtils.DOM_DATA_TREE_WRITE_CURSOR).close();
68 foreignShardModificationContext.getCursor();
69 foreignShardModificationContext.closeForeignTransaction();
70 verify(TestUtils.DOM_DATA_TREE_WRITE_CURSOR).close();
71 verify(TestUtils.DOM_DATA_TREE_SHARD_WRITE_TRANSACTION).close();
76 TestUtils.resetMocks();