f7b81a44e9e2b685860b7269425c2630911b817b
[controller.git] / opendaylight / md-sal / sal-binding-dom-it / src / test / java / org / opendaylight / controller / sal / binding / test / bugfix / WriteParentReadChildTest.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.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import org.junit.Test;
16 import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
17 import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction;
18 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
33 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey;
34 import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId;
35 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder;
36 import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder;
37 import org.opendaylight.yangtools.yang.binding.DataObject;
38 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
39 import org.opendaylight.yangtools.yang.common.RpcResult;
40
41 import com.google.common.collect.ImmutableList;
42
43 public class WriteParentReadChildTest extends AbstractDataServiceTest {
44
45     private static final String FLOW_ID = "1234";
46     private static final short TABLE_ID = (short) 0;
47     private static final String NODE_ID = "node:1";
48
49     private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID));
50     private static final FlowKey FLOW_KEY = new FlowKey(new FlowId(FLOW_ID));
51     private static final TableKey TABLE_KEY = new TableKey(TABLE_ID);
52
53     private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
54             .child(Node.class, NODE_KEY).toInstance();
55
56     private static final InstanceIdentifier<Table> TABLE_INSTANCE_ID_BA = //
57             NODE_INSTANCE_ID_BA.builder() //
58             .augmentation(FlowCapableNode.class).child(Table.class, TABLE_KEY).build();
59
60     private static final InstanceIdentifier<? extends DataObject> FLOW_INSTANCE_ID_BA = //
61             TABLE_INSTANCE_ID_BA.child(Flow.class, FLOW_KEY);
62     /**
63      *
64      * The scenario tests writing parent node, which also contains child items
65      * and then reading child directly, by specifying path to the child.
66      *
67      * Expected behaviour is child is returned.
68      *
69      * @throws Exception
70      */
71     @Test
72     public void writeTableReadFlow() throws Exception {
73
74         DataModificationTransaction modification = baDataService.beginTransaction();
75
76         Flow flow = new FlowBuilder() //
77                 .setKey(FLOW_KEY) //
78                 .setMatch(new MatchBuilder() //
79                         .setVlanMatch(new VlanMatchBuilder() //
80                                 .setVlanId(new VlanIdBuilder() //
81                                         .setVlanId(new VlanId(10)) //
82                                         .build()) //
83                                 .build()) //
84                         .build()) //
85                         .setInstructions(new InstructionsBuilder() //
86                             .setInstruction(ImmutableList.<Instruction>builder() //
87                                     .build()) //
88                         .build()) //
89                 .build();
90
91         Table table = new TableBuilder()
92             .setKey(TABLE_KEY)
93             .setFlow(ImmutableList.of(flow))
94         .build();
95
96         modification.putConfigurationData(TABLE_INSTANCE_ID_BA, table);
97         RpcResult<TransactionStatus> ret = modification.commit().get();
98         assertNotNull(ret);
99         assertEquals(TransactionStatus.COMMITED, ret.getResult());
100
101         DataObject readedTable = baDataService.readConfigurationData(TABLE_INSTANCE_ID_BA);
102         assertNotNull("Readed table should not be nul.", readedTable);
103         assertTrue(readedTable instanceof Table);
104
105         DataObject readedFlow = baDataService.readConfigurationData(FLOW_INSTANCE_ID_BA);
106         assertNotNull("Readed flow should not be null.",readedFlow);
107         assertTrue(readedFlow instanceof Flow);
108         assertEquals(flow, readedFlow);
109
110     }
111 }

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