package org.opendaylight.yangtools.yang.data.impl.schema;
import static org.junit.Assert.assertEquals;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.URISyntaxException;
+
import java.util.Collections;
+import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class InstanceIdToNodesTest {
private final NodeWithValue<?> leafListWithValue = new NodeWithValue<>(
leafList.getNodeType(), "abcd");
- static SchemaContext createTestContext() throws URISyntaxException, FileNotFoundException, ReactorException {
- final File resourceFile = new File(InstanceIdToNodesTest.class.getResource("/filter-test.yang").toURI());
- return YangParserTestUtils.parseYangSources(resourceFile);
- }
-
@BeforeClass
- public static void setUp() throws Exception {
- ctx = createTestContext();
+ public static void setUp() {
+ ctx = YangParserTestUtils.parseYangResources(InstanceIdToNodesTest.class, "/filter-test.yang");
+ }
+ @AfterClass
+ public static void teardown() {
+ ctx = null;
}
@Test
- public void testInAugment() throws Exception {
+ public void testInAugment() {
+ final LeafNode<?> leaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf).withValue("").build();
final ContainerNode expectedFilter = Builders
.containerBuilder()
.withNodeIdentifier(rootContainer)
Builders.augmentationBuilder()
.withNodeIdentifier(augmentation)
.withChild(
- Builders.leafBuilder().withNodeIdentifier(augmentedLeaf)
- .build()).build()).build()).build();
+ leaf).build()).build()).build();
final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
- YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf));
+ YangInstanceIdentifier.create(rootContainer, outerContainer, augmentation, augmentedLeaf), leaf);
assertEquals(expectedFilter, filter);
}
@Test
- public void testInAugmentLeafOverride() throws Exception {
+ public void testInAugmentLeafOverride() {
final LeafNode<Object> lastLeaf = Builders.leafBuilder().withNodeIdentifier(augmentedLeaf)
.withValue("randomValue").build();
}
@Test
- public void testListChoice() throws Exception {
+ public void testListChoice() {
+ final LeafNode<?> leaf = Builders.leafBuilder().withNodeIdentifier(leafFromCase).withValue("").build();
final ContainerNode expectedFilter = Builders
.containerBuilder()
.withNodeIdentifier(rootContainer)
.withChild(
Builders.choiceBuilder()
.withNodeIdentifier(choice)
- .withChild(
- Builders.leafBuilder()
- .withNodeIdentifier(leafFromCase)
- .build()).build()).build()).build())
+ .withChild(leaf)
+ .build())
+ .build())
+ .build())
.build();
final NormalizedNode<?, ?> filter = ImmutableNodes.fromInstanceId(ctx,
- YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase));
+ YangInstanceIdentifier.create(rootContainer, outerList, outerListWithKey, choice, leafFromCase), leaf);
assertEquals(expectedFilter, filter);
}
@Test
- public void testTopContainerLastChildOverride() throws Exception {
+ public void testTopContainerLastChildOverride() {
final ContainerNode expectedStructure = Builders
.containerBuilder()
.withNodeIdentifier(rootContainer)
.withChild(
Builders.leafBuilder()
.withNodeIdentifier(leafFromCase)
+ .withValue("")
.build()).build()).build()).build())
.build();
}
@Test
- public void testListLastChildOverride() throws Exception {
+ public void testListLastChildOverride() {
final MapEntryNode outerListEntry = Builders
.mapEntryBuilder()
.withNodeIdentifier(outerListWithKey)
}
@Test
- public void testLeafList() throws Exception {
+ public void testLeafList() {
final ContainerNode expectedFilter = Builders
.containerBuilder()
.withNodeIdentifier(rootContainer)
YangInstanceIdentifier.create(rootContainer, leafList, leafListWithValue));
assertEquals(expectedFilter, filter);
}
-}
\ No newline at end of file
+
+ @Test
+ public void testEmptyInstanceIdentifier() {
+ assertEquals(ImmutableNodes.containerNode(SchemaContext.NAME),
+ ImmutableNodes.fromInstanceId(ctx, YangInstanceIdentifier.EMPTY));
+ }
+}