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
7 package org.opendaylight.yangtools.yang.parser.builder.impl;
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;
25 * Test suite for increasing of test coverage of LeafListSchemaNodeBuilder implementation.
27 * @see org.opendaylight.yangtools.yang.parser.builder.impl.LeafListSchemaNodeBuilder
29 * @author Lukas Sedlak <lsedlak@cisco.com>
31 * @deprecated Pre-Beryllium implementation, scheduled for removal.
34 public class LeafListSchemaNodeBuilderTest extends AbstractBuilderTest {
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);
44 final UnknownSchemaNodeBuilder unknownNodeBuilder = provideUnknownNodeBuilder();
46 baseLeafListBuilder.addUnknownNodeBuilder(unknownNodeBuilder);
47 baseLeafListBuilder.setType(Uint16.getInstance());
48 final LeafListSchemaNode leafList = baseLeafListBuilder.build();
50 assertNotNull(leafList);
51 assertFalse(leafList.getUnknownSchemaNodes().isEmpty());
52 assertEquals(leafList.getUnknownSchemaNodes().size(), 1);
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);
60 final LeafListSchemaNode extendedLeafList = leafListBuilder.build();
62 assertNotNull(extendedLeafList);
63 assertFalse(extendedLeafList.getUnknownSchemaNodes().isEmpty());
64 assertEquals(extendedLeafList.getUnknownSchemaNodes().size(), 1);
66 assertNotEquals(leafList, extendedLeafList);
68 assertTrue(extendedLeafList instanceof DerivableSchemaNode);
69 assertTrue(((DerivableSchemaNode) extendedLeafList).getOriginal().isPresent());
70 assertEquals(leafList, ((DerivableSchemaNode) extendedLeafList).getOriginal().get());
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);
81 baseLeafListBuilder.setType(Uint16.getInstance());
82 final LeafListSchemaNode leafList = baseLeafListBuilder.build();
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);
90 leafListBuilder2.setType(Uint16.getInstance());
91 final LeafListSchemaNode leafList2 = leafListBuilder2.build();
93 assertNotEquals(baseLeafListBuilder, null);
94 assertNotEquals(baseLeafListBuilder, leafListBuilder2);
96 assertNotEquals(leafList, null);
97 assertNotEquals(leafList, leafList2);
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);
106 baseLeafListBuilder.setType(Uint16.getInstance());
107 final LeafListSchemaNode leafList3 = baseLeafListBuilder.build();
109 assertNotEquals(leafListBuilder2, leafListBuilder3);
110 assertNotEquals(leafList3, leafList2);
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);
122 leafListBuilder.setType(Uint16.getInstance());
123 leafListBuilder.setDescription(descString);
124 final LeafListSchemaNode leafList = leafListBuilder.build();
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());
133 assertEquals("LeafListSchemaNodeImpl[(urn:opendaylight.rpc:def:test-model?revision=2014-01-06)base-leaf-list]",
134 leafList.toString());