Merge "Update interface to hide Dispatcher"
[yangtools.git] / yang / yang-binding / src / test / java / org / opendaylight / yangtools / yang / binding / test / InstanceIdentifierTest.java
1 /*
2  * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.yangtools.yang.binding.test;
9
10 import static org.junit.Assert.assertEquals;
11 import static org.junit.Assert.assertFalse;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertTrue;
14
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
17 import org.opendaylight.yangtools.yang.binding.test.mock.FooChild;
18 import org.opendaylight.yangtools.yang.binding.test.mock.InstantiatedFoo;
19 import org.opendaylight.yangtools.yang.binding.test.mock.Node;
20 import org.opendaylight.yangtools.yang.binding.test.mock.NodeChild;
21 import org.opendaylight.yangtools.yang.binding.test.mock.NodeChildKey;
22 import org.opendaylight.yangtools.yang.binding.test.mock.NodeKey;
23 import org.opendaylight.yangtools.yang.binding.test.mock.Nodes;
24
25 public class InstanceIdentifierTest {
26
27     @Test
28     public void constructWithPredicates() {
29
30         InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
31
32         assertNotNull(nodes);
33         assertEquals(Nodes.class, nodes.getTargetType());
34
35
36         InstanceIdentifier<Node> node = InstanceIdentifier.builder(nodes).child(Node.class).toInstance();
37
38         assertNotNull(node);
39         assertEquals(Node.class, node.getTargetType());
40
41         assertTrue(nodes.contains(node));
42     }
43
44     @Test
45     public void fluentConstruction() {
46
47         InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
48         InstanceIdentifier<Node> node = InstanceIdentifier.builder(Nodes.class).child(Node.class,new NodeKey(10)).toInstance();
49
50         assertNotNull(node);
51         assertEquals(Node.class, node.getTargetType());
52
53         assertTrue(nodes.contains(node));
54     }
55
56
57     @Test
58     public void negativeContains() {
59         InstanceIdentifier<FooChild> fooChild = InstanceIdentifier.builder(Nodes.class).child(InstantiatedFoo.class).child(FooChild.class).build();
60
61         InstanceIdentifier<Node> nodeTen = InstanceIdentifier.builder(Nodes.class) //
62                 .child(Node.class,new NodeKey(10)).toInstance();
63         InstanceIdentifier<Node> nodeOne = InstanceIdentifier.builder(Nodes.class) //
64                 .child(Node.class,new NodeKey(1)).toInstance();
65         InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
66
67         assertFalse(fooChild.contains(nodeTen));
68         assertFalse(nodeTen.contains(nodes));
69
70         assertFalse(nodeOne.contains(nodes));
71         assertTrue(nodes.contains(nodeOne));
72     }
73
74     @Test
75     public void containsWildcarded() {
76         InstanceIdentifier<Nodes> nodes = InstanceIdentifier.builder(Nodes.class).toInstance();
77         InstanceIdentifier<Node> wildcarded = InstanceIdentifier.builder(Nodes.class).child(Node.class).build();
78         InstanceIdentifier<NodeChild> wildcardedChildren = InstanceIdentifier.builder(Nodes.class) //
79                 .child(Node.class) //
80                 .child(NodeChild.class).build();
81
82         assertTrue(wildcarded.isWildcarded());
83         assertTrue(wildcardedChildren.isWildcarded());
84
85
86         InstanceIdentifier<Node> nodeTen = InstanceIdentifier.builder(Nodes.class) //
87                 .child(Node.class,new NodeKey(10)).toInstance();
88         InstanceIdentifier<Node> nodeOne = InstanceIdentifier.builder(Nodes.class) //
89                 .child(Node.class,new NodeKey(1)).toInstance();
90
91         assertFalse(nodeTen.isWildcarded());
92         assertFalse(nodeOne.isWildcarded());
93         assertTrue(nodes.containsWildcarded(nodeOne));
94         assertTrue(wildcarded.containsWildcarded(nodeOne));
95         assertTrue(wildcarded.containsWildcarded(nodeTen));
96
97
98         InstanceIdentifier<NodeChild> nodeTenChildWildcarded = InstanceIdentifier.builder(Nodes.class) //
99                 .child(Node.class,new NodeKey(10)).child(NodeChild.class).toInstance();
100
101         assertTrue(nodeTenChildWildcarded.isWildcarded());
102
103         InstanceIdentifier<NodeChild> nodeTenChild = InstanceIdentifier.builder(Nodes.class) //
104                 .child(Node.class,new NodeKey(10)).child(NodeChild.class, new NodeChildKey(10)).toInstance();
105         InstanceIdentifier<NodeChild> nodeOneChild = InstanceIdentifier.builder(Nodes.class) //
106                 .child(Node.class,new NodeKey(1)).child(NodeChild.class, new NodeChildKey(1)).toInstance();
107
108
109         assertFalse(nodeTenChildWildcarded.containsWildcarded(nodeOneChild));
110         assertTrue(nodeTenChildWildcarded.containsWildcarded(nodeTenChild));
111
112     }
113
114
115     void childOfTest() {
116         InstanceIdentifier.builder(Nodes.class).child(InstantiatedFoo.class).child(FooChild.class);
117     }
118
119 }