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 public class WriteParentReadChildTest extends AbstractDataServiceTest {
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";
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);
53 private static final InstanceIdentifier<Node> NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) //
54 .child(Node.class, NODE_KEY).toInstance();
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();
60 private static final InstanceIdentifier<? extends DataObject> FLOW_INSTANCE_ID_BA = //
61 TABLE_INSTANCE_ID_BA.child(Flow.class, FLOW_KEY);
64 * The scenario tests writing parent node, which also contains child items
65 * and then reading child directly, by specifying path to the child.
67 * Expected behaviour is child is returned.
72 public void writeTableReadFlow() throws Exception {
74 DataModificationTransaction modification = baDataService.beginTransaction();
76 Flow flow = new FlowBuilder() //
78 .setMatch(new MatchBuilder() //
79 .setVlanMatch(new VlanMatchBuilder() //
80 .setVlanId(new VlanIdBuilder() //
81 .setVlanId(new VlanId(10)) //
85 .setInstructions(new InstructionsBuilder() //
86 .setInstruction(ImmutableList.<Instruction>builder() //
91 Table table = new TableBuilder()
93 .setFlow(ImmutableList.of(flow))
96 modification.putConfigurationData(TABLE_INSTANCE_ID_BA, table);
97 RpcResult<TransactionStatus> ret = modification.commit().get();
99 assertEquals(TransactionStatus.COMMITED, ret.getResult());
101 DataObject readedTable = baDataService.readConfigurationData(TABLE_INSTANCE_ID_BA);
102 assertNotNull("Readed table should not be nul.", readedTable);
103 assertTrue(readedTable instanceof Table);
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);