X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-binding-dom-it%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Fbinding%2Ftest%2Fbugfix%2FWriteParentReadChildTest.java;h=dca56abcf4a40a54072628fb7c266453df7e4858;hp=35b4e92db43bbbfdbe8545ea5779c675c1413050;hb=3a25fec0b812950c61d2fb6018407a2a6ceb5090;hpb=808313e2a87d8dd037a0566574d0acc34687149c diff --git a/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentReadChildTest.java b/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentReadChildTest.java index 35b4e92db4..dca56abcf4 100644 --- a/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentReadChildTest.java +++ b/opendaylight/md-sal/sal-binding-dom-it/src/test/java/org/opendaylight/controller/sal/binding/test/bugfix/WriteParentReadChildTest.java @@ -12,102 +12,76 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; +import com.google.common.base.Optional; +import com.google.common.collect.ImmutableList; +import java.util.concurrent.TimeUnit; import org.junit.Test; -import org.opendaylight.controller.md.sal.common.api.TransactionStatus; -import org.opendaylight.controller.sal.binding.api.data.DataModificationTransaction; +import org.opendaylight.controller.md.sal.binding.api.DataBroker; +import org.opendaylight.controller.md.sal.binding.api.WriteTransaction; +import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNode; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.TableKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.Flow; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.table.FlowKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.InstructionsBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.flow.MatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.instruction.list.Instruction; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.Nodes; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node; -import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.NodeKey; -import org.opendaylight.yang.gen.v1.urn.opendaylight.l2.types.rev130827.VlanId; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.match.VlanMatchBuilder; -import org.opendaylight.yang.gen.v1.urn.opendaylight.model.match.types.rev131026.vlan.match.fields.VlanIdBuilder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Builder; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList; +import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey; import org.opendaylight.yangtools.yang.binding.DataObject; import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; -import org.opendaylight.yangtools.yang.common.RpcResult; - -import com.google.common.collect.ImmutableList; public class WriteParentReadChildTest extends AbstractDataServiceTest { - private static final String FLOW_ID = "1234"; - private static final short TABLE_ID = (short) 0; - private static final String NODE_ID = "node:1"; + private static final int LIST11_ID = 1234; + private static final String LIST1_NAME = "bar"; + private static final String TLL_NAME = "foo"; + + private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME); + private static final List11Key LIST11_KEY = new List11Key(LIST11_ID); + private static final List1Key LIST1_KEY = new List1Key(LIST1_NAME); - private static final NodeKey NODE_KEY = new NodeKey(new NodeId(NODE_ID)); - private static final FlowKey FLOW_KEY = new FlowKey(new FlowId(FLOW_ID)); - private static final TableKey TABLE_KEY = new TableKey(TABLE_ID); + private static final InstanceIdentifier TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) // + .child(TopLevelList.class, TLL_KEY).toInstance(); - private static final InstanceIdentifier NODE_INSTANCE_ID_BA = InstanceIdentifier.builder(Nodes.class) // - .child(Node.class, NODE_KEY).toInstance(); + private static final InstanceIdentifier LIST1_INSTANCE_ID_BA = // + TLL_INSTANCE_ID_BA.builder() // + .augmentation(TllComplexAugment.class).child(List1.class, LIST1_KEY).build(); - private static final InstanceIdentifier TABLE_INSTANCE_ID_BA = // - InstanceIdentifier.builder(NODE_INSTANCE_ID_BA) // - .augmentation(FlowCapableNode.class).child(Table.class, TABLE_KEY).build(); + private static final InstanceIdentifier LIST11_INSTANCE_ID_BA = // + LIST1_INSTANCE_ID_BA.child(List11.class, LIST11_KEY); - private static final InstanceIdentifier FLOW_INSTANCE_ID_BA = // - InstanceIdentifier.builder(TABLE_INSTANCE_ID_BA) // - .child(Flow.class, FLOW_KEY) // - .toInstance(); /** - * * The scenario tests writing parent node, which also contains child items * and then reading child directly, by specifying path to the child. - * * Expected behaviour is child is returned. - * - * @throws Exception */ @Test - public void writeTableReadFlow() throws Exception { - - DataModificationTransaction modification = baDataService.beginTransaction(); - - Flow flow = new FlowBuilder() // - .setKey(FLOW_KEY) // - .setMatch(new MatchBuilder() // - .setVlanMatch(new VlanMatchBuilder() // - .setVlanId(new VlanIdBuilder() // - .setVlanId(new VlanId(10)) // - .build()) // - .build()) // - .build()) // - .setInstructions(new InstructionsBuilder() // - .setInstruction(ImmutableList.builder() // - .build()) // - .build()) // + public void writeParentReadChild() throws Exception { + + DataBroker dataBroker = testContext.getDataBroker(); + final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction(); + + List11 list11 = new List11Builder() // + .setKey(LIST11_KEY) // + .setAttrStr("primary") .build(); - Table table = new TableBuilder() - .setKey(TABLE_KEY) - .setFlow(ImmutableList.of(flow)) - .build(); - - modification.putConfigurationData(TABLE_INSTANCE_ID_BA, table); - RpcResult ret = modification.commit().get(); - assertNotNull(ret); - assertEquals(TransactionStatus.COMMITED, ret.getResult()); - - DataObject readedTable = baDataService.readConfigurationData(TABLE_INSTANCE_ID_BA); - assertNotNull("Readed table should not be nul.", readedTable); - assertTrue(readedTable instanceof Table); - - DataObject readedFlow = baDataService.readConfigurationData(FLOW_INSTANCE_ID_BA); - assertNotNull("Readed flow should not be null.",readedFlow); - assertTrue(readedFlow instanceof Flow); - assertEquals(flow, readedFlow); + List1 list1 = new List1Builder().setKey(LIST1_KEY).setList11(ImmutableList.of(list11)).build(); + + transaction.put(LogicalDatastoreType.OPERATIONAL, LIST1_INSTANCE_ID_BA, list1, true); + transaction.submit().get(5, TimeUnit.SECONDS); + + Optional readList1 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL, + LIST1_INSTANCE_ID_BA).checkedGet(1000, TimeUnit.MILLISECONDS); + assertTrue(readList1.isPresent()); + Optional readList11 = dataBroker.newReadOnlyTransaction().read( + LogicalDatastoreType.OPERATIONAL, LIST11_INSTANCE_ID_BA).checkedGet(5, TimeUnit.SECONDS); + assertNotNull("Readed flow should not be null.",readList11); + assertTrue(readList11.isPresent()); + assertEquals(list11, readList11.get()); } -} \ No newline at end of file +}