2 * Copyright (c) 2015 Cisco Systems, 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.dom.api;
10 import static org.junit.Assert.assertNotNull;
12 import com.google.common.util.concurrent.ListenableFuture;
14 import java.util.Collections;
15 import java.util.concurrent.ExecutionException;
16 import org.eclipse.jdt.annotation.NonNull;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.mdsal.dom.api.DOMDataTreeCursorAwareTransaction;
20 import org.opendaylight.mdsal.dom.api.DOMDataTreeIdentifier;
21 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducer;
22 import org.opendaylight.mdsal.dom.api.DOMDataTreeProducerException;
23 import org.opendaylight.mdsal.dom.api.DOMDataTreeService;
24 import org.opendaylight.mdsal.dom.api.DOMDataTreeWriteCursor;
25 import org.opendaylight.yangtools.yang.common.QName;
26 import org.opendaylight.yangtools.yang.common.QNameModule;
27 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
28 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
29 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
32 * Abstract test suite demonstrating various access patterns on how a {@link DOMDataTreeService}
35 public abstract class AbstractDOMDataTreeServiceTestSuite {
36 protected static final QNameModule TEST_MODULE =
37 QNameModule.create(URI.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"));
39 protected static final YangInstanceIdentifier UNORDERED_CONTAINER_IID = YangInstanceIdentifier.create(
40 new NodeIdentifier(QName.create(TEST_MODULE, "lists")),
41 new NodeIdentifier(QName.create(TEST_MODULE, "unordered-container")));
42 protected static final DOMDataTreeIdentifier UNORDERED_CONTAINER_TREE
43 = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID);
46 * Return a reference to the service used in this test. The instance
47 * needs to be reused within the same test and must be isolated between
50 * @return {@link DOMDataTreeService} instance.
52 protected abstract @NonNull DOMDataTreeService service();
55 * A simple unbound producer. It write some basic things into the data store based on the
58 * @throws DOMDataTreeProducerException when this exceptional condition happens
61 public final void testBasicProducer() throws DOMDataTreeProducerException, InterruptedException,
63 // Create a producer. It is an AutoCloseable resource, hence the try-with pattern
64 try (DOMDataTreeProducer prod =
65 service().createProducer(Collections.singleton(UNORDERED_CONTAINER_TREE))) {
68 final DOMDataTreeCursorAwareTransaction tx = prod.createTransaction(true);
71 final DOMDataTreeWriteCursor cursor =
72 tx.createCursor(new DOMDataTreeIdentifier(
73 LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID));
74 assertNotNull(cursor);
75 cursor.write(UNORDERED_CONTAINER_IID.getLastPathArgument(), ImmutableContainerNodeBuilder.create().build());
78 final ListenableFuture<?> f = tx.commit();
85 // TODO: simple listener