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.store.inmemory;
10 import static org.mockito.Mockito.mock;
11 import static org.mockito.Mockito.reset;
13 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.Collection;
15 import java.util.HashSet;
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;
29 final class TestUtils {
31 static final DOMDataTreeIdentifier DOM_DATA_TREE_IDENTIFIER =
32 new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, YangInstanceIdentifier.EMPTY);
34 static final PathArgument PATH_ARGUMENT = mock(PathArgument.class);
36 static final NodeIdentifier NODE_IDENTIFIER = NodeIdentifier.create(QName.create("test"));
38 static final NormalizedNode<?, ?> NORMALIZED_NODE = mock(NormalizedNode.class);
40 static final NormalizedNodeContainer NORMALIZED_NODE_CONTAINER = mock(NormalizedNodeContainer.class);
42 static final DOMStoreThreePhaseCommitCohort DOM_STORE_THREE_PHASE_COMMIT_COHORT =
43 mock(DOMStoreThreePhaseCommitCohort.class);
45 static final Collection<DOMStoreThreePhaseCommitCohort> COHORTS = new HashSet<>();
47 static final ListenableFuture<?> LISTENABLE_FUTURE = mock(ListenableFuture.class);
49 static final WriteableModificationNode WRITEABLE_MODIFICATION_NODE = mock(WriteableModificationNode.class);
51 static final DOMDataTreeWriteCursor DOM_DATA_TREE_WRITE_CURSOR = mock(DOMDataTreeWriteCursor.class);
53 static final WriteCursorStrategy WRITE_CURSOR_STRATEGY = mock(WriteCursorStrategy.class);
55 static final DOMDataTreeShardProducer DOM_DATA_TREE_SHARD_PRODUCER = mock(DOMDataTreeShardProducer.class);
57 static final DOMDataTreeShardWriteTransaction DOM_DATA_TREE_SHARD_WRITE_TRANSACTION =
58 mock(DOMDataTreeShardWriteTransaction.class);
60 static final DataTree DATA_TREE = mock(DataTree.class);
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);
68 private TestUtils() throws UnsupportedOperationException {
69 throw new UnsupportedOperationException("Utility class should not be instantiated");
72 static ShardDataModification createModification(final ShardRootModificationContext root,
73 final Map<YangInstanceIdentifier, ForeignShardModificationContext> shards) {
75 final ShardDataModificationFactoryBuilder builder = new ShardDataModificationFactoryBuilder(
76 root.getIdentifier());
77 for (ForeignShardModificationContext subshard : shards.values()) {
78 builder.addSubshard(subshard);
81 final ShardDataModificationFactory factory = builder.build();
82 return new ShardDataModification(root, factory.getChildren(), factory.getChildShards());