cb31885f02673685342d35796d81e7bb3c38fa71
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / bugfix / WriteParentListenAugmentTest.java
1 /*
2  * Copyright (c) 2014 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.sal.binding.test.bugfix;
10
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13
14 import java.util.concurrent.TimeUnit;
15
16 import org.junit.Test;
17 import org.opendaylight.controller.md.sal.common.api.data.DataChangeEvent;
18 import org.opendaylight.controller.sal.binding.api.data.DataChangeListener;
19 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
20 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeBuilder;
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.NodeBuilder;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
28 import org.opendaylight.yangtools.concepts.ListenerRegistration;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31
32 import com.google.common.util.concurrent.SettableFuture;
33
34 public class WriteParentListenAugmentTest extends AbstractDataServiceTest {
35
36     private static final String NODE_ID = "node:1";
37
38     private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID));
39     private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
40             .child(Node.class, NODE_KEY).toInstance();
41
42     private static final InstanceIdentifier<FlowCapableNode> AUGMENT_WILDCARDED_PATH = InstanceIdentifier
43             .builder(Nodes.class).child(Node.class).augmentation(FlowCapableNode.class).toInstance();
44
45     private static final InstanceIdentifier<FlowCapableNode> AUGMENT_NODE_PATH = InstanceIdentifier
46             .builder(Nodes.class).child(Node.class, NODE_KEY).augmentation(FlowCapableNode.class).toInstance();
47
48     @Test
49     public void writeNodeListenAugment() throws Exception {
50
51         final SettableFuture<DataChangeEvent<InstanceIdentifier<?>, DataObject>> event = SettableFuture.create();
52
53         ListenerRegistration<DataChangeListener> dclRegistration = baDataService.registerDataChangeListener(
54                 AUGMENT_WILDCARDED_PATH, new DataChangeListener() {
55
56                     @Override
57                     public void onDataChanged(final DataChangeEvent<InstanceIdentifier<?>, DataObject> change) {
58                         event.set(change);
59                     }
60                 });
61
62         DataModificationTransaction modification = baDataService.beginTransaction();
63
64         Node node = new NodeBuilder() //
65                 .setKey(NODE_KEY) //
66                 .addAugmentation(FlowCapableNode.class, flowCapableNode("one")).build();
67         modification.putOperationalData(NODE_INSTANCE_ID_BA, node);
68         modification.commit().get();
69
70         DataChangeEvent<InstanceIdentifier<?>, DataObject> receivedEvent = event.get(1000, TimeUnit.MILLISECONDS);
71         assertTrue(receivedEvent.getCreatedOperationalData().containsKey(AUGMENT_NODE_PATH));
72
73         dclRegistration.close();
74
75         DataModificationTransaction mod2 = baDataService.beginTransaction();
76         mod2.putOperationalData(AUGMENT_NODE_PATH, flowCapableNode("two"));
77         mod2.commit().get();
78
79         FlowCapableNode readedAug = (FlowCapableNode) baDataService.readOperationalData(AUGMENT_NODE_PATH);
80         assertEquals("two", readedAug.getDescription());
81
82     }
83
84     private FlowCapableNode flowCapableNode(final String description) {
85         return new FlowCapableNodeBuilder() //
86                 .setDescription(description) //
87                 .build();
88     }
89 }

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