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

©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.