586239ba0689d378a0533214dfda23a11493425f
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / parser / builder / impl / LeafListSchemaNodeBuilderTest.java
1 /*
2  * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
3  * This program and the accompanying materials are made available under the
4  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
5  * and is available at http://www.eclipse.org/legal/epl-v10.html
6  */
7 package org.opendaylight.yangtools.yang.parser.builder.impl;
8
9 import static org.junit.Assert.assertEquals;
10 import static org.junit.Assert.assertFalse;
11 import static org.junit.Assert.assertNotEquals;
12 import static org.junit.Assert.assertNotNull;
13 import static org.junit.Assert.assertNull;
14 import static org.junit.Assert.assertTrue;
15 import org.junit.Test;
16 import org.opendaylight.yangtools.yang.common.QName;
17 import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
18 import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
19 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
20 import org.opendaylight.yangtools.yang.model.api.Status;
21 import org.opendaylight.yangtools.yang.model.util.Uint16;
22 import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
23
24 /**
25  * Test suite for increasing of test coverage of LeafListSchemaNodeBuilder implementation.
26  *
27  * @see org.opendaylight.yangtools.yang.parser.builder.impl.LeafListSchemaNodeBuilder
28  *
29  * @author Lukas Sedlak <lsedlak@cisco.com>
30  *
31  * @deprecated Pre-Beryllium implementation, scheduled for removal.
32  */
33 @Deprecated
34 public class LeafListSchemaNodeBuilderTest extends AbstractBuilderTest {
35
36     @Test
37     public void testLeafListSchemaNodeBuilderWithBaseLeafListSchemaNode() {
38         final String baseLeafListLocalName = "base-leaf-list";
39         final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName);
40         final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName);
41         final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
42             10, baseLeafListQName, baseLeafListPath);
43
44         final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
45
46         baseLeafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
47         baseLeafListBuilder.setType(Uint16.getInstance());
48         final LeafListSchemaNode leafList = baseLeafListBuilder.build();
49
50         assertNotNull(leafList);
51         assertFalse(leafList.getUnknownSchemaNodes().isEmpty());
52         assertEquals(leafList.getUnknownSchemaNodes().size(), 1);
53
54         final String leafListLocalName = "extended-leaf-list";
55         final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
56         final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
57         final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
58             15, leafListQName, leafListPath, leafList);
59
60         final LeafListSchemaNode extendedLeafList = leafListBuilder.build();
61
62         assertNotNull(extendedLeafList);
63         assertFalse(extendedLeafList.getUnknownSchemaNodes().isEmpty());
64         assertEquals(extendedLeafList.getUnknownSchemaNodes().size(), 1);
65
66         assertNotEquals(leafList, extendedLeafList);
67
68         assertTrue(extendedLeafList instanceof DerivableSchemaNode);
69         assertTrue(((DerivableSchemaNode) extendedLeafList).getOriginal().isPresent());
70         assertEquals(leafList, ((DerivableSchemaNode) extendedLeafList).getOriginal().get());
71     }
72
73     @Test
74     public void testEquals() {
75         final String baseLeafListLocalName = "leaf-list1";
76         final QName baseLeafListQName = QName.create(module.getNamespace(), module.getRevision(), baseLeafListLocalName);
77         final SchemaPath baseLeafListPath = SchemaPath.create(true, baseLeafListQName);
78         final LeafListSchemaNodeBuilder baseLeafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
79             10, baseLeafListQName, baseLeafListPath);
80
81         baseLeafListBuilder.setType(Uint16.getInstance());
82         final LeafListSchemaNode leafList = baseLeafListBuilder.build();
83
84         final String leafListLocalName = "leaf-list2";
85         final QName leafListQName2 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
86         final SchemaPath leafListPath2 = SchemaPath.create(true, leafListQName2);
87         final LeafListSchemaNodeBuilder leafListBuilder2 = new LeafListSchemaNodeBuilder(module.getModuleName(),
88             10, leafListQName2, leafListPath2);
89
90         leafListBuilder2.setType(Uint16.getInstance());
91         final LeafListSchemaNode leafList2 = leafListBuilder2.build();
92
93         assertNotEquals(baseLeafListBuilder, null);
94         assertNotEquals(baseLeafListBuilder, leafListBuilder2);
95
96         assertNotEquals(leafList, null);
97         assertNotEquals(leafList, leafList2);
98
99         final QName containerQName = QName.create(module.getNamespace(), module.getRevision(), "parent-container");
100         final String leafListLocalName3 = "leaf-list2";
101         final QName leafListQName3 = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName3);
102         final SchemaPath leafListPath3 = SchemaPath.create(true, containerQName, leafListQName3);
103         final LeafListSchemaNodeBuilder leafListBuilder3 = new LeafListSchemaNodeBuilder(module.getModuleName(),
104             10, leafListQName3, leafListPath3);
105
106         baseLeafListBuilder.setType(Uint16.getInstance());
107         final LeafListSchemaNode leafList3 = baseLeafListBuilder.build();
108
109         assertNotEquals(leafListBuilder2, leafListBuilder3);
110         assertNotEquals(leafList3, leafList2);
111     }
112
113     @Test
114     public void testLeafListSchemaNodeImplProperties() {
115         final String descString = "my leaf list description";
116         final String leafListLocalName = "base-leaf-list";
117         final QName leafListQName = QName.create(module.getNamespace(), module.getRevision(), leafListLocalName);
118         final SchemaPath leafListPath = SchemaPath.create(true, leafListQName);
119         final LeafListSchemaNodeBuilder leafListBuilder = new LeafListSchemaNodeBuilder(module.getModuleName(),
120             10, leafListQName, leafListPath);
121
122         leafListBuilder.setType(Uint16.getInstance());
123         leafListBuilder.setDescription(descString);
124         final LeafListSchemaNode leafList = leafListBuilder.build();
125
126         assertEquals(leafList.getQName(), leafListQName);
127         assertEquals(leafList.getDescription(), descString);
128         assertEquals(leafList.getStatus(), Status.CURRENT);
129         assertEquals(leafList.getPath(), leafListPath);
130         assertEquals(leafList.getType(), Uint16.getInstance());
131         assertNull(leafList.getReference());
132
133         assertEquals("LeafListSchemaNodeImpl[(urn:opendaylight.rpc:def:test-model?revision=2014-01-06)base-leaf-list]",
134             leafList.toString());
135     }
136 }