ca6c78f0cf43516f37329d6ae6ade0f3fb525185
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / Bug1418AugmentationTest.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.md.sal.binding.impl.test;
10
11 import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains;
12 import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty;
13 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
14 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment;
15 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.leafOnlyUsesAugment;
16 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.top;
17 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
18
19 import org.junit.Test;
20 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
21 import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest;
22 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker;
23 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
24 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUses;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey;
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.DataObject;
33 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
34
35 public class Bug1418AugmentationTest extends AbstractDataChangeListenerTest {
36     private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
37     private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
38     private static final InstanceIdentifier<TreeLeafOnlyUsesAugment> SIMPLE_AUGMENT =
39             TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeLeafOnlyUsesAugment.class);
40     private static final InstanceIdentifier<TreeComplexUsesAugment> COMPLEX_AUGMENT =
41             TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeComplexUsesAugment.class);
42     private static final ListViaUsesKey LIST_VIA_USES_KEY =
43             new ListViaUsesKey("list key");
44     private static final ListViaUsesKey LIST_VIA_USES_KEY_MOD =
45             new ListViaUsesKey("list key modified");
46
47     @Test
48     public void leafOnlyAugmentationCreatedTest() {
49         final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
50                 AsyncDataBroker.DataChangeScope.SUBTREE, false);
51         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
52         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
53         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
54         writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
55         assertCommit(writeTx.submit());
56         AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
57         assertContains(event.getCreatedData(), SIMPLE_AUGMENT);
58         assertEmpty(event.getUpdatedData());
59         assertEmpty(event.getOriginalData());
60         assertEmpty(event.getRemovedPaths());
61     }
62
63     @Test
64     public void leafOnlyAugmentationUpdatedTest() {
65         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
66         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
67         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
68         writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
69         assertCommit(writeTx.submit());
70         final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
71                 AsyncDataBroker.DataChangeScope.SUBTREE);
72         writeTx = getDataBroker().newWriteOnlyTransaction();
73         writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf changed"));
74         assertCommit(writeTx.submit());
75         AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
76         assertContains(event.getUpdatedData(), SIMPLE_AUGMENT);
77         assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
78         assertEmpty(event.getCreatedData());
79         assertEmpty(event.getRemovedPaths());
80     }
81
82     @Test
83     public void leafOnlyAugmentationDeletedTest() {
84         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
85         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
86         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
87         writeTx.put(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment("test leaf"));
88         assertCommit(writeTx.submit());
89         final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT,
90                 AsyncDataBroker.DataChangeScope.SUBTREE);
91         writeTx = getDataBroker().newWriteOnlyTransaction();
92         writeTx.delete(LogicalDatastoreType.CONFIGURATION, SIMPLE_AUGMENT);
93         assertCommit(writeTx.submit());
94         AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
95         assertContains(event.getRemovedPaths(), SIMPLE_AUGMENT);
96         assertContains(event.getOriginalData(), SIMPLE_AUGMENT);
97         assertEmpty(event.getCreatedData());
98         assertEmpty(event.getUpdatedData());
99     }
100
101     @Test
102     public void complexAugmentationCreatedTest() {
103         final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT,
104                 AsyncDataBroker.DataChangeScope.SUBTREE, false);
105         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
106         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
107         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
108         writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
109         assertCommit(writeTx.submit());
110         AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
111         assertContains(event.getCreatedData(), COMPLEX_AUGMENT);
112         assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
113         assertEmpty(event.getUpdatedData());
114         assertEmpty(event.getOriginalData());
115         assertEmpty(event.getRemovedPaths());
116     }
117
118     @Test
119     public void complexAugmentationUpdatedTest() {
120         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
121         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP, top());
122         writeTx.put(LogicalDatastoreType.CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
123         writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY));
124         assertCommit(writeTx.submit());
125         final TestListener listener = createListener(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT,
126                 AsyncDataBroker.DataChangeScope.SUBTREE);
127         writeTx = getDataBroker().newWriteOnlyTransaction();
128         writeTx.put(LogicalDatastoreType.CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment(LIST_VIA_USES_KEY_MOD));
129         assertCommit(writeTx.submit());
130         AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event = listener.event();
131         assertContains(event.getUpdatedData(), COMPLEX_AUGMENT);
132         assertContains(event.getCreatedData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY_MOD));
133         assertContains(event.getRemovedPaths(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
134         assertContains(event.getOriginalData(), COMPLEX_AUGMENT);
135         assertContains(event.getOriginalData(), COMPLEX_AUGMENT.child(ListViaUses.class, LIST_VIA_USES_KEY));
136     }
137 }

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