HONEYCOMB-424: bump ODL dependencies to Oxygen
[honeycomb.git] / infra / data-impl / src / test / java / io / fd / honeycomb / data / impl / ModificationDiffNestedAugRewriteDeleteTest.java
1 /*
2  * Copyright (c) 2017 Cisco and/or its affiliates.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package io.fd.honeycomb.data.impl;
18
19 import static org.hamcrest.CoreMatchers.is;
20 import static org.hamcrest.MatcherAssert.assertThat;
21
22 import com.google.common.collect.ImmutableSet;
23 import org.junit.Test;
24 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
25 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
26 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeCandidateTip;
27 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
28 import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
29 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
30 import org.slf4j.Logger;
31 import org.slf4j.LoggerFactory;
32
33 public class ModificationDiffNestedAugRewriteDeleteTest extends ModificationBaseTest {
34
35     private static final Logger LOG = LoggerFactory.getLogger(ModificationDiffNestedAugRewriteDeleteTest.class);
36
37     @Test
38     public void testWriteNonPresenceNonEmptyContainerNestedAugWithContainer()
39             throws DataValidationFailedException, ReactorException {
40         final DataTree dataTree = prepareStateBeforeWithTopContainer(Builders.containerBuilder()
41                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME))
42                 .withChild(getNestedContWithContainerUnderNestedAug("val"))
43                 .build());
44         // now we have state with some data
45
46         // just empty non presence container
47         final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
48
49         final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
50         // should detect one new entry
51         LOG.debug(modificationDiff.toString());
52         assertThat(modificationDiff.getUpdates().size(), is(1));
53         // is delete
54         assertCollectionContainsOnlyDeletes(modificationDiff);
55         assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_CONTAINER_LEAF));
56     }
57
58     @Test
59     public void testWriteNonPresenceNonEmptyContainerNestedAugWithLeafList()
60             throws DataValidationFailedException, ReactorException {
61         final DataTree dataTree = prepareStateBeforeWithTopContainer(Builders.containerBuilder()
62                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME))
63                 .withChild(getNestedContWithLeafListUnderNestedAug("val"))
64                 .build());
65         // now we have state with some data
66
67         // just empty non presence container
68         final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
69
70         final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
71         // should detect one new entry
72         LOG.debug(modificationDiff.toString());
73         assertThat(modificationDiff.getUpdates().size(), is(1));
74         // is delete
75         assertCollectionContainsOnlyDeletes(modificationDiff);
76         assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_LEAF_LIST));
77     }
78
79     @Test
80     public void testWriteNonPresenceNonEmptyContainerNestedAugWithList()
81             throws DataValidationFailedException, ReactorException {
82         final DataTree dataTree = prepareStateBeforeWithTopContainer(Builders.containerBuilder()
83                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME))
84                 .withChild(getNestedContWithListUnderNestedAug("val"))
85                 .build());
86         // now we have state with some data
87
88         // just empty non presence container
89         final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
90
91         final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
92         // should detect one new entry
93         LOG.debug(modificationDiff.toString());
94         assertThat(modificationDiff.getUpdates().size(), is(1));
95         // is delete
96         assertCollectionContainsOnlyDeletes(modificationDiff);
97         assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_LIST));
98     }
99
100     @Test
101     public void testWriteNonPresenceNonEmptyContainerNestedAugWithLeaf()
102             throws DataValidationFailedException, ReactorException {
103         final DataTree dataTree = prepareStateBeforeWithTopContainer(Builders.containerBuilder()
104                 .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(TOP_CONTAINER_QNAME))
105                 .withChild(getNestedContWithLeafUnderNestedAug("val"))
106                 .build());
107         // now we have state with some data
108
109         // just empty non presence container
110         final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
111
112         final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
113         // should detect one new entry
114         LOG.debug(modificationDiff.toString());
115         assertThat(modificationDiff.getUpdates().size(), is(1));
116         // is delete
117         assertCollectionContainsOnlyDeletes(modificationDiff);
118         assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_LEAF));
119     }
120 }