Java Code Examples for org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier#of()

The following examples show how to use org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier#of() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bug8713Test.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void dataTreeCanditateValidationTest() throws Exception {
    final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug8713/");
    final LeafRefContext rootLeafRefContext = LeafRefContext.create(context);
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(
        DataTreeConfiguration.DEFAULT_OPERATIONAL, context);

    final ContainerNode root = createRootContainer();
    final YangInstanceIdentifier rootPath = YangInstanceIdentifier.of(foo("root"));
    final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
    writeModification.write(rootPath, root);
    writeModification.ready();

    final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(writeModification);

    LeafRefValidation.validate(writeContributorsCandidate, rootLeafRefContext);
    inMemoryDataTree.commit(writeContributorsCandidate);
}
 
Example 2
Source File: DataTreeCandidateValidatorTest3.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void writeDevices() throws DataValidationFailedException {
    final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
            .get();
    final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode);
    final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices);
    final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
    writeModification.write(devicesPath, devicesContainer);

    writeModification.ready();
    final DataTreeCandidate writeDevicesCandidate = inMemoryDataTree.prepare(writeModification);

    LOG.debug("*************************");
    LOG.debug("Before writeDevices: ");
    LOG.debug("*************************");
    LOG.debug("{}", inMemoryDataTree);

    boolean exception = false;
    try {
        LeafRefValidation.validate(writeDevicesCandidate, rootLeafRefContext);
    } catch (final LeafRefDataValidationFailedException e) {
        LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
        assertEquals(6, e.getValidationsErrorsCount());
        exception = true;
    }

    assertTrue(exception);

    inMemoryDataTree.commit(writeDevicesCandidate);

    LOG.debug("*************************");
    LOG.debug("After writeDevices: ");
    LOG.debug("*************************");
    LOG.debug("{}", inMemoryDataTree);
}
 
Example 3
Source File: DataTreeCandidateValidatorTest3.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void mergeDevices() throws DataValidationFailedException {

        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
                .get();

        final ContainerNode devicesContainer = createDevices2Container(devicesContSchemaNode);

        final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices);
        final DataTreeModification mergeModification = inMemoryDataTree.takeSnapshot().newModification();
        mergeModification.write(devicesPath, devicesContainer);
        mergeModification.merge(devicesPath, devicesContainer);

        mergeModification.ready();
        final DataTreeCandidate mergeDevicesCandidate = inMemoryDataTree.prepare(mergeModification);

        LOG.debug("*************************");
        LOG.debug("Before mergeDevices: ");
        LOG.debug("*************************");
        LOG.debug("{}", inMemoryDataTree);

        boolean exception = false;
        try {
            LeafRefValidation.validate(mergeDevicesCandidate, rootLeafRefContext);
        } catch (final LeafRefDataValidationFailedException e) {
            LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
            // :TODO verify errors count gz
            assertEquals(6, e.getValidationsErrorsCount());
            exception = true;
        }

        inMemoryDataTree.commit(mergeDevicesCandidate);

        LOG.debug("*************************");
        LOG.debug("After mergeDevices: ");
        LOG.debug("*************************");
        LOG.debug("{}", inMemoryDataTree);

        assertTrue(exception);
    }
 
Example 4
Source File: DataTreeCandidateValidatorTest2.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static void writeDevices() throws DataValidationFailedException {

        final ContainerSchemaNode devicesContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(devices)
                .get();

        final ContainerNode devicesContainer = createDevicesContainer(devicesContSchemaNode);

        final YangInstanceIdentifier devicesPath = YangInstanceIdentifier.of(devices);
        final DataTreeModification writeModification = inMemoryDataTree.takeSnapshot().newModification();
        writeModification.write(devicesPath, devicesContainer);

        writeModification.ready();
        final DataTreeCandidate writeDevicesCandidate = inMemoryDataTree.prepare(writeModification);

        LOG.debug("*************************");
        LOG.debug("Before writeDevices: ");
        LOG.debug("*************************");
        LOG.debug("{}", inMemoryDataTree);

        boolean exception = false;
        try {
            LeafRefValidation.validate(writeDevicesCandidate, rootLeafRefContext);
        } catch (final LeafRefDataValidationFailedException e) {
            LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());

            assertEquals(4, e.getValidationsErrorsCount());
            exception = true;
        }

        assertTrue(exception);

        inMemoryDataTree.commit(writeDevicesCandidate);

        LOG.debug("*************************");
        LOG.debug("After write: ");
        LOG.debug("*************************");
        LOG.debug("{}", inMemoryDataTree);
    }
 
