Allow programmatic module sharding configuration
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / connect / dom / BrokerIntegrationTest.java
1 /*
2  * Copyright (c) 2014 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.sal.binding.test.connect.dom;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertTrue;
13
14 import com.google.common.base.Optional;
15 import java.util.concurrent.TimeUnit;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
18 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
25 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26
27 public class BrokerIntegrationTest extends AbstractDataServiceTest {
28
29     private static final TopLevelListKey TLL_FOO_KEY = new TopLevelListKey("foo");
30     private static final TopLevelListKey TLL_BAR_KEY = new TopLevelListKey("bar");
31     private static final TopLevelListKey TLL_BAZ_KEY = new TopLevelListKey("baz");
32     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.builder(Top.class).build();
33     private static final InstanceIdentifier<TopLevelList> FOO_PATH = TOP_PATH.child(TopLevelList.class, TLL_FOO_KEY);
34     private static final InstanceIdentifier<TopLevelList> BAR_PATH = TOP_PATH.child(TopLevelList.class, TLL_BAR_KEY);
35     private static final InstanceIdentifier<TopLevelList> BAZ_PATH = TOP_PATH.child(TopLevelList.class, TLL_BAZ_KEY);
36
37     @Test
38     public void simpleModifyOperation() throws Exception {
39
40         DataBroker dataBroker = testContext.getDataBroker();
41         Optional<TopLevelList> tllFoo = dataBroker.newReadOnlyTransaction().read(
42                 LogicalDatastoreType.CONFIGURATION, FOO_PATH).get(5, TimeUnit.SECONDS);
43         assertFalse(tllFoo.isPresent());
44
45         TopLevelList tllFooData = createTll(TLL_FOO_KEY);
46
47         final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
48         transaction.put(LogicalDatastoreType.CONFIGURATION, FOO_PATH, tllFooData);
49         transaction.submit().get(5, TimeUnit.SECONDS);
50
51         Optional<TopLevelList> readedData = dataBroker.newReadOnlyTransaction().read(
52                 LogicalDatastoreType.CONFIGURATION, FOO_PATH).get(5, TimeUnit.SECONDS);
53         assertTrue(readedData.isPresent());
54         assertEquals(tllFooData.key(), readedData.get().key());
55
56         TopLevelList nodeBarData = createTll(TLL_BAR_KEY);
57         TopLevelList nodeBazData = createTll(TLL_BAZ_KEY);
58
59         final WriteTransaction insertMoreTr = dataBroker.newWriteOnlyTransaction();
60         insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAR_PATH, nodeBarData);
61         insertMoreTr.put(LogicalDatastoreType.CONFIGURATION, BAZ_PATH, nodeBazData);
62         insertMoreTr.submit().get(5, TimeUnit.SECONDS);
63
64         Optional<Top> top = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.CONFIGURATION, TOP_PATH)
65                 .get(5, TimeUnit.SECONDS);
66         assertTrue(top.isPresent());
67         assertEquals(3, top.get().getTopLevelList().size());
68
69          // We create transaction no 2
70         final WriteTransaction removalTransaction = dataBroker.newWriteOnlyTransaction();
71
72          // We remove node 1
73         removalTransaction.delete(LogicalDatastoreType.CONFIGURATION, BAR_PATH);
74
75          // We commit transaction
76         removalTransaction.submit().get(5, TimeUnit.SECONDS);
77
78         Optional<TopLevelList> readedData2 = dataBroker.newReadOnlyTransaction().read(
79                 LogicalDatastoreType.CONFIGURATION, BAR_PATH).get(5, TimeUnit.SECONDS);
80         assertFalse(readedData2.isPresent());
81     }
82
83     private static TopLevelList createTll(final TopLevelListKey key) {
84         return new TopLevelListBuilder().withKey(key).build();
85     }
86 }

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