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.BeforeClass;
22 import org.junit.Test;
23 import org.opendaylight.yangtools.yang.common.QName;
24 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
25 import org.opendaylight.yangtools.yang.model.api.Module;
26 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
27 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
28 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
29 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
30 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit;
31 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
32 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
33 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
34 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
35 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
36 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
37 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
38 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
39 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
40 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
41 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
42 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
43 import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
44 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
45 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
46 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl;
47 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitsSpecificationEffectiveStatementImpl;
48 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Decimal64SpecificationEffectiveStatementImpl;
49 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumSpecificationEffectiveStatementImpl;
50 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IdentityRefSpecificationEffectiveStatementImpl;
51 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl;
52 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.PatternConstraintEffectiveImpl;
53 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionSpecificationEffectiveStatementImpl;
55 public class EffectiveStatementTypeTest {
57 private static final StatementStreamSource IMPORTED_MODULE = sourceForResource("/type-tests/types.yang");
58 private static SchemaContext effectiveSchemaContext;
59 private static Module types;
61 private LeafSchemaNode currentLeaf;
64 public static void setup() throws ReactorException {
65 final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
66 reactor.addSource(IMPORTED_MODULE);
67 effectiveSchemaContext = reactor.buildEffective();
68 types = effectiveSchemaContext.findModules("types").iterator().next();
73 public void testBinary() {
74 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-binary"));
75 assertNotNull(currentLeaf.getType());
77 final BinaryTypeDefinition binaryEff = (BinaryTypeDefinition)
78 ((TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
79 .effectiveSubstatements().iterator().next()).getTypeDefinition();
81 assertNull(binaryEff.getBaseType());
82 assertNull(binaryEff.getUnits());
83 assertNull(binaryEff.getDefaultValue());
84 assertEquals("binary", binaryEff.getQName().getLocalName());
85 assertFalse(binaryEff.getLengthConstraint().isPresent());
86 assertEquals("CURRENT", binaryEff.getStatus().toString());
87 assertEquals("binary", binaryEff.getPath().getPathFromRoot().iterator().next().getLocalName());
88 assertNotNull(binaryEff.getUnknownSchemaNodes());
89 assertNull(binaryEff.getDescription());
90 assertNull(binaryEff.getReference());
94 public void testBits() {
95 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-bits"));
96 assertNotNull(currentLeaf.getType());
98 final List<BitsTypeDefinition.Bit> bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits();
99 final Bit bitEff = bitsEffIter.get(0);
100 final Bit bitEffSecond = bitsEffIter.get(1);
102 final BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatementImpl)
103 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
104 .getTypeDefinition();
106 assertNull(bitsEff.getBaseType());
107 assertNotNull(bitsEff.getQName());
108 assertEquals("bits", bitsEff.getQName().getLocalName());
109 assertEquals("bits", bitsEff.getPath().getLastComponent().getLocalName());
110 assertNotNull(bitsEff.getUnknownSchemaNodes());
111 assertNull(bitsEff.getDescription());
112 assertNull(bitsEff.getReference());
113 assertEquals("CURRENT", bitsEff.getStatus().toString());
114 assertNull(bitsEff.getUnits());
115 assertNotNull(bitsEff.toString());
116 assertNotNull(bitsEff.hashCode());
117 assertFalse(bitsEff.equals(null));
118 assertFalse(bitsEff.equals("test"));
119 assertTrue(bitsEff.equals(bitsEff));
120 assertEquals(3, bitsEff.getBits().size());
121 assertNull(bitsEff.getDefaultValue());
123 assertNotNull(bitEff.getPath());
124 assertNotNull(bitEff.getUnknownSchemaNodes());
125 assertEquals("test bit", bitEff.getDescription());
126 assertEquals("test bit ref", bitEff.getReference());
127 assertEquals("CURRENT", bitEff.getStatus().toString());
128 assertNotNull(bitEff.hashCode());
129 assertFalse(bitEff.equals(null));
130 assertFalse(bitEff.equals("test"));
131 assertFalse(bitEff.equals(bitEffSecond));
132 assertNotNull(bitEff.toString());
133 assertEquals("one", bitEff.getName());
134 assertNotNull(bitEff.getQName());
135 assertEquals(0, bitEff.getPosition());
139 public void testBoolean() {
140 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-boolean"));
141 assertNotNull(currentLeaf.getType());
142 final BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement<?>)
143 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
144 .getTypeDefinition();
146 assertNull(booleanEff.getBaseType());
147 assertNull(booleanEff.getUnits());
148 assertNull(booleanEff.getDefaultValue());
149 assertEquals("boolean", booleanEff.getQName().getLocalName());
150 assertNull(booleanEff.getPath().getParent().getParent());
151 assertNotNull(booleanEff.getUnknownSchemaNodes());
152 assertNull(booleanEff.getDescription());
153 assertNull(booleanEff.getReference());
154 assertEquals("CURRENT", booleanEff.getStatus().toString());
155 assertNotNull(booleanEff.toString());
159 public void testDecimal64() {
160 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-decimal64"));
161 assertNotNull(currentLeaf.getType());
162 final DecimalTypeDefinition decimal64Eff = ((Decimal64SpecificationEffectiveStatementImpl)
163 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
164 .getTypeDefinition();
166 assertNull(decimal64Eff.getBaseType());
167 assertNull(decimal64Eff.getUnits());
168 assertNull(decimal64Eff.getDefaultValue());
169 assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
170 assertNotNull(decimal64Eff.getUnknownSchemaNodes());
172 // FIXME: The yang model api is wrong: description/reference/status are not allowed under 'type', how come we
174 // allowed under 'type', how come we parse it?
175 assertNull(decimal64Eff.getDescription());
176 assertNull(decimal64Eff.getReference());
177 assertEquals("CURRENT", decimal64Eff.getStatus().toString());
179 assertEquals(3, decimal64Eff.getRangeConstraints().size());
180 assertNotNull(decimal64Eff.toString());
181 assertNotNull(decimal64Eff.hashCode());
182 assertTrue(decimal64Eff.getFractionDigits().equals(2));
183 assertFalse(decimal64Eff.equals(null));
184 assertFalse(decimal64Eff.equals("test"));
185 assertTrue(decimal64Eff.equals(decimal64Eff));
186 assertEquals("decimal64", decimal64Eff.getPath().getLastComponent().getLocalName());
190 public void testEmpty() {
191 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-empty"));
192 assertNotNull(currentLeaf.getType());
193 final EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement<?>)
194 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
195 .getTypeDefinition();
197 assertNull(emptyEff.getUnits());
198 assertNull(emptyEff.getDefaultValue());
199 assertNull(emptyEff.getBaseType());
200 assertEquals("empty", emptyEff.getQName().getLocalName());
201 assertNull(emptyEff.getPath().getParent().getParent());
202 assertNotNull(emptyEff.getUnknownSchemaNodes());
203 assertNull(emptyEff.getDescription());
204 assertNull(emptyEff.getReference());
205 assertEquals("CURRENT", emptyEff.getStatus().toString());
206 assertNotNull(emptyEff.toString());
210 public void testEnum() {
211 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-enum"));
212 assertNotNull(currentLeaf.getType());
213 final List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
214 final EnumPair enumEff = enumEffIter.iterator().next();
216 final EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatementImpl)
217 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
218 .getTypeDefinition();
220 assertEquals("enumeration", enumSpecEff.getQName().getLocalName());
221 assertEquals("enumeration", enumSpecEff.getPath().getLastComponent().getLocalName());
222 assertNull(enumSpecEff.getDefaultValue());
223 assertEquals(3, enumSpecEff.getValues().size());
224 assertNull(enumSpecEff.getBaseType());
225 assertNotNull(enumSpecEff.getUnknownSchemaNodes());
226 assertEquals("CURRENT", enumSpecEff.getStatus().toString());
227 assertNull(enumSpecEff.getDescription());
228 assertNull(enumSpecEff.getReference());
229 assertNull(enumSpecEff.getUnits());
230 assertNotNull(enumSpecEff.toString());
231 assertNotNull(enumSpecEff.hashCode());
232 assertFalse(enumSpecEff.equals(null));
233 assertFalse(enumSpecEff.equals("test"));
234 assertTrue(enumSpecEff.equals(enumSpecEff));
236 assertEquals("zero", enumEff.getName());
237 assertNotNull(enumEff.getUnknownSchemaNodes());
238 assertEquals("test enum", enumEff.getDescription());
239 assertEquals("test enum ref", enumEff.getReference());
240 assertEquals("CURRENT", enumEff.getStatus().toString());
241 assertEquals(0, enumEff.getValue());
245 public void testIdentityRef() {
246 currentLeaf = (LeafSchemaNode) types
247 .getDataChildByName(QName.create(types.getQNameModule(), "leaf-identityref"));
248 assertNotNull(currentLeaf.getType());
249 final IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatementImpl)
250 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
251 .getTypeDefinition();
253 assertNull(identityRefEff.getDefaultValue());
254 assertEquals("identityref", identityRefEff.getQName().getLocalName());
255 assertEquals("identityref", identityRefEff.getPath().getLastComponent().getLocalName());
256 assertNull(identityRefEff.getBaseType());
257 assertNotNull(identityRefEff.getUnknownSchemaNodes());
258 assertEquals("CURRENT", identityRefEff.getStatus().toString());
259 assertEquals("test-identity", identityRefEff.getIdentity().getQName().getLocalName());
260 assertNull(identityRefEff.getDescription());
261 assertNull(identityRefEff.getReference());
262 assertNotNull(identityRefEff.toString());
264 // FIXME: the model is wrong, but we accept units in 'type' statement
265 assertNull(identityRefEff.getUnits());
269 public void testInstanceIdentifier() {
270 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
271 "leaf-instance-identifier"));
272 assertNotNull(currentLeaf.getType());
273 final InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition)
274 ((TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements()
275 .iterator().next()).getTypeDefinition();
276 assertNotNull(instanceIdentEff.toString());
278 assertFalse(instanceIdentEff.requireInstance());
279 assertEquals("instance-identifier", instanceIdentEff.getQName().getLocalName());
280 assertEquals("instance-identifier", instanceIdentEff.getPath().getLastComponent().getLocalName());
281 assertNull(instanceIdentEff.getBaseType());
282 assertNull(instanceIdentEff.getDefaultValue());
283 assertNotNull(instanceIdentEff.getUnknownSchemaNodes());
284 assertNull(instanceIdentEff.getDescription());
285 assertNull(instanceIdentEff.getReference());
286 assertNull(instanceIdentEff.getUnits());
287 assertEquals("CURRENT", instanceIdentEff.getStatus().toString());
288 assertNotNull(instanceIdentEff.hashCode());
289 assertFalse(instanceIdentEff.equals(null));
290 assertFalse(instanceIdentEff.equals("test"));
291 assertTrue(instanceIdentEff.equals(instanceIdentEff));
295 public void testLeafref() {
296 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-leafref"));
297 assertNotNull(currentLeaf.getType());
299 final LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl)
300 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
301 .getTypeDefinition();
303 assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().toString());
304 assertNull(leafrefEff.getBaseType());
305 assertNull(leafrefEff.getUnits());
306 assertNull(leafrefEff.getDefaultValue());
307 assertNotNull(leafrefEff.toString());
308 assertEquals("leafref", leafrefEff.getQName().getLocalName());
309 assertEquals("CURRENT", leafrefEff.getStatus().toString());
310 assertNotNull(leafrefEff.getUnknownSchemaNodes());
311 assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName());
312 assertNull(leafrefEff.getDescription());
313 assertNull(leafrefEff.getReference());
314 assertNotNull(leafrefEff.hashCode());
315 assertFalse(leafrefEff.equals(null));
316 assertFalse(leafrefEff.equals("test"));
317 assertTrue(leafrefEff.equals(leafrefEff));
321 public void testIntAll() {
322 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int8"));
323 assertNotNull(currentLeaf.getType());
324 final TypeEffectiveStatement<?> int8Eff = (TypeEffectiveStatement<?>)
325 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
326 assertNotNull(int8Eff.toString());
328 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int16"));
329 assertNotNull(currentLeaf.getType());
330 final TypeEffectiveStatement<?> int16Eff = (TypeEffectiveStatement<?>)
331 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
332 assertNotNull(int16Eff.toString());
334 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int32"));
335 assertNotNull(currentLeaf.getType());
336 final TypeEffectiveStatement<?> int32Eff = (TypeEffectiveStatement<?>)
337 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
338 assertNotNull(int32Eff.toString());
340 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int64"));
341 assertNotNull(currentLeaf.getType());
342 final TypeEffectiveStatement<?> int64Eff = (TypeEffectiveStatement<?>)
343 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
344 assertNotNull(int64Eff.toString());
346 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint8"));
347 assertNotNull(currentLeaf.getType());
348 final TypeEffectiveStatement<?> uint8Eff = (TypeEffectiveStatement<?>)
349 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
350 assertNotNull(uint8Eff.toString());
352 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint16"));
353 assertNotNull(currentLeaf.getType());
354 final TypeEffectiveStatement<?> uint16Eff = (TypeEffectiveStatement<?>)
355 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
356 assertNotNull(uint16Eff.toString());
358 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint32"));
359 assertNotNull(currentLeaf.getType());
360 final TypeEffectiveStatement<?> uint32Eff = (TypeEffectiveStatement<?>)
361 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
362 assertNotNull(uint32Eff.toString());
364 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint64"));
365 assertNotNull(currentLeaf.getType());
366 final TypeEffectiveStatement<?> uint64Eff = (TypeEffectiveStatement<?>)
367 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
368 assertNotNull(uint64Eff.toString());
372 public void testUnion() {
373 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-union"));
374 assertNotNull(currentLeaf.getType());
375 final UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatementImpl)
376 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
377 .getTypeDefinition();
379 assertEquals(2, unionEff.getTypes().size());
380 assertEquals("union", unionEff.getQName().getLocalName());
381 assertEquals("CURRENT", unionEff.getStatus().toString());
382 assertNotNull(unionEff.getUnknownSchemaNodes());
383 assertNull(unionEff.getBaseType());
384 assertNull(unionEff.getUnits());
385 assertNull(unionEff.getDefaultValue());
386 assertNull(unionEff.getDescription());
387 assertNull(unionEff.getReference());
388 assertNotNull(unionEff.toString());
389 assertNotNull(unionEff.hashCode());
390 assertFalse(unionEff.equals(null));
391 assertFalse(unionEff.equals("test"));
392 assertTrue(unionEff.equals(unionEff));
393 assertEquals("union", unionEff.getPath().getLastComponent().getLocalName());
397 public void testLengthConstraint() {
398 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
399 "leaf-length-pattern"));
401 final StringTypeDefinition leafType = (StringTypeDefinition) currentLeaf.getType();
402 assertNotNull(leafType);
403 final LengthConstraint lengthConstraint = leafType.getLengthConstraint().get();
405 final Range<Integer> span = lengthConstraint.getAllowedRanges().span();
406 assertEquals(1, span.lowerEndpoint().intValue());
407 assertEquals(255, span.upperEndpoint().intValue());
408 assertNull(lengthConstraint.getReference());
409 assertNull(lengthConstraint.getDescription());
410 assertFalse(lengthConstraint.getErrorMessage().isPresent());
411 assertFalse(lengthConstraint.getErrorAppTag().isPresent());
412 assertNotNull(lengthConstraint.toString());
413 assertNotNull(lengthConstraint.hashCode());
414 assertFalse(lengthConstraint.equals(null));
415 assertFalse(lengthConstraint.equals("test"));
417 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
418 "leaf-length-pattern-second"));
419 assertNotNull(currentLeaf.getType());
420 final LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) currentLeaf.getType())
421 .getLengthConstraint().get();
422 assertFalse(lengthConstraint.equals(lengthConstraintSecond));
426 public void testPatternConstraint() {
427 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
428 "leaf-length-pattern"));
429 assertNotNull(currentLeaf.getType());
430 final PatternConstraintEffectiveImpl patternConstraint = (PatternConstraintEffectiveImpl)
431 ((StringTypeDefinition) currentLeaf.getType()).getPatternConstraints().get(0);
432 final PatternConstraintEffectiveImpl patternConstraintThird = (PatternConstraintEffectiveImpl)
433 ((StringTypeDefinition) currentLeaf.getType()).getPatternConstraints().get(0);
434 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(),
435 "leaf-length-pattern-second"));
436 assertNotNull(currentLeaf.getType());
437 final PatternConstraintEffectiveImpl patternConstraintSecond = (PatternConstraintEffectiveImpl)
438 ((StringTypeDefinition) currentLeaf.getType()).getPatternConstraints().get(0);
440 assertEquals("^[0-9a-fA-F]*$", patternConstraint.getRegularExpression());
441 assertNull(patternConstraint.getReference());
442 assertNull(patternConstraint.getDescription());
443 assertEquals(Optional.of("Supplied value does not match the regular expression ^[0-9a-fA-F]*$."),
444 patternConstraint.getErrorMessage());
445 assertEquals(Optional.of("invalid-regular-expression"), patternConstraint.getErrorAppTag());
446 assertNotNull(patternConstraint.toString());
447 assertNotNull(patternConstraint.hashCode());
448 assertFalse(patternConstraint.equals(null));
449 assertFalse(patternConstraint.equals("test"));
450 assertFalse(patternConstraint.equals(patternConstraintSecond));
451 assertTrue(patternConstraint.equals(patternConstraintThird));
455 public void testString() {
456 currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-string"));
457 assertNotNull(currentLeaf.getType());
458 final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement<?>)
459 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next())
460 .getTypeDefinition();
462 assertEquals("string", stringEff.getQName().getLocalName());
463 assertEquals("CURRENT", stringEff.getStatus().toString());
464 assertNull(stringEff.getUnits());
465 assertNull(stringEff.getDefaultValue());
466 assertNotNull(stringEff.getUnknownSchemaNodes());
467 assertNull(stringEff.getBaseType());
468 assertNull(stringEff.getDescription());
469 assertNull(stringEff.getReference());
470 assertNotNull(stringEff.toString());
471 assertNotNull(stringEff.hashCode());
472 assertFalse(stringEff.equals(null));
473 assertFalse(stringEff.equals("test"));
474 assertTrue(stringEff.equals(stringEff));
475 assertEquals("string", stringEff.getPath().getLastComponent().getLocalName());
476 assertFalse(stringEff.getLengthConstraint().isPresent());
477 assertNotNull(stringEff.getPatternConstraints());