Example 5
Source File: Bug4295Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private void firstModification() throws DataValidationFailedException {
    /*  MERGE */
    MapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList))
            .withChild(createOuterListEntry("1", "o-1"))
            .withChild(createOuterListEntry("2", "o-2"))
            .withChild(createOuterListEntry("3", "o-3"))
            .build();
    ContainerNode rootContainerNode = createRootContainerBuilder()
            .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
            .build();
    YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
    DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
    modification.merge(path, rootContainerNode);

    /*  WRITE INNER LIST WITH ENTRIES*/
    MapNode innerListNode = createInnerListBuilder()
        .withChild(createInnerListEntry("a", "i-a"))
        .withChild(createInnerListEntry("b", "i-b"))
        .build();
    path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2"))
            .node(innerList);
    modification.write(path, innerListNode);

    /*  COMMIT */
    modification.ready();
    inMemoryDataTree.validate(modification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
 
Example 6
Source File: Bug4295Test.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private void secondModification(final int testScenarioNumber) throws DataValidationFailedException {
    /*  MERGE */
    MapNode outerListNode = ImmutableNodes.mapNodeBuilder().withNodeIdentifier(NodeIdentifier.create(outerList))
            .withChild(createOuterListEntry("3", "o-3"))
            .withChild(createOuterListEntry("4", "o-4"))
            .withChild(createOuterListEntry("5", "o-5"))
            .build();

    ContainerNode rootContainerNode = createRootContainerBuilder()
            .withChild(createSubRootContainerBuilder().withChild(outerListNode).build())
            .build();

    YangInstanceIdentifier path = YangInstanceIdentifier.of(root);
    DataTreeModification modification = inMemoryDataTree.takeSnapshot().newModification();
    modification.merge(path, rootContainerNode);

    if (testScenarioNumber == 1) {
        /* WRITE EMPTY INNER LIST */
        writeEmptyInnerList(modification, "2");
    } else if (testScenarioNumber == 2) {
        /* WRITE INNER LIST ENTRY */
        MapEntryNode innerListEntryA = createInnerListEntry("a", "i-a-2");
        path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2"))
                .node(innerList).node(createInnerListEntryPath("a"));
        modification.write(path, innerListEntryA);
    } else if (testScenarioNumber == 3) {
        /* WRITE INNER LIST WITH ENTRIES */
        MapNode innerListNode = createInnerListBuilder().withChild(createInnerListEntry("a", "i-a-3"))
                .withChild(createInnerListEntry("c", "i-c")).build();
        path = YangInstanceIdentifier.of(root).node(subRoot).node(outerList).node(createOuterListEntryPath("2"))
                .node(innerList);
        modification.write(path, innerListNode);
    }

    /*  COMMIT */
    modification.ready();
    inMemoryDataTree.validate(modification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(modification));
}
 
Example 7
Source File: OrderedListTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public void modification1() throws DataValidationFailedException {
    OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
            new NodeIdentifier(parentOrderedList))
            .withChild(createParentOrderedListEntry("pkval1", "plfval1"))
            .withChild(createParentOrderedListEntry("pkval2", "plfval2"))
            .withChild(createParentOrderedListEntry("pkval3", "plfval3")).build();

    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(
            new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder()
            .withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build())
            .build();

    YangInstanceIdentifier path1 = YangInstanceIdentifier.of(parentContainer);

    DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();
    treeModification.write(path1, parentContainerNode);

    OrderedMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
            new NodeIdentifier(childOrderedList))
            .withChild(createChildOrderedListEntry("chkval1", "chlfval1"))
            .withChild(createChildOrderedListEntry("chkval2", "chlfval2")).build();

    YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer)
            .node(parentOrderedList).node(createParentOrderedListEntryPath("pkval2")).node(childOrderedList);

    treeModification.write(path2, childOrderedListNode);
    treeModification.ready();
    inMemoryDataTree.validate(treeModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));

    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path1);
    assertTrue(readNode.isPresent());

    readNode = snapshotAfterCommits.readNode(path2);
    assertTrue(readNode.isPresent());
}
 
