Improve segmented journal actor metrics
[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 @Deprecated
35 public class Bug1418AugmentationTest extends AbstractDataTreeChangeListenerTest {
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     @Override
48     protected Set<YangModuleInfo> getModuleInfos() throws Exception {
49         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
50                 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class),
51                 BindingReflections.getModuleInfo(TreeLeafOnlyUsesAugment.class));
52     }
53
54     @Test
55     public void leafOnlyAugmentationCreatedTest() {
56         TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
57         final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
58                 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
59
60         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
61         writeTx.put(CONFIGURATION, TOP, top());
62         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
63         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
64         assertCommit(writeTx.submit());
65
66         listener.verify();
67     }
68
69     @Test
70     public void leafOnlyAugmentationUpdatedTest() {
71         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
72         writeTx.put(CONFIGURATION, TOP, top());
73         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
74         TreeLeafOnlyUsesAugment leafOnlyUsesAugmentBefore = leafOnlyUsesAugment("test leaf");
75         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentBefore);
76         assertCommit(writeTx.submit());
77
78         TreeLeafOnlyUsesAugment leafOnlyUsesAugmentAfter = leafOnlyUsesAugment("test leaf changed");
79         final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
80                 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore),
81                 replaced(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugmentBefore,
82                     leafOnlyUsesAugmentAfter));
83
84         writeTx = getDataBroker().newWriteOnlyTransaction();
85         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugmentAfter);
86         assertCommit(writeTx.submit());
87
88         listener.verify();
89     }
90
91     @Test
92     public void leafOnlyAugmentationDeletedTest() {
93         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
94         writeTx.put(CONFIGURATION, TOP, top());
95         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
96         TreeLeafOnlyUsesAugment leafOnlyUsesAugment = leafOnlyUsesAugment("test leaf");
97         writeTx.put(CONFIGURATION, SIMPLE_AUGMENT, leafOnlyUsesAugment);
98         assertCommit(writeTx.submit());
99
100         final TestListener<TreeLeafOnlyUsesAugment> listener = createListener(CONFIGURATION, SIMPLE_AUGMENT,
101                 added(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment),
102                 deleted(path(TOP_FOO_KEY, TreeLeafOnlyUsesAugment.class), leafOnlyUsesAugment));
103
104         writeTx = getDataBroker().newWriteOnlyTransaction();
105         writeTx.delete(CONFIGURATION, SIMPLE_AUGMENT);
106         assertCommit(writeTx.submit());
107
108         listener.verify();
109     }
110
111     @Test
112     public void complexAugmentationCreatedTest() {
113         TreeComplexUsesAugment complexUsesAugment = complexUsesAugment(LIST_VIA_USES_KEY);
114         final TestListener<TreeComplexUsesAugment>  listener = createListener(CONFIGURATION, COMPLEX_AUGMENT,
115                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugment));
116
117         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
118         writeTx.put(CONFIGURATION, TOP, top());
119         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
120         writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugment);
121         assertCommit(writeTx.submit());
122
123         listener.verify();
124     }
125
126     @Test
127     public void complexAugmentationUpdatedTest() {
128         WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
129         writeTx.put(CONFIGURATION, TOP, top());
130         writeTx.put(CONFIGURATION, TOP_FOO, topLevelList(new TopLevelListKey(TOP_FOO_KEY)));
131         TreeComplexUsesAugment complexUsesAugmentBefore = complexUsesAugment(LIST_VIA_USES_KEY);
132         writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentBefore);
133         assertCommit(writeTx.submit());
134
135         TreeComplexUsesAugment complexUsesAugmentAfter = complexUsesAugment(LIST_VIA_USES_KEY_MOD);
136
137         final TestListener<TreeComplexUsesAugment> listener = createListener(CONFIGURATION, COMPLEX_AUGMENT,
138                 added(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore),
139                 replaced(path(TOP_FOO_KEY, TreeComplexUsesAugment.class), complexUsesAugmentBefore,
140                         complexUsesAugmentAfter));
141
142         writeTx = getDataBroker().newWriteOnlyTransaction();
143         writeTx.put(CONFIGURATION, COMPLEX_AUGMENT, complexUsesAugmentAfter);
144         assertCommit(writeTx.submit());
145
146         listener.verify();
147     }
148 }