2 * Copyright (c) 2014 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;
12 import org.junit.Before;
13 import org.junit.Test;
14 import org.opendaylight.yangtools.yang.data.api.schema.tree.ConflictingModificationAppliedException;
15 import org.opendaylight.yangtools.yang.data.api.schema.tree.DataValidationFailedException;
16 import org.opendaylight.yangtools.yang.data.api.schema.tree.ModifiedNodeDoesNotExistException;
17 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
19 public class ErrorReportingTest {
21 private InMemoryDataTree tree;
25 tree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create();
26 tree.setSchemaContext(TestModel.createTestContext());
30 public void writeWithoutParentExisting() {
31 InMemoryDataTreeModification modification = tree.takeSnapshot().newModification();
32 // We write node without creating parent
33 modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
36 tree.validate(modification);
37 fail("ModifiedNodeDoesNotExistException should be raised");
38 } catch (ModifiedNodeDoesNotExistException e) {
39 assertEquals(TestModel.TEST_PATH, e.getPath());
40 } catch (DataValidationFailedException e) {
41 fail("ModifiedNodeDoesNotExistException expected");
46 public void parentConcurrentlyDeletedExisting() {
47 InMemoryDataTreeModification initial = tree.takeSnapshot().newModification();
48 // We write node without creating parent
49 initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
51 // We commit transaction
52 tree.commit(tree.prepare(initial));
54 InMemoryDataTreeModification writeTx = tree.takeSnapshot().newModification();
55 InMemoryDataTreeModification deleteTx = tree.takeSnapshot().newModification();
56 deleteTx.delete(TestModel.TEST_PATH);
58 // We commit delete modification
59 tree.commit(tree.prepare(deleteTx));
61 writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
64 tree.validate(writeTx);
65 fail("ConflictingModificationAppliedException should be raised");
66 } catch (ConflictingModificationAppliedException e) {
67 assertEquals(TestModel.TEST_PATH, e.getPath());
68 } catch (DataValidationFailedException e) {
69 fail("ConflictingModificationAppliedException expected");