Make REUSABLE_*_TL final
[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
9 package org.opendaylight.controller.cluster.datastore.modification;
10
11 import com.google.common.base.Optional;
12 import com.google.common.util.concurrent.ListenableFuture;
13 import com.google.common.util.concurrent.MoreExecutors;
14 import org.junit.Before;
15 import org.opendaylight.controller.md.cluster.datastore.model.TestModel;
16 import org.opendaylight.controller.md.sal.dom.store.impl.InMemoryDOMDataStore;
17 import org.opendaylight.controller.sal.core.spi.data.DOMStoreReadTransaction;
18 import org.opendaylight.controller.sal.core.spi.data.DOMStoreThreePhaseCommitCohort;
19 import org.opendaylight.controller.sal.core.spi.data.DOMStoreWriteTransaction;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
22
23 public abstract class AbstractModificationTest {
24
25   protected InMemoryDOMDataStore store;
26
27   @Before
28   public void setUp(){
29     store = new InMemoryDOMDataStore("test", MoreExecutors.sameThreadExecutor());
30     store.onGlobalContextUpdated(TestModel.createTestContext());
31   }
32
33   protected void commitTransaction(final DOMStoreWriteTransaction transaction){
34     DOMStoreThreePhaseCommitCohort cohort = transaction.ready();
35     cohort.preCommit();
36     cohort.commit();
37   }
38
39   protected Optional<NormalizedNode<?,?>> readData(final YangInstanceIdentifier path) throws Exception{
40     DOMStoreReadTransaction transaction = store.newReadOnlyTransaction();
41     ListenableFuture<Optional<NormalizedNode<?, ?>>> future = transaction.read(path);
42     return future.get();
43   }
44 }