Example 8
Source File: OrderedListTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
public void modification2() throws DataValidationFailedException {
    OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
            new NodeIdentifier(parentOrderedList))
            .withChild(createParentOrderedListEntry("pkval3", "plfval3updated"))
            .withChild(createParentOrderedListEntry("pkval4", "plfval4"))
            .withChild(createParentOrderedListEntry("pkval5", "plfval5")).build();

    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(
            new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder()
            .withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build())
            .build();

    DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();

    YangInstanceIdentifier path1 = YangInstanceIdentifier.of(parentContainer);
    treeModification.merge(path1, parentContainerNode);

    OrderedMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
            new NodeIdentifier(childOrderedList))
            .withChild(createChildOrderedListEntry("chkval1", "chlfval1updated"))
            .withChild(createChildOrderedListEntry("chkval2", "chlfval2updated"))
            .withChild(createChildOrderedListEntry("chkval3", "chlfval3")).build();

    YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer)
            .node(parentOrderedList).node(createParentOrderedListEntryPath("pkval2")).node(childOrderedList);
    treeModification.merge(path2, childOrderedListNode);

    treeModification.ready();
    inMemoryDataTree.validate(treeModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));

    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path1);
    assertTrue(readNode.isPresent());

    readNode = snapshotAfterCommits.readNode(path2);
    assertTrue(readNode.isPresent());
}
 
Example 9
Source File: DataTreeCandidateValidatorTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@BeforeClass
public static void init() throws DataValidationFailedException {
    context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");

    for (final Module module : context.getModules()) {
        if (module.getName().equals("leafref-validation")) {
            valModule = module;
        }
    }

    valModuleQname = valModule.getQNameModule();
    rootLeafRefContext = LeafRefContext.create(context);

    odl = QName.create(valModuleQname, "odl-project");
    project = QName.create(valModuleQname, "project");
    name = QName.create(valModuleQname, "name");
    desc = QName.create(valModuleQname, "desc");
    lead = QName.create(valModuleQname, "project-lead");
    owner = QName.create(valModuleQname, "project-owner");

    odlContributor = QName.create(valModuleQname, "odl-contributor");
    contributor = QName.create(valModuleQname, "contributor");
    odlProjectName = QName.create(valModuleQname, "odl-project-name");
    login = QName.create(valModuleQname, "login");
    contributorName = QName.create(valModuleQname, "contributor-name");

    con1 = QName.create(valModuleQname, "con1");
    l1 = QName.create(valModuleQname, "l1");
    l2 = QName.create(valModuleQname, "l2");
    odlProjectDesc = QName.create(valModuleQname, "odl-project-desc");

    ch1 = QName.create(valModuleQname, "ch1");
    ch2 = QName.create(valModuleQname, "ch2");
    leafrefInChoice = QName.create(valModuleQname, "leafref-in-choice");
    listInChoice = QName.create(valModuleQname, "list-in-choice");

    leafrefInChoiceToChoice = QName.create(valModuleQname,
            "leafref-in-choice-to-choice");
    con3 = QName.create(valModuleQname, "con3");
    list3InChoice = QName.create(valModuleQname, "list3-in-choice");
    l3 = QName.create(valModuleQname, "l3");
    choiceInCon3 = QName.create(valModuleQname, "choice-in-con3");

    listInChoiceKey = QName.create(valModuleQname, "list-in-choice-key");
    k = QName.create(valModuleQname, "k");

    leafrefLeafList = QName.create(valModuleQname, "leafref-leaf-list");

    inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);

    final DataTreeModification initialDataTreeModification = inMemoryDataTree
            .takeSnapshot().newModification();

    final ContainerSchemaNode odlProjContSchemaNode = (ContainerSchemaNode) valModule.findDataChildByName(odl)
            .get();

    final ContainerNode odlProjectContainer = createOdlContainer(odlProjContSchemaNode);

    final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
    initialDataTreeModification.write(path, odlProjectContainer);
    initialDataTreeModification.ready();

    final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
            .prepare(initialDataTreeModification);
    inMemoryDataTree.commit(writeContributorsCandidate);
}
 
