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

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