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

The following examples show how to use org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier#create() . 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: StructuralApplyModificationTest.java    From yangtools with Eclipse Public License 1.0 6 votes vote down vote up
@Test
public void testMapNodeDirectEmptyWrite() {
    final DataTreeModification addListEntryModification = inMemoryDataTree.takeSnapshot().newModification();

    // Prepare root container
    final YangInstanceIdentifier.NodeIdentifier rootContainerId = getNId(TestModel.TEST_QNAME);
    addListEntryModification.write(YangInstanceIdentifier.create(rootContainerId),
        Builders.containerBuilder().withNodeIdentifier(rootContainerId).build());

    final YangInstanceIdentifier outerListParentPath = YangInstanceIdentifier.create(getNId(TestModel.TEST_QNAME),
        getNId(TestModel.OUTER_LIST_QNAME));
    addListEntryModification.merge(outerListParentPath, ImmutableNodes.mapNode(TestModel.OUTER_LIST_QNAME));

    // Check empty map node auto deleted
    assertNodeExistence(outerListParentPath, false);
}
 
Example 2
Source File: IdentifierUtils.java    From bgpcep with Eclipse Public License 1.0 5 votes vote down vote up
private static YangInstanceIdentifier firstIdentifierOf(final YangInstanceIdentifier id,
        final Predicate<PathArgument> match) {
    final int idx = Iterables.indexOf(id.getPathArguments(), match);
    Preconditions.checkArgument(idx != -1, "Failed to find %s in %s", match, id);
    // we want the element at index idx to be included in the list
    return YangInstanceIdentifier.create(Iterables.limit(id.getPathArguments(), idx + 1));
}
 
Example 3
Source File: TestingNormalizedNodeStructuresCreator.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private static Object lf112Value() {
    return YangInstanceIdentifier.create(
            new NodeIdentifier(QName.create(COMPLEX_JSON, "cont1")),
            new NodeIdentifier(QName.create(COMPLEX_JSON, "lflst11")),
            new NodeWithValue<>(QName.create(COMPLEX_JSON, "lflst11"),"foo")
    );
}
 
Example 4
Source File: NormalizedNodesTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testFindNode() {
    final DataContainerNode<?> mockedDataContainerNode = mock(DataContainerNode.class);
    final ContainerNode mockedContainerNode = mock(ContainerNode.class);
    final LeafNode<?> mockedLeafNode = mock(LeafNode.class);
    doReturn(Optional.of(mockedContainerNode)).when(mockedDataContainerNode).getChild(any(PathArgument.class));
    doReturn(Optional.of(mockedLeafNode)).when(mockedContainerNode).getChild(any(PathArgument.class));

    final QName node1QName = QName.create("test-ns", "2016-09-16", "node1");
    final QName node2Qname = QName.create("test-ns", "2016-09-16", "node2");
    final QName node3QName = QName.create("test-ns", "2016-09-16", "node3");
    final QName node4Qname = QName.create("test-ns", "2016-09-16", "node4");

    final YangInstanceIdentifier rootPath = YangInstanceIdentifier.create(new NodeIdentifier(node1QName),
            new NodeIdentifier(node2Qname));
    final YangInstanceIdentifier childPath = YangInstanceIdentifier.create(new NodeIdentifier(node1QName),
            new NodeIdentifier(node2Qname), new NodeIdentifier(node3QName), new NodeIdentifier(node4Qname));

    assertEquals(mockedLeafNode, NormalizedNodes.findNode(rootPath, mockedDataContainerNode, childPath).get());
    assertEquals(Optional.empty(), NormalizedNodes.findNode(childPath, mockedDataContainerNode, rootPath));

    final Optional<YangInstanceIdentifier> relativePath = childPath.relativeTo(rootPath);
    final PathArgument[] pathArguments = relativePath.get().getPathArguments().toArray(new PathArgument[2]);

    assertEquals(mockedLeafNode, NormalizedNodes.findNode(Optional.of(mockedDataContainerNode),
            pathArguments).get());

    assertEquals(mockedLeafNode, NormalizedNodes.findNode(mockedDataContainerNode, pathArguments).get());
}
 
