2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.controller.md.sal.binding.impl.test;
11 import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertContains;
12 import static org.opendaylight.controller.md.sal.binding.test.AssertCollections.assertEmpty;
13 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.TOP_FOO_KEY;
14 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.path;
15 import static org.opendaylight.controller.md.sal.test.model.util.ListsBindingUtils.topLevelList;
17 import org.junit.Test;
18 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
19 import org.opendaylight.controller.md.sal.binding.test.AbstractDataChangeListenerTest;
20 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataBroker.DataChangeScope;
21 import org.opendaylight.controller.md.sal.common.api.data.AsyncDataChangeEvent;
22 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugment;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.TreeComplexUsesAugmentBuilder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.augment.rev140709.complex.from.grouping.ContainerWithUsesBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.TopBuilder;
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.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
33 * Regression test suite for Bug 1125 - Can't detect switch disconnection
34 * https://bugs.opendaylight.org/show_bug.cgi?id=1125
36 public class Bug1125RegressionTest extends AbstractDataChangeListenerTest {
38 private static final InstanceIdentifier<Top> TOP_PATH = InstanceIdentifier
40 private static final InstanceIdentifier<TopLevelList> TOP_FOO_PATH = TOP_PATH
41 .child(TopLevelList.class, TOP_FOO_KEY);
43 private static final InstanceIdentifier<TreeComplexUsesAugment> FOO_AUGMENT_PATH = TOP_FOO_PATH
44 .augmentation(TreeComplexUsesAugment.class);
46 private static final InstanceIdentifier<TreeComplexUsesAugment> WILDCARDED_AUGMENT_PATH = TOP_PATH
47 .child(TopLevelList.class).augmentation(
48 TreeComplexUsesAugment.class);
50 private void writeInitialState() {
51 WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
52 initialTx.put(LogicalDatastoreType.OPERATIONAL, TOP_PATH,
53 new TopBuilder().build());
54 TreeComplexUsesAugment fooAugment = new TreeComplexUsesAugmentBuilder()
55 .setContainerWithUses(
56 new ContainerWithUsesBuilder().setLeafFromGrouping(
57 "foo").build()).build();
58 initialTx.put(LogicalDatastoreType.OPERATIONAL, path(TOP_FOO_KEY),
59 topLevelList(TOP_FOO_KEY, fooAugment));
60 assertCommit(initialTx.submit());
63 private void delete(final InstanceIdentifier<?> path) {
64 WriteTransaction tx = getDataBroker().newWriteOnlyTransaction();
65 tx.delete(LogicalDatastoreType.OPERATIONAL, path);
66 assertCommit(tx.submit());
69 private void verifyRemoved(
70 final AsyncDataChangeEvent<InstanceIdentifier<?>, DataObject> event) {
71 assertEmpty(event.getCreatedData());
72 assertEmpty(event.getUpdatedData());
73 assertContains(event.getRemovedPaths(), FOO_AUGMENT_PATH);
76 private void deleteAndListenAugment(final DataChangeScope scope,
77 final InstanceIdentifier<?> path) {
79 TestListener listener = createListener(LogicalDatastoreType.OPERATIONAL, WILDCARDED_AUGMENT_PATH, scope, false);
81 verifyRemoved(listener.event());
85 public void deleteAndListenAugment() {
87 deleteAndListenAugment(DataChangeScope.ONE, TOP_PATH);
89 deleteAndListenAugment(DataChangeScope.BASE, TOP_PATH);
91 deleteAndListenAugment(DataChangeScope.SUBTREE, TOP_PATH);
93 deleteAndListenAugment(DataChangeScope.BASE, TOP_FOO_PATH);
95 deleteAndListenAugment(DataChangeScope.ONE, TOP_FOO_PATH);
97 deleteAndListenAugment(DataChangeScope.SUBTREE, TOP_FOO_PATH);
99 deleteAndListenAugment(DataChangeScope.BASE, FOO_AUGMENT_PATH);
101 deleteAndListenAugment(DataChangeScope.ONE, FOO_AUGMENT_PATH);
103 deleteAndListenAugment(DataChangeScope.SUBTREE, FOO_AUGMENT_PATH);