import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
-import com.google.common.collect.ImmutableMap;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode;
-import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
import org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification;
-import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
import org.opendaylight.yangtools.yang.model.api.EffectiveModelContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
}
private static DataTree initDataTree(final EffectiveModelContext schemaContext, final boolean withMapNode)
- throws DataValidationFailedException {
+ throws Exception {
final var inMemoryDataTree = new InMemoryDataTreeFactory().create(
DataTreeConfiguration.DEFAULT_CONFIGURATION, schemaContext);
- final var root = Builders.containerBuilder()
+ final var root = ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(new NodeIdentifier(ROOT));
final var modificationTree = inMemoryDataTree.takeSnapshot().newModification();
- modificationTree.write(
- YangInstanceIdentifier.of(ROOT),
- withMapNode ? root.withChild(
- Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(MY_LIST)).build()).build() : root
- .build());
+ modificationTree.write(YangInstanceIdentifier.of(ROOT), withMapNode
+ ? root.withChild(ImmutableNodes.newSystemMapBuilder()
+ .withNodeIdentifier(new NodeIdentifier(MY_LIST))
+ .build())
+ .build()
+ : root.build());
modificationTree.ready();
inMemoryDataTree.validate(modificationTree);
}
@Test
- void writeInvalidContainerTest() throws DataValidationFailedException {
+ void writeInvalidContainerTest() throws Exception {
final var inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final var myList = createMap(true);
- final var root = Builders.containerBuilder()
+ final var root = ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
final var modificationTree = inMemoryDataTree.takeSnapshot().newModification();
}
@Test
- void writeInvalidMapTest() throws DataValidationFailedException {
+ void writeInvalidMapTest() throws Exception {
final var inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final var modificationTree = inMemoryDataTree.takeSnapshot().newModification();
writeMap(modificationTree, true);
}
@Test
- void writeInvalidMapEntryTest() throws DataValidationFailedException {
+ void writeInvalidMapEntryTest() throws Exception {
final var inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final var modificationTree = inMemoryDataTree.takeSnapshot().newModification();
}
private static void writeMap(final DataTreeModification modificationTree, final boolean mandatoryDataMissing) {
- modificationTree.write(YangInstanceIdentifier.of(ROOT).node(MY_LIST), createMap(mandatoryDataMissing));
+ modificationTree.write(YangInstanceIdentifier.of(ROOT, MY_LIST), createMap(mandatoryDataMissing));
}
private static SystemMapNode createMap(final boolean mandatoryDataMissing) {
- return Builders.mapBuilder()
+ return ImmutableNodes.newSystemMapBuilder()
.withNodeIdentifier(new NodeIdentifier(MY_LIST))
.withChild(mandatoryDataMissing ? createMapEntry("1", "common-value")
: createMapEntry("1", "mandatory-value", "common-value"))
}
private static void writeMapEntry(final DataTreeModification modificationTree, final Object listIdValue,
- final Object mandatoryLeafValue, final Object commonLeafValue) throws DataValidationFailedException {
+ final Object mandatoryLeafValue, final Object commonLeafValue) {
final var taskEntryNode = mandatoryLeafValue == null ? createMapEntry(listIdValue, commonLeafValue)
: createMapEntry(listIdValue, mandatoryLeafValue, commonLeafValue);
modificationTree.write(
- YangInstanceIdentifier.of(ROOT).node(MY_LIST)
- .node(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue))),
- taskEntryNode);
+ YangInstanceIdentifier.of(ROOT, MY_LIST)
+ .node(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, listIdValue)),
+ taskEntryNode);
}
private static MapEntryNode createMapEntry(final Object listIdValue, final Object mandatoryLeafValue,
final Object commonLeafValue) {
- return Builders.mapEntryBuilder()
- .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue)))
- .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
- .withChild(ImmutableNodes.leafNode(MANDATORY_LEAF, mandatoryLeafValue))
- .withChild(ImmutableNodes.leafNode(COMMON_LEAF, commonLeafValue)).build();
+ return ImmutableNodes.newMapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, listIdValue))
+ .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
+ .withChild(ImmutableNodes.leafNode(MANDATORY_LEAF, mandatoryLeafValue))
+ .withChild(ImmutableNodes.leafNode(COMMON_LEAF, commonLeafValue))
+ .build();
}
private static MapEntryNode createMapEntry(final Object listIdValue, final Object commonLeafValue) {
- return Builders.mapEntryBuilder()
- .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, ImmutableMap.of(LIST_ID, listIdValue)))
- .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
- .withChild(ImmutableNodes.leafNode(COMMON_LEAF, commonLeafValue)).build();
+ return ImmutableNodes.newMapEntryBuilder()
+ .withNodeIdentifier(NodeIdentifierWithPredicates.of(MY_LIST, LIST_ID, listIdValue))
+ .withChild(ImmutableNodes.leafNode(LIST_ID, listIdValue))
+ .withChild(ImmutableNodes.leafNode(COMMON_LEAF, commonLeafValue))
+ .build();
}
@Test
- void writeValidContainerTest() throws DataValidationFailedException {
+ void writeValidContainerTest() throws Exception {
final var inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final var myList = createMap(false);
- final var root = Builders.containerBuilder()
+ final var root = ImmutableNodes.newContainerBuilder()
.withNodeIdentifier(new NodeIdentifier(ROOT)).withChild(myList);
final var modificationTree = inMemoryDataTree.takeSnapshot().newModification();
}
@Test
- void writeValidMapTest() throws DataValidationFailedException {
+ void writeValidMapTest() throws Exception {
final var inMemoryDataTree = emptyDataTree(SCHEMA_CONTEXT);
final var modificationTree = inMemoryDataTree.takeSnapshot().newModification();
writeMap(modificationTree, false);
}
@Test
- void writeValidMapEntryTest() throws DataValidationFailedException {
+ void writeValidMapEntryTest() throws Exception {
final var inMemoryDataTree = initDataTree(SCHEMA_CONTEXT, true);
final var modificationTree = inMemoryDataTree.takeSnapshot().newModification();