Move transaction-invariants into producer
[mdsal.git] / dom / mdsal-dom-inmemory-datastore / src / test / java / org / opendaylight / mdsal / dom / store / inmemory / TestUtils.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.store.inmemory;
9
10 import static org.mockito.Mockito.mock;
11 import static org.mockito.Mockito.reset;
12
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.Collection;
15 import java.util.HashSet;
16 import java.util.Map;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
20 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
21 import org.opendaylight.yangtools.yang.common.QName;
22 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
23 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
25 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
26 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNodeContainer;
27 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
28
29 final class TestUtils {
30
31     static final DOMDataTreeIdentifier DOM_DATA_TREE_IDENTIFIER =
32             new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
33
34     static final PathArgument PATH_ARGUMENT = mock(PathArgument.class);
35
36     static final NodeIdentifier NODE_IDENTIFIER = NodeIdentifier.create(QName.create("test"));
37
38     static final NormalizedNode<?, ?> NORMALIZED_NODE = mock(NormalizedNode.class);
39
40     static final NormalizedNodeContainer NORMALIZED_NODE_CONTAINER = mock(NormalizedNodeContainer.class);
41
42     static final DOMStoreThreePhaseCommitCohort DOM_STORE_THREE_PHASE_COMMIT_COHORT =
43             mock(DOMStoreThreePhaseCommitCohort.class);
44
45     static final Collection<DOMStoreThreePhaseCommitCohort> COHORTS = new HashSet<>();
46
47     static final ListenableFuture<?> LISTENABLE_FUTURE = mock(ListenableFuture.class);
48
49     static final WriteableModificationNode WRITEABLE_MODIFICATION_NODE = mock(WriteableModificationNode.class);
50
51     static final DOMDataTreeWriteCursor DOM_DATA_TREE_WRITE_CURSOR = mock(DOMDataTreeWriteCursor.class);
52
53     static final WriteCursorStrategy WRITE_CURSOR_STRATEGY = mock(WriteCursorStrategy.class);
54
55     static final DOMDataTreeShardProducer DOM_DATA_TREE_SHARD_PRODUCER = mock(DOMDataTreeShardProducer.class);
56
57     static final DOMDataTreeShardWriteTransaction DOM_DATA_TREE_SHARD_WRITE_TRANSACTION =
58             mock(DOMDataTreeShardWriteTransaction.class);
59
60     static final DataTree DATA_TREE = mock(DataTree.class);
61
62     static void resetMocks() {
63         reset(WRITE_CURSOR_STRATEGY, DOM_DATA_TREE_WRITE_CURSOR, WRITEABLE_MODIFICATION_NODE, LISTENABLE_FUTURE,
64                 DOM_STORE_THREE_PHASE_COMMIT_COHORT, NORMALIZED_NODE_CONTAINER, NORMALIZED_NODE, PATH_ARGUMENT,
65                 DOM_DATA_TREE_SHARD_PRODUCER, DOM_DATA_TREE_SHARD_WRITE_TRANSACTION, DATA_TREE);
66     }
67
68     private TestUtils() throws UnsupportedOperationException {
69         throw new UnsupportedOperationException("Utility class should not be instantiated");
70     }
71
72     static ShardDataModification createModification(final ShardRootModificationContext root,
73             final Map<YangInstanceIdentifier, ForeignShardModificationContext> shards) {
74
75         final ShardDataModificationFactoryBuilder builder = new ShardDataModificationFactoryBuilder(
76             root.getIdentifier());
77         for (ForeignShardModificationContext subshard : shards.values()) {
78             builder.addSubshard(subshard);
79         }
80
81         final ShardDataModificationFactory factory = builder.build();
82         return new ShardDataModification(root, factory.getChildren(), factory.getChildShards());
83     }
84
85 }