Migrate yang-data-impl to JUnit5
[yangtools.git] / data / yang-data-impl / src / test / java / org / opendaylight / yangtools / yang / data / impl / schema / NormalizedDataBuilderTest.java
1 /*
2  * Copyright (c) 2016 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.data.impl.schema;
9
10 import org.junit.jupiter.api.Test;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.common.XMLNamespace;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
14 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
15 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue;
16
17 class NormalizedDataBuilderTest {
18     @Test
19     void testSchemaUnaware() {
20         // Container
21         final var builder = Builders.containerBuilder()
22             .withNodeIdentifier(getNodeIdentifier("container"))
23             .withChild(Builders.<String>leafBuilder()
24                 .withNodeIdentifier(getNodeIdentifier("leaf"))
25                 .withValue("String")
26                 .build())
27             .withChild(Builders.<Integer>leafSetBuilder()
28                 .withNodeIdentifier(getNodeIdentifier("leaf"))
29                 .withChildValue(1)
30                 .withChild(Builders.<Integer>leafSetEntryBuilder()
31                     .withNodeIdentifier(getNodeWithValueIdentifier("leaf", 3))
32                     .withValue(3)
33                     .build())
34                 .build())
35             .withChild(Builders.mapBuilder()
36                 .withNodeIdentifier(getNodeIdentifier("list"))
37                 .withChild(Builders.mapEntryBuilder()
38                     .withChild(Builders.<Integer>leafBuilder()
39                         .withNodeIdentifier(getNodeIdentifier("uint32InList"))
40                         .withValue(1)
41                         .build())
42                     .withChild(Builders.containerBuilder()
43                         .withNodeIdentifier(getNodeIdentifier("containerInList"))
44                         .build())
45                     .withNodeIdentifier(NodeIdentifierWithPredicates.of(getNodeIdentifier("list").getNodeType(),
46                         getNodeIdentifier("uint32InList").getNodeType(), 1))
47                     .build())
48                 .build())
49             .withChild(Builders.<Integer>leafBuilder()
50                 .withNodeIdentifier(getNodeIdentifier("augmentUint32"))
51                 .withValue(11)
52                 .build());
53
54         // This works without schema (adding child from augment as a direct child)
55         builder.withChild(Builders.<Integer>leafBuilder()
56             .withNodeIdentifier(getNodeIdentifier("augmentUint32"))
57             .withValue(11)
58             .build());
59     }
60
61     private static <T> NodeWithValue<T> getNodeWithValueIdentifier(final String localName, final T value) {
62         return new NodeWithValue<>(getQName(localName), value);
63     }
64
65     private static QName getQName(final String localName) {
66         return QName.create(XMLNamespace.of("namespace"), localName);
67     }
68
69     private static NodeIdentifier getNodeIdentifier(final String localName) {
70         return new NodeIdentifier(getQName(localName));
71     }
72 }