summaryrefslogtreecommitdiffstats
path: root/infra/data-impl/src/test/java/io/fd/honeycomb/data/impl/ModificationDiffTest.java
blob: cc00f2dc688aa6a95fd940d90ba2e19bbc9ef6dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
package io.fd.honeycomb.data.impl;

import static org.hamcrest.CoreMatchers.equalTo;
import static org.hamcrest.CoreMatchers.hasItems;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

import com.google.common.base.Optional;
import java.util.Map;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.ContainerNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeSnapshot;
import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TipProducingDataTree;
import org.opendaylight.yangtools.yang.data.api.schema.tree.TreeType;
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.impl.schema.tree.InMemoryDataTreeFactory;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;

public class ModificationDiffTest {

    static final QName TOP_CONTAINER_QNAME =
            QName.create("urn:opendaylight:params:xml:ns:yang:test:diff", "2015-01-05", "top-container");
    static final QName STRING_LEAF_QNAME = QName.create(TOP_CONTAINER_QNAME, "string");
    static final QName NAME_LEAF_QNAME = QName.create(TOP_CONTAINER_QNAME, "name");
    static final QName TEXT_LEAF_QNAME = QName.create(TOP_CONTAINER_QNAME, "text");
    static final QName NESTED_LIST_QNAME = QName.create(TOP_CONTAINER_QNAME, "nested-list");
    static final QName DEEP_LIST_QNAME = QName.create(TOP_CONTAINER_QNAME, "deep-list");

    static final QName WITH_CHOICE_CONTAINER_QNAME =
            QName.create("urn:opendaylight:params:xml:ns:yang:test:diff", "2015-01-05", "with-choice");
    static final QName CHOICE_QNAME = QName.create(WITH_CHOICE_CONTAINER_QNAME, "choice");
    static final QName IN_CASE1_LEAF_QNAME = QName.create(WITH_CHOICE_CONTAINER_QNAME, "in-case1");
    static final QName IN_CASE2_LEAF_QNAME = QName.create(WITH_CHOICE_CONTAINER_QNAME, "in-case2");

    static final QName PRESENCE_CONTAINER_QNAME = QName.create(TOP_CONTAINER_QNAME, "presence");

