31355ff8b82b879533b36b86c016e81c1a503a11
[yangtools.git] / yang / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / tree / Bug3674Test.java
1 /*
2  * Copyright (c) 2014 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.impl.schema.tree;
9
10 import static org.junit.Assert.assertEquals;
11 import org.junit.Before;
12 import org.junit.Test;
13 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidate;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModificationType;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
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 public class Bug3674Test {
26     private DataTree tree;
27
28     @Before
29     public void setUp() {
30         tree = InMemoryDataTreeFactory.getInstance().create();
31         tree.setSchemaContext(TestModel.createTestContext());
32
33         // Create the top-level container
34         final DataTreeModification mod = tree.takeSnapshot().newModification();
35         mod.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
36         mod.ready();
37         tree.commit(tree.prepare(mod));
38     }
39
40     @Test
41     public void testDeleteOfNonExistingNode() {
42         final DataTreeModification mod = tree.takeSnapshot().newModification();
43         mod.delete(TestModel.OUTER_LIST_PATH);
44         mod.ready();
45
46         final DataTreeCandidate candidate = tree.prepare(mod);
47         final DataTreeCandidateNode root = candidate.getRootNode();
48         assertEquals(ModificationType.UNMODIFIED, root.getModificationType());
49     }
50 }