Example 5
Source File: AbstractLithiumDataInput.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private YangInstanceIdentifier readYangInstanceIdentifierInternal() throws IOException {
    int size = input.readInt();
    final Builder<PathArgument> pathArguments = ImmutableList.builderWithExpectedSize(size);
    for (int i = 0; i < size; i++) {
        pathArguments.add(readPathArgument());
    }
    return YangInstanceIdentifier.create(pathArguments.build());
}
 
Example 6
Source File: AbstractMagnesiumDataInput.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
private @NonNull YangInstanceIdentifier readYangInstanceIdentifier(final int size) throws IOException {
    if (size > 0) {
        final Builder<PathArgument> builder = ImmutableList.builderWithExpectedSize(size);
        for (int i = 0; i < size; ++i) {
            builder.add(readPathArgument());
        }
        return YangInstanceIdentifier.create(builder.build());
    } else if (size == 0) {
        return YangInstanceIdentifier.empty();
    } else {
        throw new InvalidNormalizedNodeStreamException("Invalid YangInstanceIdentifier size " + size);
    }
}
 
Example 7
Source File: StructuralApplyModificationTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testMapNodeParentAutoCreateDelete() throws DataValidationFailedException {
    final DataTreeModification addListEntryModification = inMemoryDataTree.takeSnapshot().newModification();

    // Prepare root
    final YangInstanceIdentifier.NodeIdentifier rootContainerId = getNId(TestModel.TEST_QNAME);
    addListEntryModification.write(YangInstanceIdentifier.create(rootContainerId),
        Builders.containerBuilder().withNodeIdentifier(rootContainerId).build());

    final NodeIdentifierWithPredicates outerListEntryId = NodeIdentifierWithPredicates.of(
        TestModel.OUTER_LIST_QNAME, TestModel.ID_QNAME, 1);

    // Write list entry (MapEntryNode) without creating list parent (MapNode)
    final MapEntryNode outerListEntry = Builders.mapEntryBuilder().withNodeIdentifier(outerListEntryId).build();
    final YangInstanceIdentifier outerListParentPath = YangInstanceIdentifier.create(getNId(TestModel.TEST_QNAME),
        getNId(TestModel.OUTER_LIST_QNAME));
    final YangInstanceIdentifier outerListEntryPath = outerListParentPath.node(outerListEntryId);
    addListEntryModification.write(outerListEntryPath, outerListEntry);

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

    // Check list parent auto created
    assertNodeExistence(outerListParentPath, true);

    // Now delete
    final DataTreeModification deleteListEntryModification = inMemoryDataTree.takeSnapshot().newModification();
    deleteListEntryModification.delete(outerListEntryPath);
    deleteListEntryModification.ready();
    inMemoryDataTree.validate(deleteListEntryModification);
    inMemoryDataTree.commit(inMemoryDataTree.prepare(deleteListEntryModification));

    // Check list parent auto deleted
    assertNodeExistence(outerListParentPath, false);
}
 
Example 8
Source File: StructuralApplyModificationTest.java    From yangtools with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testNonPresenceContainerDirectEmptyWrite() throws DataValidationFailedException {
    final DataTreeModification addListEntryModification = inMemoryDataTree.takeSnapshot().newModification();

    final YangInstanceIdentifier.NodeIdentifier rootContainerId = getNId(TestModel.NON_PRESENCE_QNAME);
    final YangInstanceIdentifier path = YangInstanceIdentifier.create(rootContainerId);
    addListEntryModification.write(path, Builders.containerBuilder().withNodeIdentifier(rootContainerId).build());

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

    // Check empty container auto deleted
    assertNodeExistence(path, false);
}
 
Example 9
Source File: AbstractStringInstanceIdentifierCodec.java    From yangtools with Eclipse Public License 1.0 4 votes vote down vote up
@Override
protected final YangInstanceIdentifier deserializeImpl(final String data) {
    XpathStringParsingPathArgumentBuilder builder = new XpathStringParsingPathArgumentBuilder(this,
        requireNonNull(data));
    return YangInstanceIdentifier.create(builder.build());
}