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.impl.schema.ImmutableNodes;
16 import org.opendaylight.yangtools.yang.data.tree.api.ConflictingModificationAppliedException;
17 import org.opendaylight.yangtools.yang.data.tree.api.DataTree;
18 import org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration;
19 import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
20 import org.opendaylight.yangtools.yang.data.tree.api.ModifiedNodeDoesNotExistException;
21 import org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory;
23 class ErrorReportingTest extends AbstractTestModelTest {
24 private DataTree tree;
28 tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
32 void writeWithoutParentExisting() {
33 final var modification = tree.takeSnapshot().newModification();
34 // We write node without creating parent
35 modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
39 tree.validate(modification);
40 fail("ModifiedNodeDoesNotExistException should be raised");
41 } catch (ModifiedNodeDoesNotExistException e) {
42 assertEquals(TestModel.TEST_PATH, e.getPath());
43 } catch (DataValidationFailedException e) {
44 fail("ModifiedNodeDoesNotExistException expected");
49 void parentConcurrentlyDeletedExisting() throws DataValidationFailedException {
50 final var initial = tree.takeSnapshot().newModification();
51 // We write node without creating parent
52 initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
54 // We commit transaction
55 tree.commit(tree.prepare(initial));
57 final var writeTx = tree.takeSnapshot().newModification();
58 final var deleteTx = tree.takeSnapshot().newModification();
59 deleteTx.delete(TestModel.TEST_PATH);
61 // We commit delete modification
62 tree.commit(tree.prepare(deleteTx));
64 writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
67 tree.validate(writeTx);
68 fail("ConflictingModificationAppliedException should be raised");
69 } catch (ConflictingModificationAppliedException e) {
70 assertEquals(TestModel.TEST_PATH, e.getPath());
71 } catch (DataValidationFailedException e) {
72 fail("ConflictingModificationAppliedException expected");