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.api.schema.tree.ConflictingModificationAppliedException;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTree;
17 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeConfiguration;
18 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataTreeModification;
19 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
20 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
21 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
23 public class ErrorReportingTest {
25 private DataTree tree;
29 tree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL,
30 TestModel.createTestContext());
34 public void writeWithoutParentExisting() {
35 DataTreeModification modification = tree.takeSnapshot().newModification();
36 // We write node without creating parent
37 modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(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 public void parentConcurrentlyDeletedExisting() {
52 DataTreeModification initial = tree.takeSnapshot().newModification();
53 // We write node without creating parent
54 initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
56 // We commit transaction
57 tree.commit(tree.prepare(initial));
59 final DataTreeModification writeTx = tree.takeSnapshot().newModification();
60 final DataTreeModification deleteTx = tree.takeSnapshot().newModification();
61 deleteTx.delete(TestModel.TEST_PATH);
63 // We commit delete modification
64 tree.commit(tree.prepare(deleteTx));
66 writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
69 tree.validate(writeTx);
70 fail("ConflictingModificationAppliedException should be raised");
71 } catch (ConflictingModificationAppliedException e) {
72 assertEquals(TestModel.TEST_PATH, e.getPath());
73 } catch (DataValidationFailedException e) {
74 fail("ConflictingModificationAppliedException expected");