Example 10
Source File: DataTreeCandidateValidatorTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static void writeContributors() throws DataValidationFailedException {

        final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
                .findDataChildByName(odlContributor).get();

        final ContainerNode contributorContainer = createBasicContributorContainer(contributorContSchemaNode);

        final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
                .of(odlContributor);
        final DataTreeModification writeModification = inMemoryDataTree
                .takeSnapshot().newModification();
        writeModification.write(contributorPath, contributorContainer);
        writeModification.ready();

        final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
                .prepare(writeModification);

        LOG.debug("*************************");
        LOG.debug("Before write of contributors: ");
        LOG.debug("*************************");
        LOG.debug(inMemoryDataTree.toString());

        boolean exception = false;
        try {
            LeafRefValidation.validate(writeContributorsCandidate,
                    rootLeafRefContext);
        } catch (final LeafRefDataValidationFailedException e) {
            LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
            assertEquals(3, e.getValidationsErrorsCount());
            exception = true;
        }

        inMemoryDataTree.commit(writeContributorsCandidate);

        LOG.debug("*************************");
        LOG.debug("After write of contributors: ");
        LOG.debug("*************************");
        LOG.debug(inMemoryDataTree.toString());

        assertTrue(exception);

    }
 
Example 11
Source File: DataTreeCandidateValidatorTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
private static void write() throws DataValidationFailedException {

        final ContainerSchemaNode contributorContSchemaNode = (ContainerSchemaNode) valModule
                .findDataChildByName(odlContributor).get();

        final ContainerNode contributorContainer = createContributorContainer(contributorContSchemaNode);

        final YangInstanceIdentifier contributorPath = YangInstanceIdentifier
                .of(odlContributor);
        final DataTreeModification writeModification = inMemoryDataTree
                .takeSnapshot().newModification();
        writeModification.write(contributorPath, contributorContainer);

        writeModification.write(YangInstanceIdentifier.of(l1),
                ImmutableNodes.leafNode(l1, "Leafref l1 under the root"));
        writeModification
                .write(YangInstanceIdentifier.of(l2), ImmutableNodes.leafNode(
                        l2, "Leafref target l2 under the root"));

        writeModification.ready();
        final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree
                .prepare(writeModification);

        LOG.debug("*************************");
        LOG.debug("Before write: ");
        LOG.debug("*************************");
        LOG.debug(inMemoryDataTree.toString());

        boolean exception = false;
        try {
            LeafRefValidation.validate(writeContributorsCandidate,
                    rootLeafRefContext);
        } catch (final LeafRefDataValidationFailedException e) {
            LOG.debug("All validation errors:{}{}", NEW_LINE, e.getMessage());
            assertEquals(12, e.getValidationsErrorsCount());
            exception = true;
        }

        inMemoryDataTree.commit(writeContributorsCandidate);

        LOG.debug("*************************");
        LOG.debug("After write: ");
        LOG.debug("*************************");
        LOG.debug(inMemoryDataTree.toString());

        assertTrue(exception);
    }
 
