2 * Copyright (c) 2017 Cisco and/or its affiliates.
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:
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package io.fd.honeycomb.data.impl;
19 import static org.hamcrest.CoreMatchers.is;
20 import static org.hamcrest.MatcherAssert.assertThat;
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;
33 public class ModificationDiffNestedAugRewriteDeleteTest extends ModificationBaseTest {
35 private static final Logger LOG = LoggerFactory.getLogger(ModificationDiffNestedAugRewriteDeleteTest.class);
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"))
44 // now we have state with some data
46 // just empty non presence container
47 final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
49 final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
50 // should detect one new entry
51 LOG.debug(modificationDiff.toString());
52 assertThat(modificationDiff.getUpdates().size(), is(1));
54 assertCollectionContainsOnlyDeletes(modificationDiff);
55 assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_CONTAINER_LEAF));
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"))
65 // now we have state with some data
67 // just empty non presence container
68 final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
70 final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
71 // should detect one new entry
72 LOG.debug(modificationDiff.toString());
73 assertThat(modificationDiff.getUpdates().size(), is(1));
75 assertCollectionContainsOnlyDeletes(modificationDiff);
76 assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_LEAF_LIST));
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"))
86 // now we have state with some data
88 // just empty non presence container
89 final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
91 final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
92 // should detect one new entry
93 LOG.debug(modificationDiff.toString());
94 assertThat(modificationDiff.getUpdates().size(), is(1));
96 assertCollectionContainsOnlyDeletes(modificationDiff);
97 assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_LIST));
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"))
107 // now we have state with some data
109 // just empty non presence container
110 final DataTreeCandidateTip prepareModified = prepareStateAfterEmpty(dataTree);
112 final ModificationDiff modificationDiff = getModificationDiff(prepareModified);
113 // should detect one new entry
114 LOG.debug(modificationDiff.toString());
115 assertThat(modificationDiff.getUpdates().size(), is(1));
117 assertCollectionContainsOnlyDeletes(modificationDiff);
118 assertNodeModificationPresent(modificationDiff, ImmutableSet.of(NESTED_AUG_LEAF));