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;
14 import com.google.common.collect.ImmutableList;
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.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Builder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Builder;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
29 import org.opendaylight.yangtools.yang.binding.DataObject;
30 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
31 import org.opendaylight.yangtools.yang.common.RpcResult;
33 public class WriteParentReadChildTest extends AbstractDataServiceTest {
35 private static final int LIST11_ID = 1234;
36 private static final String LIST1_NAME = "bar";
37 private static final String TLL_NAME = "foo";
39 private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
40 private static final List11Key LIST11_KEY = new List11Key(LIST11_ID);
41 private static final List1Key LIST1_KEY = new List1Key(LIST1_NAME);
43 private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) //
44 .child(TopLevelList.class, TLL_KEY).toInstance();
46 private static final InstanceIdentifier<List1> LIST1_INSTANCE_ID_BA = //
47 TLL_INSTANCE_ID_BA.builder() //
48 .augmentation(TllComplexAugment.class).child(List1.class, LIST1_KEY).build();
50 private static final InstanceIdentifier<? extends DataObject> LIST11_INSTANCE_ID_BA = //
51 LIST1_INSTANCE_ID_BA.child(List11.class, LIST11_KEY);
54 * The scenario tests writing parent node, which also contains child items
55 * and then reading child directly, by specifying path to the child.
57 * Expected behaviour is child is returned.
62 public void writeParentReadChild() throws Exception {
64 DataModificationTransaction modification = baDataService.beginTransaction();
66 List11 list11 = new List11Builder() //
67 .setKey(LIST11_KEY) //
68 .setAttrStr("primary")
71 List1 list1 = new List1Builder()
73 .setList11(ImmutableList.of(list11))
76 modification.putConfigurationData(LIST1_INSTANCE_ID_BA, list1);
77 RpcResult<TransactionStatus> ret = modification.commit().get();
79 assertEquals(TransactionStatus.COMMITED, ret.getResult());
81 DataObject readList1 = baDataService.readConfigurationData(LIST1_INSTANCE_ID_BA);
82 assertNotNull("Readed table should not be nul.", readList1);
83 assertTrue(readList1 instanceof List1);
85 DataObject readList11 = baDataService.readConfigurationData(LIST11_INSTANCE_ID_BA);
86 assertNotNull("Readed flow should not be null.",readList11);
87 assertTrue(readList11 instanceof List11);
88 assertEquals(list11, readList11);