Correct ActionService generics
[mdsal.git] / binding / mdsal-binding-dom-adapter / src / test / java / org / opendaylight / mdsal / binding / dom / adapter / Bug1125RegressionTest.java
1 /*
2  * Copyright (c) 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 package org.opendaylight.mdsal.binding.dom.adapter;
9
10 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
11 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.path;
12 import static org.opendaylight.mdsal.binding.test.model.util.ListsBindingUtils.topLevelList;
13
14 import com.google.common.collect.ImmutableSet;
15 import java.util.Set;
16 import org.junit.Test;
17 import org.opendaylight.mdsal.binding.api.WriteTransaction;
18 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataTreeChangeListenerTest;
19 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
20 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugment;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.TopBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
27 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
28 import org.opendaylight.yangtools.yang.binding.YangModuleInfo;
29
30 /**
31  * Regression test suite for Bug 1125 - Can't detect switch disconnection
32  * https://bugs.opendaylight.org/show_bug.cgi?id=1125.
33  */
34 public class Bug1125RegressionTest extends AbstractDataTreeChangeListenerTest {
35     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier.create(Top.class);
36     private static final InstanceIdentifier<TopLevelList> TOP_FOO_PATH = TOP_PATH
37             .child(TopLevelList.class, TOP_FOO_KEY);
38
39     private static final InstanceIdentifier<TreeComplexUsesAugment> FOO_AUGMENT_PATH = TOP_FOO_PATH
40             .augmentation(TreeComplexUsesAugment.class);
41
42     private static final InstanceIdentifier<TreeComplexUsesAugment> WILDCARDED_AUGMENT_PATH = TOP_PATH
43             .child(TopLevelList.class).augmentation(
44                     TreeComplexUsesAugment.class);
45
46     @Override
47     protected Set<YangModuleInfo> getModuleInfos() throws Exception {
48         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
49                 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
50     }
51
52     @Test
53     public void deleteAndListenAugment() {
54         deleteAndListenAugment(TOP_PATH);
55
56         deleteAndListenAugment(TOP_FOO_PATH);
57
58         deleteAndListenAugment(FOO_AUGMENT_PATH);
59     }
60
61     private void deleteAndListenAugment(final InstanceIdentifier<?> path) {
62         TreeComplexUsesAugment augment = writeInitialState();
63         TestListener<TreeComplexUsesAugment> listener = createListener(LogicalDatastoreType.OPERATIONAL,
64                 WILDCARDED_AUGMENT_PATH, added(FOO_AUGMENT_PATH, augment), deleted(FOO_AUGMENT_PATH, augment));
65         WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
66         tx.delete(LogicalDatastoreType.OPERATIONAL, path);
67         assertCommit(tx.commit());
68         listener.verify();
69     }
70
71     private TreeComplexUsesAugment writeInitialState() {
72         WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
73         initialTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH, new TopBuilder().build());
74         TreeComplexUsesAugment fooAugment = new TreeComplexUsesAugmentBuilder()
75                 .setContainerWithUses(new ContainerWithUsesBuilder().setLeafFromGrouping("foo").build())
76                 .build();
77         initialTx.put(LogicalDatastoreType.OPERATIONAL, path(TOP_FOO_KEY), topLevelList(TOP_FOO_KEY, fooAugment));
78         assertCommit(initialTx.commit());
79         return fooAugment;
80     }
81 }