2 * Copyright (c) 2016 Red Hat, 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
8 package org.opendaylight.mdsal.binding.testutils;
10 import static org.opendaylight.mdsal.common.api.LogicalDatastoreType.OPERATIONAL;
12 import ch.vorburger.xtendbeans.AssertBeans;
14 import org.junit.Test;
15 import org.opendaylight.mdsal.binding.api.ReadTransaction;
16 import org.opendaylight.mdsal.binding.api.WriteTransaction;
17 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest;
18 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
21 import org.opendaylight.yangtools.yang.binding.Augmentation;
22 import org.opendaylight.yangtools.yang.binding.DataObject;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
26 * Test for {@link AugmentableExtension}.
28 * @author Michael Vorburger
30 public class AugmentableExtensionTest extends AbstractDataBrokerTest {
32 private final AugmentableExtension augmentableExtension = new AugmentableExtension();
35 public void testAugmentableExtensionOnYangObjectByBuilder() {
36 TopLevelList topLevelList = ExampleYangObjects.topLevelList().getValue();
37 Map<Class<? extends Augmentation<?>>, Augmentation<?>> augmentations = augmentableExtension
38 .getAugmentations(topLevelList);
39 AssertBeans.assertEqualByText("#{\n"
40 + " org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test"
41 + ".augment.rev140709.TreeComplexUsesAugment -> (new TreeComplexUsesAugmentBuilder => [\n"
42 + " containerWithUses = (new ContainerWithUsesBuilder => [\n"
43 + " leafFromGrouping = \"foo\"\n"
46 + "}", augmentations);
50 public void testAugmentableExtensionWithDataBroker() throws Exception {
51 WriteTransaction writeTx = getDataBroker().newWriteOnlyTransaction();
52 put(writeTx, OPERATIONAL, ExampleYangObjects.topLevelList());
53 writeTx.submit().checkedGet();
55 ReadTransaction readTx = getDataBroker().newReadOnlyTransaction();
56 InstanceIdentifier<Top> id = InstanceIdentifier.create(Top.class);
57 Top actualTop = readTx.read(OPERATIONAL, id).checkedGet().get();
58 AssertBeans.assertEqualByText("#{\n}", augmentableExtension.getAugmentations(actualTop));
60 TopLevelList topLevelList = actualTop.getTopLevelList().get(0);
61 AssertDataObjects.assertEqualByText("#{\n"
62 + " TreeComplexUsesAugment -> new TreeComplexUsesAugmentBuilder >> [\n"
63 + " containerWithUses = new ContainerWithUsesBuilder >> [\n"
64 + " leafFromGrouping = \"foo\"\n"
67 + "}", augmentableExtension.getAugmentations(topLevelList));
70 <T extends DataObject> void put(WriteTransaction tx, LogicalDatastoreType store,
71 Map.Entry<InstanceIdentifier<T>, T> obj) {
72 tx.put(OPERATIONAL, obj.getKey(), obj.getValue());