Modernize DataTreeCandidateNode API
[yangtools.git] / data / yang-data-tree-spi / src / test / java / org / opendaylight / yangtools / yang / data / tree / spi / YT1455Test.java
1 /*
2  * Copyright (c) 2022 PANTHEON.tech, s.r.o. 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.spi;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.mockito.Mockito.doReturn;
12
13 import java.util.List;
14 import org.junit.Test;
15 import org.junit.runner.RunWith;
16 import org.mockito.Mock;
17 import org.mockito.junit.MockitoJUnitRunner;
18 import org.opendaylight.yangtools.yang.common.QName;
19 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
20 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
21 import org.opendaylight.yangtools.yang.data.api.schema.DistinctNodeContainer;
22 import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
23 import org.opendaylight.yangtools.yang.data.api.schema.UnkeyedListNode;
24 import org.opendaylight.yangtools.yang.data.tree.api.ModificationType;
25
26 @RunWith(MockitoJUnitRunner.StrictStubs.class)
27 public class YT1455Test {
28     @Mock
29     public DistinctNodeContainer<PathArgument, NormalizedNode> oldData;
30     @Mock
31     public DistinctNodeContainer<PathArgument, NormalizedNode> newData;
32     @Mock
33     public UnkeyedListNode child;
34
35     @Test
36     public void testDeleteUnkeyedList() {
37         final var childId = new NodeIdentifier(QName.create("foo", "foo"));
38         doReturn(childId).when(child).name();
39         doReturn(List.of(child)).when(oldData).body();
40         doReturn(List.of()).when(newData).body();
41         doReturn(null).when(newData).childByArg(childId);
42
43         final var delta = DataTreeCandidateNodes.containerDelta(oldData, newData);
44         assertEquals(1, delta.size());
45
46         final var first = delta.iterator().next();
47         assertEquals(childId, first.name());
48         assertEquals(ModificationType.DELETE, first.modificationType());
49         assertEquals(child, first.dataBefore());
50         assertEquals(null, first.dataAfter());
51         assertEquals(0, first.childNodes().size());
52     }
53 }