2 * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.binding.test;
10 import static org.junit.Assert.*;
12 import org.junit.Test;
13 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
14 import org.opendaylight.yangtools.yang.binding.test.mock.FooChild;
15 import org.opendaylight.yangtools.yang.binding.test.mock.InstantiatedFoo;
16 import org.opendaylight.yangtools.yang.binding.test.mock.Node;
17 import org.opendaylight.yangtools.yang.binding.test.mock.NodeChild;
18 import org.opendaylight.yangtools.yang.binding.test.mock.NodeChildKey;
19 import org.opendaylight.yangtools.yang.binding.test.mock.NodeKey;
20 import org.opendaylight.yangtools.yang.binding.test.mock.Nodes;
22 public class InstanceIdentifierTest {
25 public void constructWithPredicates() {
27 InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
30 assertEquals(Nodes.class, nodes.getTargetType());
33 InstanceIdentifier<Node> node = InstanceIdentifier.builder(nodes).node(Node.class).toInstance();
36 assertEquals(Node.class, node.getTargetType());
38 assertTrue(nodes.contains(node));
42 public void fluentConstruction() {
44 InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
45 InstanceIdentifier<Node> node = InstanceIdentifier.builder(Nodes.class).child(Node.class,new NodeKey(10)).toInstance();
48 assertEquals(Node.class, node.getTargetType());
50 assertTrue(nodes.contains(node));
55 public void negativeContains() {
56 InstanceIdentifier<FooChild> fooChild = InstanceIdentifier.builder(Nodes.class).child(InstantiatedFoo.class).child(FooChild.class).build();
58 InstanceIdentifier<Node> nodeTen = InstanceIdentifier.builder(Nodes.class) //
59 .child(Node.class,new NodeKey(10)).toInstance();
60 InstanceIdentifier<Node> nodeOne = InstanceIdentifier.builder(Nodes.class) //
61 .child(Node.class,new NodeKey(1)).toInstance();
62 InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
64 assertFalse(fooChild.contains(nodeTen));
65 assertFalse(nodeTen.contains(nodes));
67 assertFalse(nodeOne.contains(nodes));
68 assertTrue(nodes.contains(nodeOne));
72 public void containsWildcarded() {
73 InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
74 InstanceIdentifier<Node> wildcarded = InstanceIdentifier.builder(Nodes.class).child(Node.class).build();
75 InstanceIdentifier<NodeChild> wildcardedChildren = InstanceIdentifier.builder(Nodes.class) //
77 .child(NodeChild.class).build();
79 assertTrue(wildcarded.isWildcarded());
80 assertTrue(wildcardedChildren.isWildcarded());
83 InstanceIdentifier<Node> nodeTen = InstanceIdentifier.builder(Nodes.class) //
84 .child(Node.class,new NodeKey(10)).toInstance();
85 InstanceIdentifier<Node> nodeOne = InstanceIdentifier.builder(Nodes.class) //
86 .child(Node.class,new NodeKey(1)).toInstance();
88 assertFalse(nodeTen.isWildcarded());
89 assertFalse(nodeOne.isWildcarded());
90 assertTrue(nodes.containsWildcarded(nodeOne));
91 assertTrue(wildcarded.containsWildcarded(nodeOne));
92 assertTrue(wildcarded.containsWildcarded(nodeTen));
95 InstanceIdentifier<NodeChild> nodeTenChildWildcarded = InstanceIdentifier.builder(Nodes.class) //
96 .child(Node.class,new NodeKey(10)).child(NodeChild.class).toInstance();
98 assertTrue(nodeTenChildWildcarded.isWildcarded());
100 InstanceIdentifier<NodeChild> nodeTenChild = InstanceIdentifier.builder(Nodes.class) //
101 .child(Node.class,new NodeKey(10)).child(NodeChild.class, new NodeChildKey(10)).toInstance();
102 InstanceIdentifier<NodeChild> nodeOneChild = InstanceIdentifier.builder(Nodes.class) //
103 .child(Node.class,new NodeKey(1)).child(NodeChild.class, new NodeChildKey(1)).toInstance();
106 assertFalse(nodeTenChildWildcarded.containsWildcarded(nodeOneChild));
107 assertTrue(nodeTenChildWildcarded.containsWildcarded(nodeTenChild));
113 InstanceIdentifier.builder(Nodes.class).child(InstantiatedFoo.class).child(FooChild.class);