Search in sources :

Example 16 with InMemoryDataTreeFactory

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

the class ConfigStatementValidationTest method testOnPathCaseLeafFail.

@Test(expected = SchemaValidationFailedException.class)
public void testOnPathCaseLeafFail() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
    final YangInstanceIdentifier.NodeIdentifier choice1Id = new YangInstanceIdentifier.NodeIdentifier(QName.create(TestModel.TEST_QNAME, "choice1"));
    final YangInstanceIdentifier.NodeIdentifier case2ContId = new YangInstanceIdentifier.NodeIdentifier(QName.create(TestModel.TEST_QNAME, "case2-cont"));
    final YangInstanceIdentifier ii = TestModel.TEST_PATH.node(choice1Id).node(case2ContId);
    final ContainerNode case2Cont = Builders.containerBuilder().withNodeIdentifier(case2ContId).withChild(leafNode(QName.create(TestModel.TEST_QNAME, "case2-leaf1"), "leaf-value")).build();
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(ii, case2Cont);
    modificationTree.ready();
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 17 with InMemoryDataTreeFactory

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

the class ConfigStatementValidationTest method testOnPathFail.

@Test(expected = SchemaValidationFailedException.class)
public void testOnPathFail() throws DataValidationFailedException {
    final DataTree inMemoryDataTree = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, SCHEMA_CONTEXT);
    final DataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    final YangInstanceIdentifier ii = OUTER_LIST_1_PATH.node(new YangInstanceIdentifier.NodeIdentifier(TestModel.INNER_LIST_QNAME)).node(INNER_FOO_ENTRY_NODE.getIdentifier());
    modificationTree.write(ii, INNER_FOO_ENTRY_NODE);
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) DataTree(org.opendaylight.yangtools.yang.data.tree.api.DataTree) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Test(org.junit.Test)

Example 18 with InMemoryDataTreeFactory

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

the class InMemoryDataTreeBenchmark method setup.

@Setup(Level.Trial)
public void setup() throws DataValidationFailedException {
    datastore = new InMemoryDataTreeFactory().create(DataTreeConfiguration.DEFAULT_CONFIGURATION, BenchmarkModel.createTestContext());
    final DataTreeModification modification = begin();
    modification.write(BenchmarkModel.TEST_PATH, ImmutableContainerNodeBuilder.create().withNodeIdentifier(BenchmarkModel.TEST).withChild(EMPTY_OUTER_LIST).build());
    commit(modification);
}
Also used : CursorAwareDataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.CursorAwareDataTreeModification) DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory) Setup(org.openjdk.jmh.annotations.Setup)

Example 19 with InMemoryDataTreeFactory

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

the class UniqueConstraintTest method initDataTree.

private static InMemoryDataTree initDataTree(final EffectiveModelContext schemaContext, final boolean uniqueIndex) throws DataValidationFailedException {
    final InMemoryDataTree inMemoryDataTree = (InMemoryDataTree) new InMemoryDataTreeFactory().create(new DataTreeConfiguration.Builder(TreeType.CONFIGURATION).setUniqueIndexes(uniqueIndex).build());
    inMemoryDataTree.setEffectiveModelContext(schemaContext);
    final MapNode taskNode = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(TASK)).build();
    final InMemoryDataTreeModification modificationTree = inMemoryDataTree.takeSnapshot().newModification();
    modificationTree.write(YangInstanceIdentifier.of(TASK_CONTAINER).node(TASK), taskNode);
    modificationTree.ready();
    inMemoryDataTree.validate(modificationTree);
    final DataTreeCandidate prepare = inMemoryDataTree.prepare(modificationTree);
    inMemoryDataTree.commit(prepare);
    return inMemoryDataTree;
}
Also used : DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) NodeIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier) MapNode(org.opendaylight.yangtools.yang.data.api.schema.MapNode) InMemoryDataTreeFactory(org.opendaylight.yangtools.yang.data.tree.impl.di.InMemoryDataTreeFactory)

Example 20 with InMemoryDataTreeFactory

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

the class DataTreeCandidateValidatorTest 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-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 ContainerNode odlProjectContainer = createOdlContainer();
    final YangInstanceIdentifier path = YangInstanceIdentifier.of(odl);
    initialDataTreeModification.write(path, odlProjectContainer);
    initialDataTreeModification.ready();
    final DataTreeCandidate writeContributorsCandidate = inMemoryDataTree.prepare(initialDataTreeModification);
    inMemoryDataTree.commit(writeContributorsCandidate);
}
Also used : DataTreeModification(org.opendaylight.yangtools.yang.data.tree.api.DataTreeModification) DataTreeCandidate(org.opendaylight.yangtools.yang.data.tree.api.DataTreeCandidate) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) QNameModule(org.opendaylight.yangtools.yang.common.QNameModule) Module(org.opendaylight.yangtools.yang.model.api.Module) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) 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