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
37 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
38 public class AbstractDataBrokerTestTest extends AbstractConcurrentDataBrokerTest {
40 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
43 public void before() {
44 assertThat(getDataBroker()).isNotNull();
48 public void aEnsureDataBrokerIsNotNull() {
49 assertThat(getDataBroker()).isNotNull();
53 public void bPutSomethingIntoDataStore() throws Exception {
55 assertThat(isTopInDataStore()).isTrue();
59 public void cEnsureDataStoreIsEmptyAgainInNewTest() throws ReadFailedException {
60 assertThat(isTopInDataStore()).isFalse();
63 // copy/pasted from Bug1125RegressionTest.writeInitialState()
64 private void writeInitialState() throws TransactionCommitFailedException {
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.submit().checkedGet();
73 private boolean isTopInDataStore() throws ReadFailedException {
74 ReadOnlyTransaction readTx = getDataBroker().newReadOnlyTransaction();
76 return readTx.read(LogicalDatastoreType.OPERATIONAL, TOP_PATH).checkedGet().isPresent();