7c114e7ef98d481df4e2361685504b52cc6118ce
[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.common.api.data.LogicalDatastoreType.CONFIGURATION;
12 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
13 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.complexUsesAugment;
14 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.leafOnlyUsesAugment;
15 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path;
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 com.google.common.collect.ImmutableSet;
20 import org.junit.Test;
21 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
22 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
23 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeLeafOnlyUsesAugment;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ListViaUsesKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
32
33 public class Bug1418AugmentationTest extends AbstractDataTreeChangeListenerTest {
34     private static final InstanceIdentifier<Top> TOP = InstanceIdentifier.create(Top.class);
35     private static final InstanceIdentifier<TopLevelList> TOP_FOO = TOP.child(TopLevelList.class, TOP_FOO_KEY);
36     private static final InstanceIdentifier<TreeLeafOnlyUsesAugment> SIMPLE_AUGMENT =
37             TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeLeafOnlyUsesAugment.class);
38     private static final InstanceIdentifier<TreeComplexUsesAugment> COMPLEX_AUGMENT =
39             TOP.child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeComplexUsesAugment.class);
40     private static final ListViaUsesKey LIST_VIA_USES_KEY =
41             new ListViaUsesKey("list key");
42     private static final ListViaUsesKey LIST_VIA_USES_KEY_MOD =
43             new ListViaUsesKey("list key modified");
44
45     @Override
46     protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
47         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
48                 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class),
49                 BindingReflections.getModuleInfo(TreeLeafOnlyUsesAugment.class));
50     }
51
52     @Test
53     public void leafOnlyAugmentationCreatedTest() {
54         TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
55         final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
56                 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
57
58         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
59         writeTx.put(CONFIGURATION, TOP, top());
60         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
61         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
62         assertCommit(writeTx.submit());
63
64         listener.verify();
65     }
66
67     @Test
68     public void leafOnlyAugmentationUpdatedTest() {
69         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
70         writeTx.put(CONFIGURATION, TOP, top());
71         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
72         TreeLeafOnlyUsesAugment leafOnlyUsesAugmentBefore = leafOnlyUsesAugment("test leaf");
73         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentBefore);
74         assertCommit(writeTx.submit());
75
76         TreeLeafOnlyUsesAugment leafOnlyUsesAugmentAfter = leafOnlyUsesAugment("test leaf changed");
77         final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
78                 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore),
79                 replaced(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore,
80                     leafOnlyUsesAugmentAfter));
81
82         writeTx = getDataBroker().newWriteOnlyTransaction();
83         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentAfter);
84         assertCommit(writeTx.submit());
85
86         listener.verify();
87     }
88
89     @Test
90     public void leafOnlyAugmentationDeletedTest() {
91         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
92         writeTx.put(CONFIGURATION, TOP, top());
93         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
94         TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
95         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
96         assertCommit(writeTx.submit());
97
98         final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
99                 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment),
100                 deleted(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
101
102         writeTx = getDataBroker().newWriteOnlyTransaction();
103         writeTx.delete(CONFIGURATION, SIMPLE_AUGMENT);
104         assertCommit(writeTx.submit());
105
106         listener.verify();
107     }
108
109     @Test
110     public void complexAugmentationCreatedTest() {
111         TreeComplexUsesAugment complexUsesAugment = complexUsesAugment(LIST_VIA_USES_KEY);
112         final TestListener<TreeComplexUsesAugment>  listener = createListener(CONFIGURATION, COMPLEX_AUGMENT,
113                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment));
114
115         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
116         writeTx.put(CONFIGURATION, TOP, top());
117         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
118         writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment);
119         assertCommit(writeTx.submit());
120
121         listener.verify();
122     }
123
124     @Test
125     public void complexAugmentationUpdatedTest() {
126         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
127         writeTx.put(CONFIGURATION, TOP, top());
128         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
129         TreeComplexUsesAugment complexUsesAugmentBefore = complexUsesAugment(LIST_VIA_USES_KEY);
130         writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentBefore);
131         assertCommit(writeTx.submit());
132
133         TreeComplexUsesAugment complexUsesAugmentAfter = complexUsesAugment(LIST_VIA_USES_KEY_MOD);
134
135         final TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, COMPLEX_AUGMENT,
136                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore),
137                 replaced(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore,
138                         complexUsesAugmentAfter));
139
140         writeTx = getDataBroker().newWriteOnlyTransaction();
141         writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentAfter);
142         assertCommit(writeTx.submit());
143
144         listener.verify();
145     }
146 }

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