Bump odlparent/yangtools/mdsal
[controller.git] / opendaylight / md-sal / sal-distributed-datastore / src / test / java / org / opendaylight / controller / cluster / datastore / modification / AbstractModificationTest.java
1 /*
2  * Copyright (c) 2014 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.controller.cluster.datastore.modification;
9
10 import com.google.common.util.concurrent.ListenableFuture;
11 import com.google.common.util.concurrent.MoreExecutors;
12 import java.util.Optional;
13 import org.junit.AfterClass;
14 import org.junit.Before;
15 import org.junit.BeforeClass;
16 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
17 import org.opendaylight.mdsal.dom.spi.store.DOMStoreReadTransaction;
18 import org.opendaylight.mdsal.dom.spi.store.DOMStoreThreePhaseCommitCohort;
19 import org.opendaylight.mdsal.dom.spi.store.DOMStoreWriteTransaction;
20 import org.opendaylight.mdsal.dom.store.inmemory.InMemoryDOMDataStore;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23 import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
24
25 public abstract class AbstractModificationTest {
26     private static EffectiveModelContext TEST_SCHEMA_CONTEXT;
27
28     protected InMemoryDOMDataStore store;
29
30     @BeforeClass
31     public static void beforeClass() {
32         TEST_SCHEMA_CONTEXT = TestModel.createTestContext();
33     }
34
35     @AfterClass
36     public static void afterClass() {
37         TEST_SCHEMA_CONTEXT = null;
38     }
39
40     @Before
41     public void setUp() {
42         store = new InMemoryDOMDataStore("test", MoreExecutors.newDirectExecutorService());
43         store.onModelContextUpdated(TEST_SCHEMA_CONTEXT);
44     }
45
46     protected void commitTransaction(final DOMStoreWriteTransaction transaction) {
47         DOMStoreThreePhaseCommitCohort cohort = transaction.ready();
48         cohort.preCommit();
49         cohort.commit();
50     }
51
52     protected Optional<NormalizedNode<?, ?>> readData(final YangInstanceIdentifier path) throws Exception {
53         DOMStoreReadTransaction transaction = store.newReadOnlyTransaction();
54         ListenableFuture<Optional<NormalizedNode<?, ?>>> future = transaction.read(path);
55         return future.get();
56     }
57 }