1348af1e72b6262a83cd78e2a0501f425df724cf
[controller.git] / opendaylight / md-sal / sal-binding-broker / src / test / java / org / opendaylight / controller / md / sal / binding / impl / test / 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
9 package org.opendaylight.controller.md.sal.binding.impl.test;
10
11 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
12 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path;
13 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
14
15 import com.google.common.collect.ImmutableSet;
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
18 import org.opendaylight.controller.md.sal.binding.test.AbstractDataTreeChangeListenerTest;
19 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
20 import org.opendaylight.mdsal.binding.spec.reflect.BindingReflections;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.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
36     private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier
37             .create(Top.class);
38     private static final InstanceIdentifier<TopLevelList> TOP_FOO_PATH = TOP_PATH
39             .child(TopLevelList.class, TOP_FOO_KEY);
40
41     private static final InstanceIdentifier<TreeComplexUsesAugment> FOO_AUGMENT_PATH = TOP_FOO_PATH
42             .augmentation(TreeComplexUsesAugment.class);
43
44     private static final InstanceIdentifier<TreeComplexUsesAugment> WILDCARDED_AUGMENT_PATH = TOP_PATH
45             .child(TopLevelList.class).augmentation(
46                     TreeComplexUsesAugment.class);
47
48     @Override
49     protected Iterable<YangModuleInfo> getModuleInfos() throws Exception {
50         return ImmutableSet.of(BindingReflections.getModuleInfo(Top.class),
51                 BindingReflections.getModuleInfo(TreeComplexUsesAugment.class));
52     }
53
54     private TreeComplexUsesAugment writeInitialState() {
55         WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
56         initialTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH,
57                 new TopBuilder().build());
58         TreeComplexUsesAugment fooAugment = new TreeComplexUsesAugmentBuilder()
59                 .setContainerWithUses(
60                         new ContainerWithUsesBuilder().setLeafFromGrouping(
61                                 "foo").build()).build();
62         initialTx.put(LogicalDatastoreType.OPERATIONAL, path(TOP_FOO_KEY),
63                 topLevelList(TOP_FOO_KEY, fooAugment));
64         assertCommit(initialTx.submit());
65         return fooAugment;
66     }
67
68     private void delete(final InstanceIdentifier<?> path) {
69         WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
70         tx.delete(LogicalDatastoreType.OPERATIONAL, path);
71         assertCommit(tx.submit());
72     }
73
74     private void deleteAndListenAugment(final InstanceIdentifier<?> path) {
75         TreeComplexUsesAugment augment = writeInitialState();
76         TestListener<TreeComplexUsesAugment> listener = createListener(LogicalDatastoreType.OPERATIONAL,
77                 WILDCARDED_AUGMENT_PATH, added(FOO_AUGMENT_PATH, augment), deleted(FOO_AUGMENT_PATH, augment));
78         delete(path);
79         listener.verify();
80     }
81
82     @Test
83     public void deleteAndListenAugment() {
84         deleteAndListenAugment(TOP_PATH);
85
86         deleteAndListenAugment(TOP_FOO_PATH);
87
88         deleteAndListenAugment(FOO_AUGMENT_PATH);
89     }
90 }

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