2 * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved.
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
9 package org.opendaylight.yangtools.yang.stmt;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertFalse;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertNull;
15 import static org.junit.Assert.assertTrue;
16 import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
18 import com.google.common.collect.Range;
19 import java.util.List;
20 import java.util.Optional;
21 import org.junit.AfterClass;
22 import org.junit.BeforeClass;
23 import org.junit.Test;
24 import org.opendaylight.yangtools.yang.common.QName;
25 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
26 import org.opendaylight.yangtools.yang.model.api.Module;
27 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
28 import org.opendaylight.yangtools.yang.model.api.Status;
29 import org.opendaylight.yangtools.yang.model.api.stmt.LeafEffectiveStatement;
30 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
31 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
32 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
33 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
34 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
35 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
36 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
37 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
38 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
39 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
40 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
41 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
42 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
43 import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
44 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
45 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
46 import org.opendaylight.yangtools.yang.parser.rfc7950.reactor.RFC7950Reactors;
47 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.BitsSpecificationEffectiveStatement;
48 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.Decimal64SpecificationEffectiveStatement;
49 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.EnumSpecificationEffectiveStatement;
50 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.IdentityRefSpecificationEffectiveStatement;
51 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.LeafrefSpecificationEffectiveStatement;
52 import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.type.UnionSpecificationEffectiveStatement;
53 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
55 public class EffectiveStatementTypeTest {
56 private static SchemaContext effectiveSchemaContext;
57 private static Module types;
59 private LeafSchemaNode currentLeaf;
62 public static void setup() throws ReactorException {
63 effectiveSchemaContext = RFC7950Reactors.defaultReactor().newBuild()
64 .addSource(sourceForResource("/type-tests/types.yang"))
66 types = effectiveSchemaContext.findModules("types").iterator().next();
71 public static void teardown() {
72 effectiveSchemaContext = null;
77 public void testBinary() {
78 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-binary"));
79 assertNotNull(currentLeaf.getType());
81 final BinaryTypeDefinition binaryEff = (BinaryTypeDefinition)
82 ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf)
83 .effectiveSubstatements().iterator().next()).getTypeDefinition();
85 assertNull(binaryEff.getBaseType());
86 assertEquals(Optional.empty(), binaryEff.getUnits());
87 assertEquals(Optional.empty(), binaryEff.getDefaultValue());
88 assertEquals("binary", binaryEff.getQName().getLocalName());
89 assertFalse(binaryEff.getLengthConstraint().isPresent());
90 assertEquals(Status.CURRENT, binaryEff.getStatus());
91 assertEquals("binary", binaryEff.getPath().getPathFromRoot().iterator().next().getLocalName());
92 assertNotNull(binaryEff.getUnknownSchemaNodes());
93 assertFalse(binaryEff.getDescription().isPresent());
94 assertFalse(binaryEff.getReference().isPresent());
98 public void testBits() {
99 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-bits"));
100 assertNotNull(currentLeaf.getType());
102 final List<BitsTypeDefinition.Bit> bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits();
103 final Bit bitEff = bitsEffIter.get(0);
104 final Bit bitEffSecond = bitsEffIter.get(1);
106 final BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatement)
107 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
108 .getTypeDefinition();
110 assertNull(bitsEff.getBaseType());
111 assertNotNull(bitsEff.getQName());
112 assertEquals("bits", bitsEff.getQName().getLocalName());
113 assertEquals("bits", bitsEff.getPath().getLastComponent().getLocalName());
114 assertNotNull(bitsEff.getUnknownSchemaNodes());
115 assertFalse(bitsEff.getDescription().isPresent());
116 assertFalse(bitsEff.getReference().isPresent());
117 assertEquals(Status.CURRENT, bitsEff.getStatus());
118 assertEquals(Optional.empty(), bitsEff.getUnits());
119 assertNotNull(bitsEff.toString());
120 assertNotNull(bitsEff.hashCode());
121 assertFalse(bitsEff.equals(null));
122 assertFalse(bitsEff.equals("test"));
123 assertTrue(bitsEff.equals(bitsEff));
124 assertEquals(3, bitsEff.getBits().size());
125 assertEquals(Optional.empty(), bitsEff.getDefaultValue());
127 assertNotNull(bitEff.getPath());
128 assertNotNull(bitEff.getUnknownSchemaNodes());
129 assertEquals(Optional.of("test bit"), bitEff.getDescription());
130 assertEquals(Optional.of("test bit ref"), bitEff.getReference());
131 assertEquals(Status.CURRENT, bitEff.getStatus());
132 assertNotNull(bitEff.hashCode());
133 assertFalse(bitEff.equals(null));
134 assertFalse(bitEff.equals("test"));
135 assertFalse(bitEff.equals(bitEffSecond));
136 assertNotNull(bitEff.toString());
137 assertEquals("one", bitEff.getName());
138 assertNotNull(bitEff.getQName());
139 assertEquals(0, bitEff.getPosition());
143 public void testBoolean() {
144 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-boolean"));
145 assertNotNull(currentLeaf.getType());
146 final BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement<?>)
147 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
148 .getTypeDefinition();
150 assertNull(booleanEff.getBaseType());
151 assertEquals(Optional.empty(), booleanEff.getUnits());
152 assertEquals(Optional.empty(), booleanEff.getDefaultValue());
153 assertEquals("boolean", booleanEff.getQName().getLocalName());
154 assertNull(booleanEff.getPath().getParent().getParent());
155 assertNotNull(booleanEff.getUnknownSchemaNodes());
156 assertFalse(booleanEff.getDescription().isPresent());
157 assertFalse(booleanEff.getReference().isPresent());
158 assertEquals(Status.CURRENT, booleanEff.getStatus());
159 assertNotNull(booleanEff.toString());
163 public void testDecimal64() {
164 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-decimal64"));
165 assertNotNull(currentLeaf.getType());
166 final DecimalTypeDefinition decimal64Eff = ((Decimal64SpecificationEffectiveStatement)
167 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
168 .getTypeDefinition();
170 assertNull(decimal64Eff.getBaseType());
171 assertEquals(Optional.empty(), decimal64Eff.getUnits());
172 assertEquals(Optional.empty(), decimal64Eff.getDefaultValue());
173 assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
174 assertNotNull(decimal64Eff.getUnknownSchemaNodes());
176 // FIXME: The yang model api is wrong: description/reference/status are not allowed under 'type', how come we
178 // allowed under 'type', how come we parse it?
179 assertFalse(decimal64Eff.getDescription().isPresent());
180 assertFalse(decimal64Eff.getReference().isPresent());
181 assertEquals(Status.CURRENT, decimal64Eff.getStatus());
183 assertEquals(3, decimal64Eff.getRangeConstraint().get().getAllowedRanges().asRanges().size());
184 assertNotNull(decimal64Eff.toString());
185 assertNotNull(decimal64Eff.hashCode());
186 assertEquals(2, decimal64Eff.getFractionDigits());
187 assertFalse(decimal64Eff.equals(null));
188 assertFalse(decimal64Eff.equals("test"));
189 assertTrue(decimal64Eff.equals(decimal64Eff));
190 assertEquals("decimal64", decimal64Eff.getPath().getLastComponent().getLocalName());
194 public void testEmpty() {
195 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-empty"));
196 assertNotNull(currentLeaf.getType());
197 final EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement<?>)
198 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
199 .getTypeDefinition();
201 assertEquals(Optional.empty(), emptyEff.getUnits());
202 assertEquals(Optional.empty(), emptyEff.getDefaultValue());
203 assertNull(emptyEff.getBaseType());
204 assertEquals("empty", emptyEff.getQName().getLocalName());
205 assertNull(emptyEff.getPath().getParent().getParent());
206 assertNotNull(emptyEff.getUnknownSchemaNodes());
207 assertFalse(emptyEff.getDescription().isPresent());
208 assertFalse(emptyEff.getReference().isPresent());
209 assertEquals("CURRENT", emptyEff.getStatus().toString());
210 assertNotNull(emptyEff.toString());
214 public void testEnum() {
215 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-enum"));
216 assertNotNull(currentLeaf.getType());
217 final List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
218 final EnumPair enumEff = enumEffIter.iterator().next();
220 final EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatement)
221 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
222 .getTypeDefinition();
224 assertEquals("enumeration", enumSpecEff.getQName().getLocalName());
225 assertEquals("enumeration", enumSpecEff.getPath().getLastComponent().getLocalName());
226 assertEquals(Optional.empty(), enumSpecEff.getDefaultValue());
227 assertEquals(3, enumSpecEff.getValues().size());
228 assertNull(enumSpecEff.getBaseType());
229 assertNotNull(enumSpecEff.getUnknownSchemaNodes());
230 assertEquals(Status.CURRENT, enumSpecEff.getStatus());
231 assertFalse(enumSpecEff.getDescription().isPresent());
232 assertFalse(enumSpecEff.getReference().isPresent());
233 assertEquals(Optional.empty(), enumSpecEff.getUnits());
234 assertNotNull(enumSpecEff.toString());
235 assertNotNull(enumSpecEff.hashCode());
236 assertFalse(enumSpecEff.equals(null));
237 assertFalse(enumSpecEff.equals("test"));
238 assertTrue(enumSpecEff.equals(enumSpecEff));
240 assertEquals("zero", enumEff.getName());
241 assertNotNull(enumEff.getUnknownSchemaNodes());
242 assertEquals(Optional.of("test enum"), enumEff.getDescription());
243 assertEquals(Optional.of("test enum ref"), enumEff.getReference());
244 assertEquals(Status.CURRENT, enumEff.getStatus());
245 assertEquals(0, enumEff.getValue());
249 public void testIdentityRef() {
250 currentLeaf = (LeafSchemaNode) types
251 .getDataChildByName(QName.create(types.getQNameModule(), "leaf-identityref"));
252 assertNotNull(currentLeaf.getType());
253 final IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatement)
254 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
255 .getTypeDefinition();
257 assertEquals(Optional.empty(), identityRefEff.getDefaultValue());
258 assertEquals("identityref", identityRefEff.getQName().getLocalName());
259 assertEquals("identityref", identityRefEff.getPath().getLastComponent().getLocalName());
260 assertNull(identityRefEff.getBaseType());
261 assertNotNull(identityRefEff.getUnknownSchemaNodes());
262 assertEquals(Status.CURRENT, identityRefEff.getStatus());
263 assertEquals("test-identity", identityRefEff.getIdentities().iterator().next().getQName().getLocalName());
264 assertFalse(identityRefEff.getDescription().isPresent());
265 assertFalse(identityRefEff.getReference().isPresent());
266 assertNotNull(identityRefEff.toString());
268 // FIXME: the model is wrong, but we accept units in 'type' statement
269 assertEquals(Optional.empty(), identityRefEff.getUnits());
273 public void testInstanceIdentifier() {
274 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
275 "leaf-instance-identifier"));
276 assertNotNull(currentLeaf.getType());
277 final InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition)
278 ((TypeEffectiveStatement<?>) ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements()
279 .iterator().next()).getTypeDefinition();
280 assertNotNull(instanceIdentEff.toString());
282 assertFalse(instanceIdentEff.requireInstance());
283 assertEquals("instance-identifier", instanceIdentEff.getQName().getLocalName());
284 assertEquals("instance-identifier", instanceIdentEff.getPath().getLastComponent().getLocalName());
285 assertNull(instanceIdentEff.getBaseType());
286 assertEquals(Optional.empty(), instanceIdentEff.getDefaultValue());
287 assertNotNull(instanceIdentEff.getUnknownSchemaNodes());
288 assertFalse(instanceIdentEff.getDescription().isPresent());
289 assertFalse(instanceIdentEff.getReference().isPresent());
290 assertEquals(Optional.empty(), instanceIdentEff.getUnits());
291 assertEquals(Status.CURRENT, instanceIdentEff.getStatus());
292 assertNotNull(instanceIdentEff.hashCode());
293 assertFalse(instanceIdentEff.equals(null));
294 assertFalse(instanceIdentEff.equals("test"));
295 assertTrue(instanceIdentEff.equals(instanceIdentEff));
299 public void testLeafref() {
300 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-leafref"));
301 assertNotNull(currentLeaf.getType());
303 final LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatement)
304 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
305 .getTypeDefinition();
307 assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().getOriginalString());
308 assertNull(leafrefEff.getBaseType());
309 assertEquals(Optional.empty(), leafrefEff.getUnits());
310 assertEquals(Optional.empty(), leafrefEff.getDefaultValue());
311 assertNotNull(leafrefEff.toString());
312 assertEquals("leafref", leafrefEff.getQName().getLocalName());
313 assertEquals(Status.CURRENT, leafrefEff.getStatus());
314 assertNotNull(leafrefEff.getUnknownSchemaNodes());
315 assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName());
316 assertFalse(leafrefEff.getDescription().isPresent());
317 assertFalse(leafrefEff.getReference().isPresent());
318 assertNotNull(leafrefEff.hashCode());
319 assertFalse(leafrefEff.equals(null));
320 assertFalse(leafrefEff.equals("test"));
321 assertTrue(leafrefEff.equals(leafrefEff));
325 public void testLeafrefWithDeref() {
326 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName
327 .create(types.getQNameModule(), "leaf-leafref-deref"));
328 assertNotNull(currentLeaf.getType());
330 final LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatement)
331 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
332 .getTypeDefinition();
334 assertEquals("deref(../container-test)/leaf-test",
335 leafrefEff.getPathStatement().getOriginalString());
336 assertNull(leafrefEff.getBaseType());
337 assertEquals(Optional.empty(), leafrefEff.getUnits());
338 assertEquals(Optional.empty(), leafrefEff.getDefaultValue());
339 assertNotNull(leafrefEff.toString());
340 assertEquals("leafref", leafrefEff.getQName().getLocalName());
341 assertEquals(Status.CURRENT, leafrefEff.getStatus());
342 assertNotNull(leafrefEff.getUnknownSchemaNodes());
343 assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName());
344 assertFalse(leafrefEff.getDescription().isPresent());
345 assertFalse(leafrefEff.getReference().isPresent());
346 assertNotNull(leafrefEff.hashCode());
347 assertFalse(leafrefEff.equals(null));
348 assertFalse(leafrefEff.equals("test"));
349 assertTrue(leafrefEff.equals(leafrefEff));
353 public void testIntAll() {
354 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int8"));
355 assertNotNull(currentLeaf.getType());
356 final TypeEffectiveStatement<?> int8Eff = (TypeEffectiveStatement<?>)
357 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
358 assertNotNull(int8Eff.toString());
360 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int16"));
361 assertNotNull(currentLeaf.getType());
362 final TypeEffectiveStatement<?> int16Eff = (TypeEffectiveStatement<?>)
363 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
364 assertNotNull(int16Eff.toString());
366 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int32"));
367 assertNotNull(currentLeaf.getType());
368 final TypeEffectiveStatement<?> int32Eff = (TypeEffectiveStatement<?>)
369 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
370 assertNotNull(int32Eff.toString());
372 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int64"));
373 assertNotNull(currentLeaf.getType());
374 final TypeEffectiveStatement<?> int64Eff = (TypeEffectiveStatement<?>)
375 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
376 assertNotNull(int64Eff.toString());
378 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint8"));
379 assertNotNull(currentLeaf.getType());
380 final TypeEffectiveStatement<?> uint8Eff = (TypeEffectiveStatement<?>)
381 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
382 assertNotNull(uint8Eff.toString());
384 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint16"));
385 assertNotNull(currentLeaf.getType());
386 final TypeEffectiveStatement<?> uint16Eff = (TypeEffectiveStatement<?>)
387 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
388 assertNotNull(uint16Eff.toString());
390 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint32"));
391 assertNotNull(currentLeaf.getType());
392 final TypeEffectiveStatement<?> uint32Eff = (TypeEffectiveStatement<?>)
393 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
394 assertNotNull(uint32Eff.toString());
396 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint64"));
397 assertNotNull(currentLeaf.getType());
398 final TypeEffectiveStatement<?> uint64Eff = (TypeEffectiveStatement<?>)
399 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next();
400 assertNotNull(uint64Eff.toString());
404 public void testUnion() {
405 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-union"));
406 assertNotNull(currentLeaf.getType());
407 final UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatement)
408 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
409 .getTypeDefinition();
411 assertEquals(2, unionEff.getTypes().size());
412 assertEquals("union", unionEff.getQName().getLocalName());
413 assertEquals("CURRENT", unionEff.getStatus().toString());
414 assertNotNull(unionEff.getUnknownSchemaNodes());
415 assertNull(unionEff.getBaseType());
416 assertEquals(Optional.empty(), unionEff.getUnits());
417 assertEquals(Optional.empty(), unionEff.getDefaultValue());
418 assertFalse(unionEff.getDescription().isPresent());
419 assertFalse(unionEff.getReference().isPresent());
420 assertNotNull(unionEff.toString());
421 assertNotNull(unionEff.hashCode());
422 assertFalse(unionEff.equals(null));
423 assertFalse(unionEff.equals("test"));
424 assertTrue(unionEff.equals(unionEff));
425 assertEquals("union", unionEff.getPath().getLastComponent().getLocalName());
429 public void testLengthConstraint() {
430 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
431 "leaf-length-pattern"));
433 final StringTypeDefinition leafType = (StringTypeDefinition) currentLeaf.getType();
434 assertNotNull(leafType);
435 final LengthConstraint lengthConstraint = leafType.getLengthConstraint().get();
437 final Range<Integer> span = lengthConstraint.getAllowedRanges().span();
438 assertEquals(1, span.lowerEndpoint().intValue());
439 assertEquals(255, span.upperEndpoint().intValue());
440 assertFalse(lengthConstraint.getReference().isPresent());
441 assertFalse(lengthConstraint.getDescription().isPresent());
442 assertFalse(lengthConstraint.getErrorMessage().isPresent());
443 assertFalse(lengthConstraint.getErrorAppTag().isPresent());
444 assertNotNull(lengthConstraint.toString());
445 assertNotNull(lengthConstraint.hashCode());
446 assertFalse(lengthConstraint.equals(null));
447 assertFalse(lengthConstraint.equals("test"));
449 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
450 "leaf-length-pattern-second"));
451 assertNotNull(currentLeaf.getType());
452 final LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) currentLeaf.getType())
453 .getLengthConstraint().get();
454 assertFalse(lengthConstraint.equals(lengthConstraintSecond));
458 public void testPatternConstraint() {
459 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
460 "leaf-length-pattern"));
461 assertNotNull(currentLeaf.getType());
462 final PatternConstraint patternConstraint = ((StringTypeDefinition) currentLeaf.getType())
463 .getPatternConstraints().get(0);
464 final PatternConstraint patternConstraintThird = ((StringTypeDefinition) currentLeaf.getType())
465 .getPatternConstraints().get(0);
466 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
467 "leaf-length-pattern-second"));
468 assertNotNull(currentLeaf.getType());
469 final PatternConstraint patternConstraintSecond = ((StringTypeDefinition) currentLeaf.getType())
470 .getPatternConstraints().get(0);
472 assertEquals("^(?:[0-9a-fA-F]*)$", patternConstraint.getJavaPatternString());
473 assertFalse(patternConstraint.getReference().isPresent());
474 assertFalse(patternConstraint.getDescription().isPresent());
475 assertEquals(Optional.empty(), patternConstraint.getErrorMessage());
476 assertEquals(Optional.of("invalid-regular-expression"), patternConstraint.getErrorAppTag());
477 assertNotNull(patternConstraint.toString());
478 assertNotNull(patternConstraint.hashCode());
479 assertFalse(patternConstraint.equals(null));
480 assertFalse(patternConstraint.equals("test"));
481 assertFalse(patternConstraint.equals(patternConstraintSecond));
482 assertTrue(patternConstraint.equals(patternConstraintThird));
486 public void testString() {
487 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-string"));
488 assertNotNull(currentLeaf.getType());
489 final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement<?>)
490 ((LeafEffectiveStatement) currentLeaf).effectiveSubstatements().iterator().next())
491 .getTypeDefinition();
493 assertEquals("string", stringEff.getQName().getLocalName());
494 assertEquals(Status.CURRENT, stringEff.getStatus());
495 assertEquals(Optional.empty(), stringEff.getUnits());
496 assertEquals(Optional.empty(), stringEff.getDefaultValue());
497 assertNotNull(stringEff.getUnknownSchemaNodes());
498 assertNull(stringEff.getBaseType());
499 assertFalse(stringEff.getDescription().isPresent());
500 assertFalse(stringEff.getReference().isPresent());
501 assertNotNull(stringEff.toString());
502 assertNotNull(stringEff.hashCode());
503 assertFalse(stringEff.equals(null));
504 assertFalse(stringEff.equals("test"));
505 assertTrue(stringEff.equals(stringEff));
506 assertEquals("string", stringEff.getPath().getLastComponent().getLocalName());
507 assertFalse(stringEff.getLengthConstraint().isPresent());
508 assertNotNull(stringEff.getPatternConstraints());