X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=dom%2Fmdsal-dom-api%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fapi%2FAbstractDOMDataTreeServiceTestSuite.java;fp=dom%2Fmdsal-dom-api%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fmd%2Fsal%2Fdom%2Fapi%2FAbstractDOMDataTreeServiceTestSuite.java;h=896c606eb9ce3a592e359e39ae045e5f42e1269b;hb=c9e43c3fa7ecc66546afb7eda8a1b5d5b15f4120;hp=0000000000000000000000000000000000000000;hpb=ecf38b90583e84c6362aaf32c24fd356f25d5e46;p=mdsal.git diff --git a/dom/mdsal-dom-api/src/test/java/org/opendaylight/controller/md/sal/dom/api/AbstractDOMDataTreeServiceTestSuite.java b/dom/mdsal-dom-api/src/test/java/org/opendaylight/controller/md/sal/dom/api/AbstractDOMDataTreeServiceTestSuite.java new file mode 100644 index 0000000000..896c606eb9 --- /dev/null +++ b/dom/mdsal-dom-api/src/test/java/org/opendaylight/controller/md/sal/dom/api/AbstractDOMDataTreeServiceTestSuite.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.controller.md.sal.dom.api; + +import static org.junit.Assert.assertNotNull; +import com.google.common.util.concurrent.CheckedFuture; +import java.net.URI; +import java.util.Collections; +import javax.annotation.Nonnull; +import org.junit.Test; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; +import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.common.QNameModule; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; +import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier; +import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; + +/** + * Abstract test suite demonstrating various access patterns on how a {@link DOMDataTreeService} + * can be used. + */ +public abstract class AbstractDOMDataTreeServiceTestSuite { + protected static final QNameModule TEST_MODULE = QNameModule.create(URI.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"), null); + + protected static final YangInstanceIdentifier UNORDERED_CONTAINER_IID = YangInstanceIdentifier.create( + new NodeIdentifier(QName.create(TEST_MODULE, "lists")), + new NodeIdentifier(QName.create(TEST_MODULE, "unordered-container"))); + protected static final DOMDataTreeIdentifier UNORDERED_CONTAINER_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID); + + /** + * Return a reference to the service used in this test. The instance + * needs to be reused within the same test and must be isolated between + * tests. + * + * @return {@link DOMDataTreeService} instance. + */ + protected abstract @Nonnull DOMDataTreeService service(); + + /** + * A simple unbound producer. It write some basic things into the data store based on the + * test model. + * @throws DOMDataTreeProducerException + * @throws TransactionCommitFailedException + */ + @Test + public final void testBasicProducer() throws DOMDataTreeProducerException, TransactionCommitFailedException { + // Create a producer. It is an AutoCloseable resource, hence the try-with pattern + try (final DOMDataTreeProducer prod = service().createProducer(Collections.singleton(UNORDERED_CONTAINER_TREE))) { + assertNotNull(prod); + + final DOMDataWriteTransaction tx = prod.createTransaction(true); + assertNotNull(tx); + + tx.put(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID, ImmutableContainerNodeBuilder.create().build()); + + final CheckedFuture f = tx.submit(); + assertNotNull(f); + + f.checkedGet(); + } + } + + // TODO: simple listener +}