Example 12
Source File: DataTreeCandidateValidatorTest3.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@BeforeClass
public static void init() throws DataValidationFailedException {
    context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");

    for (final Module module : context.getModules()) {
        if (module.getName().equals("leafref-validation3")) {
            mainModule = module;
        }
    }

    rootModuleQname = mainModule.getQNameModule();
    rootLeafRefContext = LeafRefContext.create(context);


    chips = QName.create(rootModuleQname, "chips");
    chip = QName.create(rootModuleQname, "chip");
    devType = QName.create(rootModuleQname, "dev_type");
    chipDesc = QName.create(rootModuleQname, "chip_desc");

    devices = QName.create(rootModuleQname, "devices");
    device = QName.create(rootModuleQname, "device");
    typeText1 = QName.create(rootModuleQname, "type_text1");
    typeText2 = QName.create(rootModuleQname, "type_text2");
    typeText3 = QName.create(rootModuleQname, "type_text3");
    devDesc = QName.create(rootModuleQname, "dev_desc");
    sn = QName.create(rootModuleQname, "sn");
    defaultIp = QName.create(rootModuleQname, "default_ip");

    deviceTypeStr = QName.create(rootModuleQname, "device_types");
    deviceType = QName.create(rootModuleQname, "device_type");
    type1 = QName.create(rootModuleQname, "type1");
    type2 = QName.create(rootModuleQname, "type2");
    type3 = QName.create(rootModuleQname, "type3");
    desc = QName.create(rootModuleQname, "desc");

    inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);

    final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();

    final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(chips)
            .get();
    final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode);
    final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips);
    initialDataTreeModification.write(path1, chipsContainer);

    final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule
            .findDataChildByName(deviceTypeStr).get();
    final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode);
    final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr);
    initialDataTreeModification.write(path2, deviceTypesContainer);

    initialDataTreeModification.ready();
    final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification);

    inMemoryDataTree.commit(writeChipsCandidate);

    LOG.debug("{}", inMemoryDataTree);
}
 
Example 13
Source File: DataTreeCandidateValidatorTest2.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@BeforeClass
public static void init() throws DataValidationFailedException {
    context = YangParserTestUtils.parseYangResourceDirectory("/leafref-validation");

    for (final Module module : context.getModules()) {
        if (module.getName().equals("leafref-validation2")) {
            mainModule = module;
        }
    }

    rootModuleQname = mainModule.getQNameModule();
    rootLeafRefContext = LeafRefContext.create(context);

    chips = QName.create(rootModuleQname, "chips");
    chip = QName.create(rootModuleQname, "chip");
    devType = QName.create(rootModuleQname, "dev_type");
    chipDesc = QName.create(rootModuleQname, "chip_desc");

    devices = QName.create(rootModuleQname, "devices");
    device = QName.create(rootModuleQname, "device");
    typeText = QName.create(rootModuleQname, "type_text");
    devDesc = QName.create(rootModuleQname, "dev_desc");
    sn = QName.create(rootModuleQname, "sn");
    defaultIp = QName.create(rootModuleQname, "default_ip");

    deviceTypeStr = QName.create(rootModuleQname, "device_types");
    deviceType = QName.create(rootModuleQname, "device_type");
    type = QName.create(rootModuleQname, "type");
    desc = QName.create(rootModuleQname, "desc");

    inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_OPERATIONAL, context);
    final DataTreeModification initialDataTreeModification = inMemoryDataTree.takeSnapshot().newModification();
    final ContainerSchemaNode chipsListContSchemaNode = (ContainerSchemaNode) mainModule.findDataChildByName(chips)
            .get();
    final ContainerNode chipsContainer = createChipsContainer(chipsListContSchemaNode);
    final YangInstanceIdentifier path1 = YangInstanceIdentifier.of(chips);
    initialDataTreeModification.write(path1, chipsContainer);

    final ContainerSchemaNode devTypesListContSchemaNode = (ContainerSchemaNode) mainModule
            .findDataChildByName(deviceTypeStr).get();
    final ContainerNode deviceTypesContainer = createDevTypeStrContainer(devTypesListContSchemaNode);
    final YangInstanceIdentifier path2 = YangInstanceIdentifier.of(deviceTypeStr);
    initialDataTreeModification.write(path2, deviceTypesContainer);

    initialDataTreeModification.ready();
    final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification);

    inMemoryDataTree.commit(writeChipsCandidate);
    LOG.debug("{}", inMemoryDataTree);
}
 
