Bug 2682 - Switch sal-binding-dom-it to sal-test-model
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / bugfix / WriteParentListenAugmentTest.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
9 package org.opendaylight.controller.sal.binding.test.bugfix;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.concurrent.TimeUnit;
15
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
18 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
19 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
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.augment.rev140709.TreeComplexUsesAugment;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31
32 import com.google.common.util.concurrent.SettableFuture;
33
34 @SuppressWarnings("deprecation")
35 public class WriteParentListenAugmentTest extends AbstractDataServiceTest {
36
37     private static final String TLL_NAME = "foo";
38
39     private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
40     private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) //
41             .child(TopLevelList.class, TLL_KEY).toInstance();
42
43     private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_WILDCARDED_PATH = InstanceIdentifier
44             .builder(Top.class).child(TopLevelList.class).augmentation(TreeComplexUsesAugment.class).toInstance();
45
46     private static final InstanceIdentifier<TreeComplexUsesAugment> AUGMENT_TLL_PATH = InstanceIdentifier
47             .builder(Top.class).child(TopLevelList.class, TLL_KEY).augmentation(TreeComplexUsesAugment.class).toInstance();
48
49     @Test
50     public void writeNodeListenAugment() throws Exception {
51
52         final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
53
54         ListenerRegistration<DataChangeListener> dclRegistration = baDataService.registerDataChangeListener(
55                 AUGMENT_WILDCARDED_PATH, new DataChangeListener() {
56
57                     @Override
58                     public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
59                         event.set(change);
60                     }
61                 });
62
63         DataModificationTransaction modification = baDataService.beginTransaction();
64
65         TopLevelList tll = new TopLevelListBuilder() //
66                 .setKey(TLL_KEY) //
67                 .addAugmentation(TreeComplexUsesAugment.class, treeComplexUsesAugment("one")).build();
68         modification.putOperationalData(TLL_INSTANCE_ID_BA, tll);
69         modification.commit().get();
70
71         DataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
72         assertTrue(receivedEvent.getCreatedOperationalData().containsKey(AUGMENT_TLL_PATH));
73
74         dclRegistration.close();
75
76         DataModificationTransaction mod2 = baDataService.beginTransaction();
77         mod2.putOperationalData(AUGMENT_TLL_PATH, treeComplexUsesAugment("two"));
78         mod2.commit().get();
79
80         TreeComplexUsesAugment readedAug = (TreeComplexUsesAugment) baDataService.readOperationalData(AUGMENT_TLL_PATH);
81         assertEquals("two", readedAug.getContainerWithUses().getLeafFromGrouping());
82
83     }
84
85     private TreeComplexUsesAugment treeComplexUsesAugment(final String value) {
86         return new TreeComplexUsesAugmentBuilder() //
87                 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping(value).build()) //
88                 .build();
89     }
90 }

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