d91267454aea067254771d13eb00b40b24478057
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / bugfix / DeleteNestedAugmentationListenParentTest.java
1 /*
2  * Copyright (c) 2014, 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
9 package org.opendaylight.controller.sal.binding.test.bugfix;
10
11 import com.google.common.collect.ImmutableSet;
12 import java.util.concurrent.ExecutionException;
13 import java.util.concurrent.TimeUnit;
14 import java.util.concurrent.TimeoutException;
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugment;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.List11SimpleAugmentBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Builder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
32 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
34
35 public class DeleteNestedAugmentationListenParentTest extends AbstractDataTreeChangeListenerTest {
36
37     private static final TopLevelListKey FOO_KEY = new TopLevelListKey("foo");
38
39     private static final List1Key LIST1_KEY = new List1Key("one");
40
41     private static final List11Key LIST11_KEY = new List11Key(100);
42
43     private static final InstanceIdentifier<TllComplexAugment> TLL_COMPLEX_AUGMENT_PATH = InstanceIdentifier
44             .builder(Top.class)
45             .child(TopLevelList.class,FOO_KEY)
46             .augmentation(TllComplexAugment.class)
47             .build();
48
49     private static final InstanceIdentifier<List11> LIST11_PATH = TLL_COMPLEX_AUGMENT_PATH.builder()
50             .child(List1.class,LIST1_KEY)
51             .child(List11.class,LIST11_KEY)
52             .build();
53
54     @Override
55     protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
56         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
57                 BindingReflections.getModuleInfo(List11SimpleAugment.class));
58     }
59
60     @Test
61     public void deleteChildListenParent() throws InterruptedException, ExecutionException, TimeoutException {
62         DataBroker dataBroker = getDataBroker();
63         final WriteTransaction initTx = dataBroker.newWriteOnlyTransaction();
64
65         List11 list11Before = createList11();
66         initTx.put(LogicalDatastoreType.OPERATIONAL, LIST11_PATH, list11Before, true);
67         initTx.submit().get(5, TimeUnit.SECONDS);
68
69         List11 list11After = new List11Builder().withKey(LIST11_KEY).setAttrStr("good").build();
70
71         final TestListener<List11> listener = createListener(LogicalDatastoreType.OPERATIONAL, LIST11_PATH,
72                 added(LIST11_PATH, list11Before), subtreeModified(LIST11_PATH, list11Before, list11After));
73
74         final WriteTransaction deleteTx = dataBroker.newWriteOnlyTransaction();
75         deleteTx.delete(LogicalDatastoreType.OPERATIONAL, LIST11_PATH.augmentation(List11SimpleAugment.class));
76         deleteTx.submit().get(5, TimeUnit.SECONDS);
77
78         listener.verify();
79     }
80
81     private static List11 createList11() {
82         List11Builder builder = new List11Builder()
83             .withKey(LIST11_KEY)
84             .addAugmentation(List11SimpleAugment.class,new List11SimpleAugmentBuilder()
85                     .setAttrStr2("bad").build())
86             .setAttrStr("good");
87         return builder.build();
88     }
89 }

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