2 * Copyright (c) 2014 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.sal.binding.test.bugfix;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
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;
41 import com.google.common.collect.ImmutableList;
43 @SuppressWarnings("deprecation")
44 public class WriteParentReadChildTest extends AbstractDataServiceTest {
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";
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);
54 private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
55 .child(Node.class, NODE_KEY).toInstance();
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();
61 private static final InstanceIdentifier<? extends DataObject> FLOW_INSTANCE_ID_BA = //
62 TABLE_INSTANCE_ID_BA.child(Flow.class, FLOW_KEY);
65 * The scenario tests writing parent node, which also contains child items
66 * and then reading child directly, by specifying path to the child.
68 * Expected behaviour is child is returned.
73 public void writeTableReadFlow() throws Exception {
75 DataModificationTransaction modification = baDataService.beginTransaction();
77 Flow flow = new FlowBuilder() //
79 .setMatch(new MatchBuilder() //
80 .setVlanMatch(new VlanMatchBuilder() //
81 .setVlanId(new VlanIdBuilder() //
82 .setVlanId(new VlanId(10)) //
86 .setInstructions(new InstructionsBuilder() //
87 .setInstruction(ImmutableList.<Instruction>builder() //
92 Table table = new TableBuilder()
94 .setFlow(ImmutableList.of(flow))
97 modification.putConfigurationData(TABLE_INSTANCE_ID_BA, table);
98 RpcResult<TransactionStatus> ret = modification.commit().get();
100 assertEquals(TransactionStatus.COMMITED, ret.getResult());
102 DataObject readedTable = baDataService.readConfigurationData(TABLE_INSTANCE_ID_BA);
103 assertNotNull("Readed table should not be nul.", readedTable);
104 assertTrue(readedTable instanceof Table);
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);