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.api.schema.tree.TreeType;
18 import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
19 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
21 public class Retest_ErrorReportingTest {
23 private InMemoryDataTree tree;
26 public void setup() throws ReactorException {
27 tree = (InMemoryDataTree) InMemoryDataTreeFactory.getInstance().create(TreeType.OPERATIONAL);
28 tree.setSchemaContext(RetestModel.createTestContext());
32 public void writeWithoutParentExisting() {
33 InMemoryDataTreeModification modification = tree.takeSnapshot().newModification();
34 // We write node without creating parent
35 modification.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
38 tree.validate(modification);
39 fail("ModifiedNodeDoesNotExistException should be raised");
40 } catch (ModifiedNodeDoesNotExistException e) {
41 assertEquals(TestModel.TEST_PATH, e.getPath());
42 } catch (DataValidationFailedException e) {
43 fail("ModifiedNodeDoesNotExistException expected");
48 public void parentConcurrentlyDeletedExisting() {
49 InMemoryDataTreeModification initial = tree.takeSnapshot().newModification();
50 // We write node without creating parent
51 initial.write(TestModel.TEST_PATH, ImmutableNodes.containerNode(TestModel.TEST_QNAME));
53 // We commit transaction
54 tree.commit(tree.prepare(initial));
56 InMemoryDataTreeModification writeTx = tree.takeSnapshot().newModification();
57 InMemoryDataTreeModification deleteTx = tree.takeSnapshot().newModification();
58 deleteTx.delete(TestModel.TEST_PATH);
60 // We commit delete modification
61 tree.commit(tree.prepare(deleteTx));
63 writeTx.write(TestModel.OUTER_LIST_PATH, ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME).build());
66 tree.validate(writeTx);
67 fail("ConflictingModificationAppliedException should be raised");
68 } catch (ConflictingModificationAppliedException e) {
69 assertEquals(TestModel.TEST_PATH, e.getPath());
70 } catch (DataValidationFailedException e) {
71 fail("ConflictingModificationAppliedException expected");