Correct InstanceIdentifier.trustedCreate()
[mdsal.git] / binding / mdsal-binding-test-model / src / test / java / org / opendaylight / mdsal / binding / test / model / Mdsal818Test.java
1 /*
2  * Copyright (c) 2023 PANTHEON.tech, s.r.o. 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.mdsal.binding.test.model;
9
10 import static org.junit.jupiter.api.Assertions.assertFalse;
11 import static org.junit.jupiter.api.Assertions.assertInstanceOf;
12 import static org.junit.jupiter.api.Assertions.assertTrue;
13
14 import org.junit.jupiter.api.Test;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.Top;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelList;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.TopLevelListKey;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedList;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.mdsal.test.binding.rev140701.two.level.list.top.level.list.NestedListKey;
20 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
21 import org.opendaylight.yangtools.yang.binding.KeyedInstanceIdentifier;
22
23 class Mdsal818Test {
24     @Test
25     void simpleWildcardInstanceIdentitifer() {
26         final var id = InstanceIdentifier.builder(Top.class).child(TopLevelList.class).build();
27         assertTrue(id.isWildcarded());
28         assertFalse(id instanceof KeyedInstanceIdentifier);
29     }
30
31     @Test
32     void simpleKeyedInstanceIdentitifer() {
33         final var first = assertInstanceOf(KeyedInstanceIdentifier.class, InstanceIdentifier.builder(Top.class)
34             .child(TopLevelList.class, new TopLevelListKey("foo"))
35             .build());
36         assertFalse(first.isWildcarded());
37     }
38
39     @Test
40     void wildcardKeyedInstanceIdentitifer() {
41         final var first = assertInstanceOf(KeyedInstanceIdentifier.class, InstanceIdentifier.builder(Top.class)
42             .child(TopLevelList.class)
43             .child(NestedList.class, new NestedListKey("foo"))
44             .build());
45         assertTrue(first.isWildcarded());
46     }
47 }