Merge "Bug 1293 - Switch packaging of config-util to bundle"
[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 @SuppressWarnings("deprecation")
44 public class WriteParentReadChildTest extends AbstractDataServiceTest {
45
46     private static final String FLOW_ID = "1234";
47     private static final short TABLE_ID = (short) 0;
48     private static final String NODE_ID = "node:1";
49
50     private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID));
51     private static final FlowKey FLOW_KEY = new FlowKey(new FlowId(FLOW_ID));
52     private static final TableKey TABLE_KEY = new TableKey(TABLE_ID);
53
54     private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
55             .child(Node.class, NODE_KEY).toInstance();
56
57     private static final InstanceIdentifier<Table> TABLE_INSTANCE_ID_BA = //
58             NODE_INSTANCE_ID_BA.builder() //
59             .augmentation(FlowCapableNode.class).child(Table.class, TABLE_KEY).build();
60
61     private static final InstanceIdentifier<? extends DataObject> FLOW_INSTANCE_ID_BA = //
62             TABLE_INSTANCE_ID_BA.child(Flow.class, FLOW_KEY);
63     /**
64      *
65      * The scenario tests writing parent node, which also contains child items
66      * and then reading child directly, by specifying path to the child.
67      *
68      * Expected behaviour is child is returned.
69      *
70      * @throws Exception
71      */
72     @Test
73     public void writeTableReadFlow() throws Exception {
74
75         DataModificationTransaction modification = baDataService.beginTransaction();
76
77         Flow flow = new FlowBuilder() //
78                 .setKey(FLOW_KEY) //
79                 .setMatch(new MatchBuilder() //
80                         .setVlanMatch(new VlanMatchBuilder() //
81                                 .setVlanId(new VlanIdBuilder() //
82                                         .setVlanId(new VlanId(10)) //
83                                         .build()) //
84                                 .build()) //
85                         .build()) //
86                         .setInstructions(new InstructionsBuilder() //
87                             .setInstruction(ImmutableList.<Instruction>builder() //
88                                     .build()) //
89                         .build()) //
90                 .build();
91
92         Table table = new TableBuilder()
93             .setKey(TABLE_KEY)
94             .setFlow(ImmutableList.of(flow))
95         .build();
96
97         modification.putConfigurationData(TABLE_INSTANCE_ID_BA, table);
98         RpcResult<TransactionStatus> ret = modification.commit().get();
99         assertNotNull(ret);
100         assertEquals(TransactionStatus.COMMITED, ret.getResult());
101
102         DataObject readedTable = baDataService.readConfigurationData(TABLE_INSTANCE_ID_BA);
103         assertNotNull("Readed table should not be nul.", readedTable);
104         assertTrue(readedTable instanceof Table);
105
106         DataObject readedFlow = baDataService.readConfigurationData(FLOW_INSTANCE_ID_BA);
107         assertNotNull("Readed flow should not be null.",readedFlow);
108         assertTrue(readedFlow instanceof Flow);
109         assertEquals(flow, readedFlow);
110
111     }
112 }