2ec1c43c9be4c4d65a8a4f0a98a96f305a8f962e
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / ForwardedBackwardsCompatibleDataBrokerTest.java
1 package org.opendaylight.controller.md.sal.binding.impl.test;
2
3 import com.google.common.util.concurrent.MoreExecutors;
4 import org.junit.Test;
5 import org.opendaylight.controller.md.sal.binding.impl.ForwardedBackwardsCompatibleDataBroker;
6 import org.opendaylight.controller.md.sal.binding.test.AbstractSchemaAwareTest;
7 import org.opendaylight.controller.md.sal.binding.test.DataBrokerTestCustomizer;
8 import org.opendaylight.controller.md.sal.dom.api.DOMDataBroker;
9 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
14 import org.opendaylight.yangtools.yang.binding.DataObject;
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
16 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
17
18 import java.util.concurrent.ExecutionException;
19
20 import static junit.framework.TestCase.assertNotNull;
21
22 public class ForwardedBackwardsCompatibleDataBrokerTest extends
23     AbstractSchemaAwareTest {
24
25     private DataBrokerTestCustomizer testCustomizer;
26     private ForwardedBackwardsCompatibleDataBroker dataBroker;
27     private DOMDataBroker domBroker;
28
29     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
30     private static final TopLevelListKey TOP_LIST_KEY = new TopLevelListKey("foo");
31     private static final InstanceIdentifier<TopLevelList> NODE_PATH = TOP_PATH.child(TopLevelList.class, TOP_LIST_KEY);
32     private static final TopLevelList NODE = new TopLevelListBuilder().setKey(TOP_LIST_KEY).build();
33
34     protected DataBrokerTestCustomizer createDataBrokerTestCustomizer() {
35         return new DataBrokerTestCustomizer();
36     }
37
38     @Override
39     protected void setupWithSchema(final SchemaContext context) {
40         testCustomizer = createDataBrokerTestCustomizer();
41
42         domBroker = testCustomizer.createDOMDataBroker();
43         dataBroker = createBackwardsCompatibleDataBroker();
44         testCustomizer.updateSchema(context);
45     }
46
47     public ForwardedBackwardsCompatibleDataBroker createBackwardsCompatibleDataBroker() {
48         return new ForwardedBackwardsCompatibleDataBroker(domBroker, testCustomizer.getBindingToNormalized(), testCustomizer.getSchemaService(), MoreExecutors
49             .sameThreadExecutor());
50     }
51
52
53
54
55     /**
56      * The purpose of this test is to exercise the backwards compatible broker
57      * <p>
58      * This test tries to execute the code which ensures that the parents
59      * for a given node get automatically created.
60      *
61      * @see org.opendaylight.controller.md.sal.binding.impl.AbstractReadWriteTransaction#ensureParentsByMerge(org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType, org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier, org.opendaylight.yangtools.yang.binding.InstanceIdentifier)
62      */
63     @Test
64     public void testEnsureParentsByMerge() throws InterruptedException, ExecutionException {
65         DataModificationTransaction writeTx =
66             dataBroker.beginTransaction();
67
68         writeTx.putOperationalData(NODE_PATH, NODE);
69
70         writeTx.commit();
71
72         // TOP_PATH should exist as it is the parent of NODE_PATH
73         DataObject object = dataBroker.readOperationalData(TOP_PATH);
74
75         assertNotNull(object);
76
77     }
78
79
80 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.