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.impl.schema.tree;
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.fail;
13 import org.junit.Before;
14 import org.junit.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.DataTreeModification;
20 import org.opendaylight.yangtools.yang.data.tree.api.DataValidationFailedException;
21 import org.opendaylight.yangtools.yang.data.tree.api.ModifiedNodeDoesNotExistException;
23 public class ErrorReportingTest extends AbstractTestModelTest {
25 private DataTree tree;
29 tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, SCHEMA_CONTEXT);
33 public void writeWithoutParentExisting() {
34 DataTreeModification modification = tree.takeSnapshot().newModification();
35 // We write node without creating parent
36 modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
40 tree.validate(modification);
41 fail("ModifiedNodeDoesNotExistException should be raised");
42 } catch (ModifiedNodeDoesNotExistException e) {
43 assertEquals(TestModel.TEST_PATH, e.getPath());
44 } catch (DataValidationFailedException e) {
45 fail("ModifiedNodeDoesNotExistException expected");
50 public void parentConcurrentlyDeletedExisting() throws DataValidationFailedException {
51 DataTreeModification initial = tree.takeSnapshot().newModification();
52 // We write node without creating parent
53 initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
55 // We commit transaction
56 tree.commit(tree.prepare(initial));
58 final DataTreeModification writeTx = tree.takeSnapshot().newModification();
59 final DataTreeModification deleteTx = tree.takeSnapshot().newModification();
60 deleteTx.delete(TestModel.TEST_PATH);
62 // We commit delete modification
63 tree.commit(tree.prepare(deleteTx));
65 writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
68 tree.validate(writeTx);
69 fail("ConflictingModificationAppliedException should be raised");
70 } catch (ConflictingModificationAppliedException e) {
71 assertEquals(TestModel.TEST_PATH, e.getPath());
72 } catch (DataValidationFailedException e) {
73 fail("ConflictingModificationAppliedException expected");