Example 14
Source File: OrderedListTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
public void modification3() throws DataValidationFailedException {
    OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
            new NodeIdentifier(parentOrderedList))
            .withChild(createParentOrderedListEntry("pkval1", "plfval1")).build();

    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(
            new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder()
            .withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build())
            .build();

    YangInstanceIdentifier path1 = YangInstanceIdentifier.of(parentContainer);

    DataTreeModification treeModification = inMemoryDataTree.takeSnapshot().newModification();
    treeModification.write(path1, parentContainerNode);

    OrderedMapNode childOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
            new NodeIdentifier(childOrderedList))
            .withChild(createChildOrderedListEntry("chkval1", "chlfval1new")).build();

    YangInstanceIdentifier path2 = YangInstanceIdentifier.of(parentContainer).node(childContainer)
            .node(parentOrderedList)
            .node(createParentOrderedListEntryPath("pkval4")).node(childOrderedList);

    treeModification.merge(path2, childOrderedListNode);

    try {
        treeModification.ready();
        fail("Exception should have been thrown.");
        inMemoryDataTree.validate(treeModification);
        inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification));
    } catch (final IllegalArgumentException ex) {
        LOG.debug("IllegalArgumentException was thrown as expected", ex);
        assertTrue(ex.getMessage().contains("Metadata not available for modification ModifiedNode"));
    }

    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path1);
    assertTrue(readNode.isPresent());

    readNode = snapshotAfterCommits.readNode(path2);
    assertFalse(readNode.isPresent());
}
 
Example 15
Source File: OrderedListTest.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
public void modification4() throws DataValidationFailedException {
    DataTreeModification treeModification1 = inMemoryDataTree.takeSnapshot().newModification();
    DataTreeModification treeModification2 = inMemoryDataTree.takeSnapshot().newModification();

    OrderedMapNode parentOrderedListNode = Builders.orderedMapBuilder().withNodeIdentifier(
        new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval1", "plfval1"))
            .build();

    OrderedMapNode parentOrderedListNode2 = Builders.orderedMapBuilder().withNodeIdentifier(
        new NodeIdentifier(parentOrderedList)).withChild(createParentOrderedListEntry("pkval2", "plfval2"))
            .build();

    ContainerNode parentContainerNode = Builders.containerBuilder().withNodeIdentifier(
            new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder()
            .withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode).build())
            .build();

    ContainerNode parentContainerNode2 = Builders.containerBuilder().withNodeIdentifier(
            new NodeIdentifier(parentContainer)).withChild(Builders.containerBuilder()
            .withNodeIdentifier(new NodeIdentifier(childContainer)).withChild(parentOrderedListNode2).build())
            .build();

    YangInstanceIdentifier path = YangInstanceIdentifier.of(parentContainer);

    treeModification1.write(path, parentContainerNode);
    treeModification2.write(path, parentContainerNode2);
    treeModification1.ready();
    treeModification2.ready();

    inMemoryDataTree.validate(treeModification1);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification1));

    try {
        inMemoryDataTree.validate(treeModification2);
        fail("Exception should have been thrown.");
        inMemoryDataTree.commit(inMemoryDataTree.prepare(treeModification2));
    } catch (ConflictingModificationAppliedException ex) {
        LOG.debug("ConflictingModificationAppliedException was thrown as expected", ex);
        assertTrue(ex.getMessage().contains("Node was replaced by other transaction"));
    }

    DataTreeSnapshot snapshotAfterCommits = inMemoryDataTree.takeSnapshot();
    Optional<NormalizedNode<?, ?>> readNode = snapshotAfterCommits.readNode(path);
    assertTrue(readNode.isPresent());
}