    static final YangInstanceIdentifier TOP_CONTAINER_ID = YangInstanceIdentifier.of(TOP_CONTAINER_QNAME);
    static final YangInstanceIdentifier NESTED_LIST_ID = TOP_CONTAINER_ID.node(new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME));

    @Test
    public void testInitialWrite() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();
        final DataTreeModification dataTreeModification = getModification(dataTree);
        final NormalizedNode<?, ?> topContainer = getTopContainer("string1");
        final YangInstanceIdentifier TOP_CONTAINER_ID = YangInstanceIdentifier.of(TOP_CONTAINER_QNAME);
        dataTreeModification.write(TOP_CONTAINER_ID, topContainer);
        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final ModificationDiff modificationDiff = getModificationDiff(prepare);

        assertThat(modificationDiff.getUpdates().size(), is(1));
        assertThat(modificationDiff.getUpdates().values().size(), is(1));
        assertUpdate(modificationDiff.getUpdates().values().iterator().next(), TOP_CONTAINER_ID, null, topContainer);
    }

    @Test
    public void testWritePresenceEmptyContainer() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();
        final DataTreeModification dataTreeModification = getModification(dataTree);
        final NormalizedNode<?, ?> presenceContainer = Builders.containerBuilder()
                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(PRESENCE_CONTAINER_QNAME))
                .build();
        final YangInstanceIdentifier PRESENCE_CONTAINER_ID = YangInstanceIdentifier.of(PRESENCE_CONTAINER_QNAME);
        dataTreeModification.write(PRESENCE_CONTAINER_ID, presenceContainer);
        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final ModificationDiff modificationDiff = getModificationDiff(prepare);

        dataTree.commit(prepare);

        final Optional<NormalizedNode<?, ?>> presenceAfter = getModification(dataTree).readNode(PRESENCE_CONTAINER_ID);
        assertTrue(presenceAfter.isPresent());
        assertThat(presenceAfter.get(), equalTo(presenceContainer));

        assertThat(modificationDiff.getUpdates().size(), is(1));
        assertThat(modificationDiff.getUpdates().values().size(), is(1));
        assertUpdate(modificationDiff.getUpdates().values().iterator().next(), PRESENCE_CONTAINER_ID, null, presenceContainer);
    }

    @Test
    public void testInitialWriteForContainerWithChoice() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();
        final DataTreeModification dataTreeModification = getModification(dataTree);
        final ContainerNode containerWithChoice = Builders.containerBuilder()
                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(WITH_CHOICE_CONTAINER_QNAME))
                .withChild(Builders.choiceBuilder()
                        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(CHOICE_QNAME))
                        .withChild(ImmutableNodes.leafNode(IN_CASE1_LEAF_QNAME, "withinCase1"))
                        .build())
                .build();
        final YangInstanceIdentifier WITH_CHOICE_CONTAINER_ID = YangInstanceIdentifier.of(WITH_CHOICE_CONTAINER_QNAME);
        dataTreeModification.write(WITH_CHOICE_CONTAINER_ID, containerWithChoice);
        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();

        assertThat(updates.size(), is(1));
        assertUpdate(getNormalizedNodeUpdateForAfterType(updates, ContainerNode.class),
                WITH_CHOICE_CONTAINER_ID, null, containerWithChoice);
    }

    private DataTreeModification getModification(final TipProducingDataTree dataTree) {
        final DataTreeSnapshot dataTreeSnapshot = dataTree.takeSnapshot();
        return dataTreeSnapshot.newModification();
    }

    @Test
    public void testWriteNonPresenceEmptyContainer() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();
        final DataTreeModification dataTreeModification = getModification(dataTree);
        final NormalizedNode<?, ?> topContainer = ImmutableNodes.containerNode(TOP_CONTAINER_QNAME);
        dataTreeModification.write(TOP_CONTAINER_ID, topContainer);
        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final ModificationDiff modificationDiff = getModificationDiff(prepare);

        assertThat(modificationDiff.getUpdates().size(), is(0));
    }

    private DataTreeCandidateTip prepareModification(final TipProducingDataTree dataTree,
                                                     final DataTreeModification dataTreeModification)
            throws DataValidationFailedException {
        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        return dataTree.prepare(dataTreeModification);
    }

    @Test
    public void testUpdateWrite() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();
        final ContainerNode topContainer = getTopContainer("string1");
        addNodeToTree(dataTree, topContainer, TOP_CONTAINER_ID);

        final DataTreeModification dataTreeModification = getModification(dataTree);
        final NormalizedNode<?, ?> topContainerAfter = getTopContainer("string2");
        dataTreeModification.write(TOP_CONTAINER_ID, topContainerAfter);
        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();

        assertThat(updates.size(), is(1));
        assertThat(updates.values().size(), is(1));
        assertUpdate(updates.values().iterator().next(), TOP_CONTAINER_ID, topContainer, topContainerAfter);
    }

    private ModificationDiff getModificationDiff(final DataTreeCandidateTip prepare) {
        return ModificationDiff.recursivelyFromCandidateRoot(prepare.getRootNode());
    }

    @Test
    public void testUpdateMerge() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();
        final ContainerNode topContainer = getTopContainer("string1");
        addNodeToTree(dataTree, topContainer, TOP_CONTAINER_ID);

        final DataTreeModification dataTreeModification = getModification(dataTree);
        final NormalizedNode<?, ?> topContainerAfter = getTopContainer("string2");
        dataTreeModification.merge(TOP_CONTAINER_ID, topContainerAfter);
        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();
        assertThat(updates.size(), is(1));
        assertThat(updates.values().size(), is(1));
        assertUpdate(updates.values().iterator().next(), TOP_CONTAINER_ID, topContainer, topContainerAfter);
    }

    @Test
    public void testUpdateDelete() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();
        final ContainerNode topContainer = getTopContainer("string1");
        addNodeToTree(dataTree, topContainer, TOP_CONTAINER_ID);

        final DataTreeModification dataTreeModification = getModification(dataTree);
        dataTreeModification.delete(TOP_CONTAINER_ID);
        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();
        assertThat(updates.size(), is(1));
        assertThat(updates.values().size(), is(1));
        assertUpdate(updates.values().iterator().next(), TOP_CONTAINER_ID, topContainer, null);
    }

    @Test
    public void testWriteAndUpdateInnerList() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();

        DataTreeSnapshot dataTreeSnapshot = dataTree.takeSnapshot();
        DataTreeModification dataTreeModification = dataTreeSnapshot.newModification();
        final YangInstanceIdentifier listId =
                YangInstanceIdentifier.create(
                        new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME),
                        new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME));

        final MapNode mapNode = getNestedList("name1", "text");
        final YangInstanceIdentifier listEntryId = listId.node(mapNode.getValue().iterator().next().getIdentifier());
        dataTreeModification.write(listId, mapNode);
        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        DataTreeCandidateTip prepare = dataTree.prepare(dataTreeModification);

        Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();

        assertThat(updates.size(), is(1));
        assertUpdate(getNormalizedNodeUpdateForAfterType(updates, MapEntryNode.class),
                listEntryId, null, mapNode.getValue().iterator().next());

        // Commit so that update can be tested next
        dataTree.commit(prepare);

        YangInstanceIdentifier listItemId = listId.node(
                new YangInstanceIdentifier.NodeIdentifierWithPredicates(NESTED_LIST_QNAME, NAME_LEAF_QNAME, "name1"));
        MapEntryNode mapEntryNode =
                getNestedList("name1", "text-update").getValue().iterator().next();

        dataTreeSnapshot = dataTree.takeSnapshot();
        dataTreeModification = dataTreeSnapshot.newModification();
        dataTreeModification.write(listItemId, mapEntryNode);
        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        prepare = dataTree.prepare(dataTreeModification);

        updates = getModificationDiff(prepare).getUpdates();
        assertThat(updates.size(), is(1 /*Actual list entry*/));
    }
