Merge "Removing { } from NormalizedNodeJsonBodyWriter"
[controller.git] / opendaylight / md-sal / sal-dom-api / src / test / java / org / opendaylight / controller / md / sal / dom / api / AbstractDOMDataTreeServiceTestSuite.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, 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.dom.api;
9
10 import static org.junit.Assert.assertNotNull;
11 import com.google.common.util.concurrent.CheckedFuture;
12 import java.net.URI;
13 import java.util.Collections;
14 import javax.annotation.Nonnull;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
17 import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.common.QNameModule;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
21 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
22 import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
23
24 /**
25  * Abstract test suite demonstrating various access patterns on how a {@link DOMDataTreeService}
26  * can be used.
27  */
28 public abstract class AbstractDOMDataTreeServiceTestSuite {
29     protected static final QNameModule TEST_MODULE = QNameModule.create(URI.create("urn:opendaylight:params:xml:ns:yang:controller:md:sal:test:store"), null);
30
31     protected static final YangInstanceIdentifier UNORDERED_CONTAINER_IID = YangInstanceIdentifier.create(
32         new NodeIdentifier(QName.create(TEST_MODULE, "lists")),
33         new NodeIdentifier(QName.create(TEST_MODULE, "unordered-container")));
34     protected static final DOMDataTreeIdentifier UNORDERED_CONTAINER_TREE = new DOMDataTreeIdentifier(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID);
35
36     /**
37      * Return a reference to the service used in this test. The instance
38      * needs to be reused within the same test and must be isolated between
39      * tests.
40      *
41      * @return {@link DOMDataTreeService} instance.
42      */
43     protected abstract @Nonnull DOMDataTreeService service();
44
45     /**
46      * A simple unbound producer. It write some basic things into the data store based on the
47      * test model.
48      * @throws DOMDataTreeProducerException
49      * @throws TransactionCommitFailedException
50      */
51     @Test
52     public final void testBasicProducer() throws DOMDataTreeProducerException, TransactionCommitFailedException {
53         // Create a producer. It is an AutoCloseable resource, hence the try-with pattern
54         try (final DOMDataTreeProducer prod = service().createProducer(Collections.singleton(UNORDERED_CONTAINER_TREE))) {
55             assertNotNull(prod);
56
57             final DOMDataWriteTransaction tx = prod.createTransaction(true);
58             assertNotNull(tx);
59
60             tx.put(LogicalDatastoreType.OPERATIONAL, UNORDERED_CONTAINER_IID, ImmutableContainerNodeBuilder.create().build());
61
62             final CheckedFuture<Void, TransactionCommitFailedException> f = tx.submit();
63             assertNotNull(f);
64
65             f.checkedGet();
66         }
67     }
68
69     // TODO: simple listener
70 }