2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
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
8 package org.opendaylight.yangtools.yang.data.tree.impl;
10 import static org.junit.jupiter.api.Assertions.assertEquals;
11 import static org.junit.jupiter.api.Assertions.fail;
13 import org.junit.jupiter.api.BeforeEach;
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
16 import org.opendaylight.yangtools.yang.data.spi.node.ImmutableNodes;
17 import org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException;
18 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
19 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
20 import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
21 import org.opendaylight.yangtools.yang.data.tree.api.ModifiedNodeDoesNotExistException;
22 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
24 class ErrorReportingTest extends AbstractTestModelTest {
25 private DataTree tree;
29 tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
33 void writeWithoutParentExisting() {
34 final var modification = tree.takeSnapshot().newModification();
35 // We write node without creating parent
36 modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.newSystemMapBuilder()
37 .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
41 tree.validate(modification);
42 fail("ModifiedNodeDoesNotExistException should be raised");
43 } catch (ModifiedNodeDoesNotExistException e) {
44 assertEquals(TestModel.TEST_PATH, e.getPath());
45 } catch (DataValidationFailedException e) {
46 fail("ModifiedNodeDoesNotExistException expected");
51 void parentConcurrentlyDeletedExisting() throws DataValidationFailedException {
52 final var initial = tree.takeSnapshot().newModification();
53 // We write node without creating parent
54 initial.write(TestModel.TEST_PATH,
55 ImmutableNodes.newContainerBuilder().withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME)).build());
57 // We commit transaction
58 tree.commit(tree.prepare(initial));
60 final var writeTx = tree.takeSnapshot().newModification();
61 final var deleteTx = tree.takeSnapshot().newModification();
62 deleteTx.delete(TestModel.TEST_PATH);
64 // We commit delete modification
65 tree.commit(tree.prepare(deleteTx));
67 writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.newSystemMapBuilder()
68 .withNodeIdentifier(new NodeIdentifier(TestModel.OUTER_LIST_QNAME))
72 tree.validate(writeTx);
73 fail("ConflictingModificationAppliedException should be raised");
74 } catch (ConflictingModificationAppliedException e) {
75 assertEquals(TestModel.TEST_PATH, e.getPath());
76 } catch (DataValidationFailedException e) {
77 fail("ConflictingModificationAppliedException expected");