//
    private void assertUpdate(final ModificationDiff.NormalizedNodeUpdate update,
                              final YangInstanceIdentifier idExpected,
                              final NormalizedNode<?, ?> beforeExpected,
                              final NormalizedNode<?, ?> afterExpected) {
        assertThat(update.getId(), is(idExpected));
        assertThat(update.getDataBefore(), is(beforeExpected));
        assertThat(update.getDataAfter(), is(afterExpected));
    }

    @Test
    public void testWriteTopContainerAndInnerList() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();

        DataTreeSnapshot dataTreeSnapshot = dataTree.takeSnapshot();
        DataTreeModification dataTreeModification = dataTreeSnapshot.newModification();

        final ContainerNode topContainer = getTopContainer("string1");
        dataTreeModification.write(TOP_CONTAINER_ID, topContainer);

        final YangInstanceIdentifier listId =
                YangInstanceIdentifier.create(
                        new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME),
                        new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME));

        final MapNode mapNode = getNestedList("name1", "text");
        final YangInstanceIdentifier listEntryId = listId.node(mapNode.getValue().iterator().next().getIdentifier());

        dataTreeModification.write(listId, mapNode);

        final DataTreeCandidateTip prepare = prepareModification(dataTree, dataTreeModification);

        final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();

        assertThat(updates.size(), is(2));
        assertThat(updates.values().size(), is(2));
        assertUpdate(getNormalizedNodeUpdateForAfterType(updates, ContainerNode.class), TOP_CONTAINER_ID, null,
                Builders.containerBuilder(topContainer).withChild(mapNode).build());
        assertUpdate(getNormalizedNodeUpdateForAfterType(updates, MapEntryNode.class), listEntryId, null, mapNode.getValue().iterator().next());
        // Assert that keys of the updates map are not wildcarded YID
        assertThat(updates.keySet(), hasItems(
                TOP_CONTAINER_ID,
                listEntryId));
    }

    private ModificationDiff.NormalizedNodeUpdate getNormalizedNodeUpdateForAfterType(
            final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates,
            final Class<? extends NormalizedNode<?, ?>> containerNodeClass) {
        return updates.values().stream()
                    .filter(update -> containerNodeClass.isAssignableFrom(update.getDataAfter().getClass()))
                    .findFirst().get();
    }

    private ModificationDiff.NormalizedNodeUpdate getNormalizedNodeUpdateForBeforeType(
            final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates,
            final Class<? extends NormalizedNode<?, ?>> containerNodeClass) {
        return updates.values().stream()
                    .filter(update -> containerNodeClass.isAssignableFrom(update.getDataBefore().getClass()))
                    .findFirst().get();
    }

    @Test
    public void testWriteDeepList() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();

        DataTreeSnapshot dataTreeSnapshot = dataTree.takeSnapshot();
        DataTreeModification dataTreeModification = dataTreeSnapshot.newModification();

        YangInstanceIdentifier listId =
                YangInstanceIdentifier.create(
                        new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME),
                        new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME));

        MapNode mapNode = getNestedList("name1", "text");
        dataTreeModification.write(listId, mapNode);

        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        DataTreeCandidateTip prepare = dataTree.prepare(dataTreeModification);
        dataTree.commit(prepare);

        dataTreeSnapshot = dataTree.takeSnapshot();
        dataTreeModification = dataTreeSnapshot.newModification();

        final YangInstanceIdentifier.NodeIdentifierWithPredicates nestedListNodeId =
                new YangInstanceIdentifier.NodeIdentifierWithPredicates(NESTED_LIST_QNAME, NAME_LEAF_QNAME, "name1");
        listId = YangInstanceIdentifier.create(
                new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME),
                new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME),
                nestedListNodeId);
        final YangInstanceIdentifier deepListId =
                listId.node(new YangInstanceIdentifier.NodeIdentifier(DEEP_LIST_QNAME));
        final YangInstanceIdentifier deepListEntryId = deepListId.node(
                new YangInstanceIdentifier.NodeIdentifierWithPredicates(DEEP_LIST_QNAME, NAME_LEAF_QNAME, "name1"));

        final MapEntryNode deepListEntry = getDeepList("name1").getValue().iterator().next();
        // Merge parent list, just to see no modifications on it
        dataTreeModification.merge(
                listId,
                Builders.mapEntryBuilder().withNodeIdentifier(nestedListNodeId)
                        .withChild(ImmutableNodes.leafNode(NAME_LEAF_QNAME, "name1")).build());
        dataTreeModification.merge(
                deepListId,
                Builders.mapBuilder()
                        .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(DEEP_LIST_QNAME))
                        .build());
        dataTreeModification.merge(
                deepListEntryId,
                deepListEntry);

        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        prepare = dataTree.prepare(dataTreeModification);
        dataTree.commit(prepare);

        final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();
        assertThat(updates.size(), is(1));
        assertUpdate(getNormalizedNodeUpdateForAfterType(updates, MapEntryNode.class), deepListEntryId, null, deepListEntry);
    }

    @Test
    public void testDeleteInnerListItem() throws Exception {
        final TipProducingDataTree dataTree = getDataTree();

        DataTreeSnapshot dataTreeSnapshot = dataTree.takeSnapshot();
        DataTreeModification dataTreeModification = dataTreeSnapshot.newModification();
        final YangInstanceIdentifier listId =
                YangInstanceIdentifier.create(
                        new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME),
                        new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME));

        final MapNode mapNode = getNestedList("name1", "text");
        dataTreeModification.write(listId, mapNode);
        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        DataTreeCandidateTip prepare = dataTree.prepare(dataTreeModification);

        // Commit so that update can be tested next
        dataTree.commit(prepare);

        YangInstanceIdentifier listItemId = listId.node(
                new YangInstanceIdentifier.NodeIdentifierWithPredicates(NESTED_LIST_QNAME, NAME_LEAF_QNAME, "name1"));

        dataTreeSnapshot = dataTree.takeSnapshot();
        dataTreeModification = dataTreeSnapshot.newModification();
        dataTreeModification.delete(listItemId);
        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        prepare = dataTree.prepare(dataTreeModification);

        final Map<YangInstanceIdentifier, ModificationDiff.NormalizedNodeUpdate> updates = getModificationDiff(prepare).getUpdates();
        assertThat(updates.size(), is(1));
        assertUpdate(getNormalizedNodeUpdateForBeforeType(updates, MapEntryNode.class), listItemId, mapNode.getValue().iterator().next(), null);
    }

    static void addNodeToTree(final DataTree dataTree, final NormalizedNode<?, ?> node,
                                              final YangInstanceIdentifier id)
            throws DataValidationFailedException {
        DataTreeSnapshot dataTreeSnapshot = dataTree.takeSnapshot();
        DataTreeModification dataTreeModification = dataTreeSnapshot.newModification();
        dataTreeModification.write(id, node);
        dataTreeModification.ready();
        dataTree.validate(dataTreeModification);
        DataTreeCandidate prepare = dataTree.prepare(dataTreeModification);
        dataTree.commit(prepare);
    }

    static TipProducingDataTree getDataTree() throws ReactorException {
        final TipProducingDataTree dataTree = InMemoryDataTreeFactory.getInstance().create(TreeType.CONFIGURATION);
        dataTree.setSchemaContext(getSchemaCtx());
        return dataTree;
    }

    static ContainerNode getTopContainer(final String stringValue) {
        return Builders.containerBuilder()
                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME))
                .withChild(ImmutableNodes.leafNode(STRING_LEAF_QNAME, stringValue))
                .build();
    }

    static MapNode getNestedList(final String listItemName, final String text) {
        return Builders.mapBuilder()
                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(NESTED_LIST_QNAME))
                .withChild(
                        Builders.mapEntryBuilder()
                                .withNodeIdentifier(
                                        new YangInstanceIdentifier.NodeIdentifierWithPredicates(NESTED_LIST_QNAME,
                                                NAME_LEAF_QNAME, listItemName))
                                .withChild(ImmutableNodes.leafNode(NAME_LEAF_QNAME, listItemName))
                                .withChild(ImmutableNodes.leafNode(TEXT_LEAF_QNAME, text))
                                .build()
                )
                .build();
    }

    private MapNode getDeepList(final String listItemName) {
        return Builders.mapBuilder()
                .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(DEEP_LIST_QNAME))
                .withChild(
                        Builders.mapEntryBuilder()
                                .withNodeIdentifier(
                                        new YangInstanceIdentifier.NodeIdentifierWithPredicates(DEEP_LIST_QNAME,
                                                NAME_LEAF_QNAME, listItemName))
                                .withChild(ImmutableNodes.leafNode(NAME_LEAF_QNAME, listItemName))
                                .build()
                )
                .build();
    }

    private static SchemaContext getSchemaCtx() throws ReactorException {
        final CrossSourceStatementReactor.BuildAction buildAction = YangInferencePipeline.RFC6020_REACTOR.newBuild();
        buildAction.addSource(new YangStatementSourceImpl(ModificationDiffTest.class.getResourceAsStream("/test-diff.yang")));
        return buildAction.buildEffective();
    }
}