735138a530ab801149adbaceb79e38c3b27d92b9
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / bugfix / DeleteNestedAugmentationListenParentTest.java
1 package org.opendaylight.controller.sal.binding.test.bugfix;
2
3 import static org.junit.Assert.assertFalse;
4
5 import java.util.concurrent.ExecutionException;
6
7 import org.junit.Test;
8 import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
9 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
10 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
11 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsData;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.FlowStatisticsDataBuilder;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.statistics.rev130819.flow.statistics.FlowStatisticsBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
27 import org.opendaylight.yangtools.yang.binding.DataObject;
28 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
29
30 import com.google.common.util.concurrent.SettableFuture;
31
32 @SuppressWarnings("deprecation")
33 public class DeleteNestedAugmentationListenParentTest extends AbstractDataServiceTest {
34
35     private static final NodeKey NODE_KEY = new NodeKey(new NodeId("foo"));
36
37     private static final TableKey TABLE_KEY = new TableKey((short) 0);
38
39     private static final FlowKey FLOW_KEY = new FlowKey(new FlowId("100"));
40
41     private static final InstanceIdentifier<FlowCapableNode> NODE_AUGMENT_PATH = InstanceIdentifier.builder(Nodes.class)
42             .child(Node.class,NODE_KEY)
43             .augmentation(FlowCapableNode.class)
44             .build();
45
46     private static final InstanceIdentifier<Flow> FLOW_PATH = NODE_AUGMENT_PATH.builder()
47             .child(Table.class,TABLE_KEY)
48             .child(Flow.class,FLOW_KEY)
49             .build();
50
51
52     @Test
53     public void deleteChildListenParent() throws InterruptedException, ExecutionException {
54         DataModificationTransaction initTx = baDataService.beginTransaction();
55
56         initTx.putOperationalData(FLOW_PATH, flow());
57         initTx.commit().get();
58
59         final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
60
61         baDataService.registerDataChangeListener(FLOW_PATH, new DataChangeListener() {
62
63             @Override
64             public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
65                 event.set(change);
66             }
67         });
68
69         DataModificationTransaction deleteTx = baDataService.beginTransaction();
70         deleteTx.removeOperationalData(FLOW_PATH.augmentation(FlowStatisticsData.class));
71         deleteTx.commit().get();
72
73         DataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get();
74         assertFalse(receivedEvent.getRemovedOperationalData().contains(NODE_AUGMENT_PATH));
75     }
76
77     private Flow flow() {
78         FlowBuilder builder = new FlowBuilder()
79             .setKey(FLOW_KEY)
80             .addAugmentation(FlowStatisticsData.class,new FlowStatisticsDataBuilder()
81                     .setFlowStatistics(new FlowStatisticsBuilder().build())
82                     .build())
83             .setBarrier(true)
84             .setMatch(new MatchBuilder()
85             .build())
86         ;
87         return builder.build();
88     }
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.