Migrate OSGI compendium reference
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / 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.controller.md.sal.binding.test.tests;
9
10 import static com.google.common.truth.Truth.assertThat;
11 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
12 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path;
13 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
14
15 import org.junit.Before;
16 import org.junit.FixMethodOrder;
17 import org.junit.Test;
18 import org.junit.runners.MethodSorters;
19 import org.opendaylight.controller.md.sal.binding.api.ReadOnlyTransaction;
20 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
21 import org.opendaylight.controller.md.sal.binding.test.AbstractConcurrentDataBrokerTest;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
24 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31
32 /**
33  * Integration tests the AbstractDataBrokerTest.
34  *
35  * @author Michael Vorburger
36  */
37 @Deprecated
38 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
39 public class AbstractDataBrokerTestTest extends AbstractConcurrentDataBrokerTest {
40
41     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
42
43     @Before
44     public void before() {
45         assertThat(getDataBroker()).isNotNull();
46     }
47
48     @Test
49     public void aEnsureDataBrokerIsNotNull() {
50         assertThat(getDataBroker()).isNotNull();
51     }
52
53     @Test
54     public void bPutSomethingIntoDataStore() throws Exception {
55         writeInitialState();
56         assertThat(isTopInDataStore()).isTrue();
57     }
58
59     @Test
60     public void cEnsureDataStoreIsEmptyAgainInNewTest() throws ReadFailedException {
61         assertThat(isTopInDataStore()).isFalse();
62     }
63
64     // copy/pasted from Bug1125RegressionTest.writeInitialState()
65     private void writeInitialState() throws TransactionCommitFailedException {
66         WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
67         initialTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
68         TreeComplexUsesAugment fooAugment = new TreeComplexUsesAugmentBuilder()
69                 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build()).build();
70         initialTx.put(LogicalDatastoreType.OPERATIONAL, path(TOP_FOO_KEY), topLevelList(TOP_FOO_KEY, fooAugment));
71         initialTx.submit().checkedGet();
72     }
73
74     private boolean isTopInDataStore() throws ReadFailedException {
75         try (ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction()) {
76             return readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).checkedGet().isPresent();
77         }
78     }
79
80 }