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;
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;
18 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
20 public class Retest_ErrorReportingTest {
22 private InMemoryDataTree tree;
25 public void setup() throws ReactorException {
26 tree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create();
27 tree.setSchemaContext(RetestModel.createTestContext());
31 public void writeWithoutParentExisting() {
32 InMemoryDataTreeModification modification = tree.takeSnapshot().newModification();
33 // We write node without creating parent
34 modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
37 tree.validate(modification);
38 fail("ModifiedNodeDoesNotExistException should be raised");
39 } catch (ModifiedNodeDoesNotExistException e) {
40 assertEquals(TestModel.TEST_PATH, e.getPath());
41 } catch (DataValidationFailedException e) {
42 fail("ModifiedNodeDoesNotExistException expected");
47 public void parentConcurrentlyDeletedExisting() {
48 InMemoryDataTreeModification initial = tree.takeSnapshot().newModification();
49 // We write node without creating parent
50 initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
52 // We commit transaction
53 tree.commit(tree.prepare(initial));
55 InMemoryDataTreeModification writeTx = tree.takeSnapshot().newModification();
56 InMemoryDataTreeModification deleteTx = tree.takeSnapshot().newModification();
57 deleteTx.delete(TestModel.TEST_PATH);
59 // We commit delete modification
60 tree.commit(tree.prepare(deleteTx));
62 writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
65 tree.validate(writeTx);
66 fail("ConflictingModificationAppliedException should be raised");
67 } catch (ConflictingModificationAppliedException e) {
68 assertEquals(TestModel.TEST_PATH, e.getPath());
69 } catch (DataValidationFailedException e) {
70 fail("ConflictingModificationAppliedException expected");