Search in sources :

Example 21 with InMemoryDataTreeFactory

use of org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory in project yangtools by opendaylight.

the class DataTreeCandidateValidatorTest3 method init.

@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();
    initialDataTreeModification.write(YangInstanceIdentifier.of(chips), Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(chips)).addChild(Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(chip)).addChild(createChipsListEntry("dev_type_1", "desc1")).addChild(createChipsListEntry("dev_type_2", "desc2")).build()).build());
    initialDataTreeModification.write(YangInstanceIdentifier.of(deviceTypeStr), Builders.containerBuilder().withNodeIdentifier(new NodeIdentifier(deviceTypeStr)).addChild(Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(deviceType)).addChild(createDevTypeListEntry("dev_type1_1", "dev_type2_1", "dev_type3_1", "typedesc1")).addChild(createDevTypeListEntry("dev_type1_2", "dev_type2_2", "dev_type3_2", "typedesc2")).addChild(createDevTypeListEntry("dev_type1_3", "dev_type2_3", "dev_type3_3", "typedesc3")).build()).build());
    initialDataTreeModification.ready();
    final DataTreeCandidate writeChipsCandidate = inMemoryDataTree.prepare(initialDataTreeModification);
    inMemoryDataTree.commit(writeChipsCandidate);
    LOG.debug("{}", inMemoryDataTree);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) BeforeClass(org.junit.BeforeClass)

Aggregations

InMemoryDataTreeFactory (org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)21 DataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification)17 DataTreeCandidate (org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate)13 DataTree (org.opendaylight.yangtools.yang.data.tree.api.DataTree)11 Test (org.junit.Test)8 NodeIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier)8 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)6 Before (org.junit.Before)5 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 BeforeClass (org.junit.BeforeClass)3 QNameModule (org.opendaylight.yangtools.yang.common.QNameModule)3 Module (org.opendaylight.yangtools.yang.model.api.Module)3 DataTreeConfiguration (org.opendaylight.yangtools.yang.data.tree.api.DataTreeConfiguration)2 DataTreeSnapshot (org.opendaylight.yangtools.yang.data.tree.api.DataTreeSnapshot)2 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)2 ChoiceNode (org.opendaylight.yangtools.yang.data.api.schema.ChoiceNode)1 LeafNode (org.opendaylight.yangtools.yang.data.api.schema.LeafNode)1 MapNode (org.opendaylight.yangtools.yang.data.api.schema.MapNode)1 SystemMapNode (org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode)1 CursorAwareDataTreeModification (org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification)1