Migrate yang-data-tree-ri to JUnit5
[yangtools.git] / data / yang-data-tree-ri / src / test / java / org / opendaylight / yangtools / yang / data / tree / impl / Bug3674Test.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.data.tree.impl;
9
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11
12 import org.junit.jupiter.api.Test;
13 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
14 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
15 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
16 import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
17 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
18 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
19
20 /**
21  * BUG-3674: issuing a delete on a non-existent entry must be preserved in
22  *           DataTreeModification, but should appear as UNMODIFIED in the
23  *           resulting DataTreeCandidate.
24  */
25 class Bug3674Test extends AbstractTestModelTest {
26     private DataTree tree;
27
28     @Test
29     void testDeleteOfNonExistingNode() throws DataValidationFailedException {
30         tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
31
32         // Create the top-level container
33         final var mod = tree.takeSnapshot().newModification();
34         mod.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
35         mod.ready();
36         tree.commit(tree.prepare(mod));
37
38         final var mod2 = tree.takeSnapshot().newModification();
39         mod2.delete(TestModel.OUTER_LIST_PATH);
40         mod2.ready();
41
42         final var candidate = tree.prepare(mod2);
43         final var root = candidate.getRootNode();
44         assertEquals(ModificationType.UNMODIFIED, root.modificationType());
45     }
46 }