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;
13 import org.junit.Test;
14 import org.opendaylight.mdsal.binding.api.ReadTransaction;
15 import org.opendaylight.mdsal.binding.api.WriteTransaction;
16 import org.opendaylight.mdsal.binding.dom.adapter.test.AbstractDataBrokerTest;
17 import org.opendaylight.mdsal.common.api.LogicalDatastoreType;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
20 import org.opendaylight.yangtools.yang.binding.DataObject;
21 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24 * Tests the {@link AssertDataObjects} utility.
26 * @author Michael Vorburger
28 public class AssertDataObjectsTest extends AbstractDataBrokerTest {
30 private static final String HEADER = "import static extension org.opendaylight.mdsal.binding.testutils."
31 + "XtendBuilderExtensions.operator_doubleGreaterThan\n\n";
34 public void testAssertDataObjectsWithTopLevelListKey() {
35 AssertDataObjects.assertEqualByText("new TopLevelListKey(\"test\")\n", new TopLevelListKey("test"));
39 public void testAssertDataObjectsWithEmptyTop() {
40 AssertDataObjects.assertEqualByText(HEADER + "new TopBuilder\n", ExampleYangObjects.topEmpty().getValue());
44 public void testAssertDataObjectsWithComplexTopWithKey() {
45 AssertDataObjects.assertEqualByText(HEADER + "new TopBuilder >> [\n"
46 + " topLevelList = #[\n"
47 + " new TopLevelListBuilder >> [\n"
49 + " addAugmentation(TreeComplexUsesAugment, new TreeComplexUsesAugmentBuilder >> [\n"
50 + " containerWithUses = new ContainerWithUsesBuilder >> [\n"
51 + " leafFromGrouping = \"foo\"\n"
56 + "]", ExpectedObjects.top());
60 public void testAssertDataObjectsWithTopLevelList() {
61 AssertDataObjects.assertEqualBeans(ExpectedObjects.topLevelList(),
62 ExampleYangObjects.topLevelList().getValue());
63 AssertDataObjects.assertEqualByText(HEADER + "new TopLevelListBuilder >> [\n"
65 + " addAugmentation(TreeComplexUsesAugment, new TreeComplexUsesAugmentBuilder >> [\n"
66 + " containerWithUses = new ContainerWithUsesBuilder >> [\n"
67 + " leafFromGrouping = \"foo\"\n"
70 + "]", ExampleYangObjects.topLevelList().getValue());
74 public void testAssertDataObjectsWithDataBroker() throws Exception {
75 WriteTransaction initialTx = getDataBroker().newWriteOnlyTransaction();
76 put(initialTx, OPERATIONAL, ExampleYangObjects.topEmpty());
77 put(initialTx, OPERATIONAL, ExampleYangObjects.topLevelList());
78 initialTx.submit().checkedGet();
80 ReadTransaction readTx = getDataBroker().newReadOnlyTransaction();
81 InstanceIdentifier<Top> id = InstanceIdentifier.create(Top.class);
82 Top actualTop = readTx.read(OPERATIONAL, id).checkedGet().get();
84 AssertDataObjects.assertEqualBeans(ExpectedObjects.top(), actualTop);
86 String expectedTopText = "import static extension org.opendaylight.mdsal.binding.testutils."
87 + "XtendBuilderExtensions.operator_doubleGreaterThan\n\n"
88 + "new TopBuilder >> [\n"
89 + " topLevelList = #[\n"
90 + " new TopLevelListBuilder >> [\n"
92 + " addAugmentation(TreeComplexUsesAugment, new TreeComplexUsesAugmentBuilder >> [\n"
93 + " containerWithUses = new ContainerWithUsesBuilder >> [\n"
94 + " leafFromGrouping = \"foo\"\n"
100 AssertDataObjects.assertEqualByText(expectedTopText, actualTop);
103 <T extends DataObject> void put(WriteTransaction tx, LogicalDatastoreType store,
104 Map.Entry<InstanceIdentifier<T>, T> obj) {
105 tx.put(OPERATIONAL, obj.getKey(), obj.getValue());