2 * Copyright (c) 2016 Red Hat, 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.controller.md.sal.binding.test.tests;
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;
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;
33 * Integration tests the AbstractDataBrokerTest.
35 * @author Michael Vorburger
38 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
39 public class AbstractDataBrokerTestTest extends AbstractConcurrentDataBrokerTest {
41 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
44 public void before() {
45 assertThat(getDataBroker()).isNotNull();
49 public void aEnsureDataBrokerIsNotNull() {
50 assertThat(getDataBroker()).isNotNull();
54 public void bPutSomethingIntoDataStore() throws Exception {
56 assertThat(isTopInDataStore()).isTrue();
60 public void cEnsureDataStoreIsEmptyAgainInNewTest() throws ReadFailedException {
61 assertThat(isTopInDataStore()).isFalse();
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();
74 private boolean isTopInDataStore() throws ReadFailedException {
75 try (ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction()) {
76 return readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).checkedGet().isPresent();