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.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 import com.google.common.collect.ImmutableList;
35 @SuppressWarnings("deprecation")
36 public class WriteParentReadChildTest extends AbstractDataServiceTest {
38 private static final int LIST11_ID = 1234;
39 private static final String LIST1_NAME = "bar";
40 private static final String TLL_NAME = "foo";
42 private static final TopLevelListKey TLL_KEY = new TopLevelListKey(TLL_NAME);
43 private static final List11Key LIST11_KEY = new List11Key(LIST11_ID);
44 private static final List1Key LIST1_KEY = new List1Key(LIST1_NAME);
46 private static final InstanceIdentifier<TopLevelList> TLL_INSTANCE_ID_BA = InstanceIdentifier.builder(Top.class) //
47 .child(TopLevelList.class, TLL_KEY).toInstance();
49 private static final InstanceIdentifier<List1> LIST1_INSTANCE_ID_BA = //
50 TLL_INSTANCE_ID_BA.builder() //
51 .augmentation(TllComplexAugment.class).child(List1.class, LIST1_KEY).build();
53 private static final InstanceIdentifier<? extends DataObject> LIST11_INSTANCE_ID_BA = //
54 LIST1_INSTANCE_ID_BA.child(List11.class, LIST11_KEY);
57 * The scenario tests writing parent node, which also contains child items
58 * and then reading child directly, by specifying path to the child.
60 * Expected behaviour is child is returned.
65 public void writeParentReadChild() throws Exception {
67 DataModificationTransaction modification = baDataService.beginTransaction();
69 List11 list11 = new List11Builder() //
70 .setKey(LIST11_KEY) //
71 .setAttrStr("primary")
74 List1 list1 = new List1Builder()
76 .setList11(ImmutableList.of(list11))
79 modification.putConfigurationData(LIST1_INSTANCE_ID_BA, list1);
80 RpcResult<TransactionStatus> ret = modification.commit().get();
82 assertEquals(TransactionStatus.COMMITED, ret.getResult());
84 DataObject readList1 = baDataService.readConfigurationData(LIST1_INSTANCE_ID_BA);
85 assertNotNull("Readed table should not be nul.", readList1);
86 assertTrue(readList1 instanceof List1);
88 DataObject readList11 = baDataService.readConfigurationData(LIST11_INSTANCE_ID_BA);
89 assertNotNull("Readed flow should not be null.",readList11);
90 assertTrue(readList11 instanceof List11);
91 assertEquals(list11, readList11);