AbstractConcurrentDataBrokerTest @deprecate-s the AbstractDataBrokerTest
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / test / tests / AbstractDataBrokerTestTest.java
1 /*
2  * Copyright (c) 2016 Red Hat, 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.binding.dom.adapter.test.tests;
9
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotNull;
12 import static org.junit.Assert.assertTrue;
13 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
14 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.path;
15 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList;
16
17 import java.util.concurrent.ExecutionException;
18 import org.junit.Before;
19 import org.junit.FixMethodOrder;
20 import org.junit.Test;
21 import org.junit.runners.MethodSorters;
22 import org.opendaylight.mdsal.binding.api.ReadTransaction;
23 import org.opendaylight.mdsal.binding.api.WriteTransaction;
24 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractConcurrentDataBrokerTest;
25 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder;
31 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
32
33 /**
34  * Integration tests the AbstractDataBrokerTest.
35  *
36  * @author Michael Vorburger
37  */
38 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
39 public class AbstractDataBrokerTestTest extends AbstractConcurrentDataBrokerTest {
40     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
41
42     @Before
43     public void before() {
44         assertNotNull(getDataBroker());
45     }
46
47     @Test
48     public void aEnsureDataBrokerIsNotNull() {
49         assertNotNull(getDataBroker());
50     }
51
52     @Test
53     public void bPutSomethingIntoDataStore() throws Exception {
54         writeInitialState();
55         assertTrue(isTopInDataStore());
56     }
57
58     @Test
59     public void cEnsureDataStoreIsEmptyAgainInNewTest() throws Exception {
60         assertFalse(isTopInDataStore());
61     }
62
63     // copy/pasted from Bug1125RegressionTest.writeInitialState()
64     private void writeInitialState() throws InterruptedException, ExecutionException {
65         WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
66         initialTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
67         TreeComplexUsesAugment fooAugment = new TreeComplexUsesAugmentBuilder()
68                 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build()).build();
69         initialTx.put(LogicalDatastoreType.OPERATIONAL, path(TOP_FOO_KEY), topLevelList(TOP_FOO_KEY, fooAugment));
70         initialTx.commit().get();
71     }
72
73     private boolean isTopInDataStore() throws InterruptedException, ExecutionException {
74         try (ReadTransaction readTx = getDataBroker().newReadOnlyTransaction()) {
75             return readTx.exists(LogicalDatastoreType.OPERATIONAL, TOP_PATH).get();
76         }
77     }
78 }