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 com.google.common.base.Optional;
16 import com.google.common.collect.ImmutableList;
17 import java.util.concurrent.TimeUnit;
18 import org.junit.Test;
19 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
20 import org.opendaylight.controller.md.sal.binding.api.WriteTransaction;
21 import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
22 import org.opendaylight.controller.sal.binding.test.AbstractDataServiceTest;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.TllComplexAugment;
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Builder;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.List1Key;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Builder;
29 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.of.migration.test.model.rev150210.aug.grouping.list1.List11Key;
30 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.Top;
31 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelList;
32 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.test.list.rev140701.two.level.list.TopLevelListKey;
33 import org.opendaylight.yangtools.yang.binding.DataObject;
34 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
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).build();
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.
59 * Expected behaviour is child is returned.
62 public void writeParentReadChild() throws Exception {
64 DataBroker dataBroker = testContext.getDataBroker();
65 final WriteTransaction transaction = dataBroker.newWriteOnlyTransaction();
67 List11 list11 = new List11Builder().withKey(LIST11_KEY).setAttrStr("primary").build();
68 List1 list1 = new List1Builder().withKey(LIST1_KEY).setList11(ImmutableList.of(list11)).build();
70 transaction.put(LogicalDatastoreType.OPERATIONAL, LIST1_INSTANCE_ID_BA, list1, true);
71 transaction.submit().get(5, TimeUnit.SECONDS);
73 Optional<List1> readList1 = dataBroker.newReadOnlyTransaction().read(LogicalDatastoreType.OPERATIONAL,
74 LIST1_INSTANCE_ID_BA).get(1000, TimeUnit.MILLISECONDS);
75 assertTrue(readList1.isPresent());
77 Optional<? extends DataObject> readList11 = dataBroker.newReadOnlyTransaction().read(
78 LogicalDatastoreType.OPERATIONAL, LIST11_INSTANCE_ID_BA).get(5, TimeUnit.SECONDS);
79 assertNotNull("Readed flow should not be null.",readList11);
80 assertTrue(readList11.isPresent());
81 assertEquals(list11, readList11.get());