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;
17 import java.util.List;
18 import org.junit.Before;
19 import org.junit.Test;
20 import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
21 import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement;
22 import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
23 import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition;
24 import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
25 import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
26 import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
27 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
28 import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
29 import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition;
30 import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
31 import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
32 import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
33 import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
34 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
35 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
36 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
37 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
38 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
39 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl;
40 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitEffectiveStatementImpl;
41 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitsSpecificationEffectiveStatementImpl;
42 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Decimal64SpecificationEffectiveStatementImpl;
43 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumEffectiveStatementImpl;
44 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumSpecificationEffectiveStatementImpl;
45 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IdentityRefSpecificationEffectiveStatementImpl;
46 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl;
47 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.PatternConstraintEffectiveImpl;
48 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionSpecificationEffectiveStatementImpl;
50 public class EffectiveStatementTypeTest {
52 private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl(
53 "/type-tests/types.yang", false);
54 private static EffectiveSchemaContext effectiveSchemaContext;
55 private static LeafSchemaNode currentLeaf;
58 public void setup() throws ReactorException {
59 CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
60 reactor.addSource(IMPORTED_MODULE);
61 effectiveSchemaContext = reactor.buildEffective();
65 public void testBinary() {
66 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
67 .getDataChildByName("leaf-binary");
68 assertNotNull(currentLeaf.getType());
70 BinaryTypeDefinition binaryEff = (BinaryTypeDefinition) ((TypeEffectiveStatement<?>)
71 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
73 assertNull(binaryEff.getBaseType());
74 assertNull(binaryEff.getUnits());
75 assertNull(binaryEff.getDefaultValue());
76 assertEquals("binary", binaryEff.getQName().getLocalName());
77 assertEquals(0, binaryEff.getLengthConstraints().size());
78 assertEquals("CURRENT", binaryEff.getStatus().toString());
79 assertEquals("binary", binaryEff.getPath().getPathFromRoot().iterator().next().getLocalName());
80 assertNotNull(binaryEff.getUnknownSchemaNodes());
81 assertNull(binaryEff.getDescription());
82 assertNull(binaryEff.getReference());
86 public void testBits() {
87 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
88 .getDataChildByName("leaf-bits");
89 assertNotNull(currentLeaf.getType());
91 List<BitsTypeDefinition.Bit> bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits();
92 BitEffectiveStatementImpl bitEff = (BitEffectiveStatementImpl) bitsEffIter.get(0);
93 BitEffectiveStatementImpl bitEffSecond = (BitEffectiveStatementImpl) bitsEffIter.get(1);
95 BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatementImpl)
96 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
98 assertNull(bitsEff.getBaseType());
99 assertNotNull(bitsEff.getQName());
100 assertEquals("bits", bitsEff.getQName().getLocalName());
101 assertEquals("bits", bitsEff.getPath().getLastComponent().getLocalName());
102 assertNotNull(bitsEff.getUnknownSchemaNodes());
103 assertNull(bitsEff.getDescription());
104 assertNull(bitsEff.getReference());
105 assertEquals("CURRENT", bitsEff.getStatus().toString());
106 assertNull(bitsEff.getUnits());
107 assertNotNull(bitsEff.toString());
108 assertNotNull(bitsEff.hashCode());
109 assertFalse(bitsEff.equals(null));
110 assertFalse(bitsEff.equals("test"));
111 assertTrue(bitsEff.equals(bitsEff));
112 assertEquals(3, bitsEff.getBits().size());
113 assertNull(bitsEff.getDefaultValue());
115 assertNotNull(bitEff.getPath());
116 assertNotNull(bitEff.getUnknownSchemaNodes());
117 assertEquals("test bit", bitEff.getDescription());
118 assertEquals("test bit ref", bitEff.getReference());
119 assertEquals("CURRENT", bitEff.getStatus().toString());
120 assertNotNull(bitEff.hashCode());
121 assertFalse(bitEff.equals(null));
122 assertFalse(bitEff.equals("test"));
123 assertFalse(bitEff.equals(bitEffSecond));
124 assertNotNull(bitEff.toString());
125 assertEquals("one", bitEff.getName());
126 assertNotNull(bitEff.getQName());
127 assertEquals("0", bitEff.getPosition().toString());
128 assertEquals(0, bitEff.getPosition().longValue());
132 public void testBoolean() {
133 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
134 .getDataChildByName("leaf-boolean");
135 assertNotNull(currentLeaf.getType());
136 BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement<?>)
137 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
139 assertNull(booleanEff.getBaseType());
140 assertNull(booleanEff.getUnits());
141 assertNull(booleanEff.getDefaultValue());
142 assertEquals("boolean", booleanEff.getQName().getLocalName());
143 assertNull(booleanEff.getPath().getParent().getParent());
144 assertNotNull(booleanEff.getUnknownSchemaNodes());
145 assertNull(booleanEff.getDescription());
146 assertNull(booleanEff.getReference());
147 assertEquals("CURRENT", booleanEff.getStatus().toString());
148 assertNotNull(booleanEff.toString());
152 public void testDecimal64() {
153 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
154 .getDataChildByName("leaf-decimal64");
155 assertNotNull(currentLeaf.getType());
156 DecimalTypeDefinition decimal64Eff = ((Decimal64SpecificationEffectiveStatementImpl)
157 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
159 assertNull(decimal64Eff.getBaseType());
160 assertNull(decimal64Eff.getUnits());
161 assertNull(decimal64Eff.getDefaultValue());
162 assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
163 assertNotNull(decimal64Eff.getUnknownSchemaNodes());
165 // FIXME: The model is wrong: description/reference/status are not allowed under 'type', how come we parse it?
166 assertNull(decimal64Eff.getDescription());
167 assertNull(decimal64Eff.getReference());
168 assertEquals("CURRENT", decimal64Eff.getStatus().toString());
170 assertEquals(3, decimal64Eff.getRangeConstraints().size());
171 assertNotNull(decimal64Eff.toString());
172 assertNotNull(decimal64Eff.hashCode());
173 assertTrue(decimal64Eff.getFractionDigits().equals(2));
174 assertFalse(decimal64Eff.equals(null));
175 assertFalse(decimal64Eff.equals("test"));
176 assertTrue(decimal64Eff.equals(decimal64Eff));
177 assertEquals("decimal64", decimal64Eff.getPath().getLastComponent().getLocalName());
181 public void testEmpty() {
182 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
183 .getDataChildByName("leaf-empty");
184 assertNotNull(currentLeaf.getType());
185 EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement<?>)
186 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
188 assertNull(emptyEff.getUnits());
189 assertNull(emptyEff.getDefaultValue());
190 assertNull(emptyEff.getBaseType());
191 assertEquals("empty", emptyEff.getQName().getLocalName());
192 assertNull(emptyEff.getPath().getParent().getParent());
193 assertNotNull(emptyEff.getUnknownSchemaNodes());
194 assertNull(emptyEff.getDescription());
195 assertNull(emptyEff.getReference());
196 assertEquals("CURRENT", emptyEff.getStatus().toString());
197 assertNotNull(emptyEff.toString());
201 public void testEnum() {
202 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
203 .getDataChildByName("leaf-enum");
204 assertNotNull(currentLeaf.getType());
205 List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues();
206 EnumEffectiveStatementImpl enumEff = (EnumEffectiveStatementImpl) enumEffIter.iterator().next();
208 EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatementImpl)
209 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
211 assertEquals("enumeration", enumSpecEff.getQName().getLocalName());
212 assertEquals("enumeration", enumSpecEff.getPath().getLastComponent().getLocalName());
213 assertNull(enumSpecEff.getDefaultValue());
214 assertEquals(3, enumSpecEff.getValues().size());
215 assertNull(enumSpecEff.getBaseType());
216 assertNotNull(enumSpecEff.getUnknownSchemaNodes());
217 assertEquals("CURRENT", enumSpecEff.getStatus().toString());
218 assertNull(enumSpecEff.getDescription());
219 assertNull(enumSpecEff.getReference());
220 assertNull(enumSpecEff.getUnits());
221 assertNotNull(enumSpecEff.toString());
222 assertNotNull(enumSpecEff.hashCode());
223 assertFalse(enumSpecEff.equals(null));
224 assertFalse(enumSpecEff.equals("test"));
225 assertTrue(enumSpecEff.equals(enumSpecEff));
227 assertEquals("zero", enumEff.getQName().getLocalName());
228 assertEquals("zero", enumEff.getName());
229 assertNotNull(enumEff.getPath());
230 assertNotNull(enumEff.getUnknownSchemaNodes());
231 assertEquals("test enum", enumEff.getDescription());
232 assertEquals("test enum ref", enumEff.getReference());
233 assertEquals("CURRENT", enumEff.getStatus().toString());
234 assertEquals("0", enumEff.getValue().toString());
238 public void testIdentityRef() {
239 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
240 .getDataChildByName("leaf-identityref");
241 assertNotNull(currentLeaf.getType());
242 IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatementImpl)
243 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
245 assertNull(identityRefEff.getDefaultValue());
246 assertEquals("identityref", identityRefEff.getQName().getLocalName());
247 assertEquals("identityref", identityRefEff.getPath().getLastComponent().getLocalName());
248 assertNull(identityRefEff.getBaseType());
249 assertNotNull(identityRefEff.getUnknownSchemaNodes());
250 assertEquals("CURRENT", identityRefEff.getStatus().toString());
251 assertEquals("test-identity", identityRefEff.getIdentity().getQName().getLocalName());
252 assertNull(identityRefEff.getDescription());
253 assertNull(identityRefEff.getReference());
254 assertNotNull(identityRefEff.toString());
256 // FIXME: the model is wrong, but we accept units in 'type' statement
257 assertNull(identityRefEff.getUnits());
261 public void testInstanceIdentifier() {
262 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
263 .getDataChildByName("leaf-instance-identifier");
264 assertNotNull(currentLeaf.getType());
265 InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition)
266 ((TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
267 .effectiveSubstatements().iterator().next()).getTypeDefinition();
268 assertNotNull(instanceIdentEff.toString());
270 assertFalse(instanceIdentEff.requireInstance());
271 assertEquals("instance-identifier", instanceIdentEff.getQName().getLocalName());
272 assertEquals("instance-identifier", instanceIdentEff.getPath().getLastComponent().getLocalName());
273 assertNull(instanceIdentEff.getBaseType());
274 assertNull(instanceIdentEff.getDefaultValue());
275 assertNotNull(instanceIdentEff.getUnknownSchemaNodes());
276 assertNull(instanceIdentEff.getDescription());
277 assertNull(instanceIdentEff.getReference());
278 assertNull(instanceIdentEff.getUnits());
279 assertEquals("CURRENT", instanceIdentEff.getStatus().toString());
280 assertNotNull(instanceIdentEff.hashCode());
281 assertFalse(instanceIdentEff.equals(null));
282 assertFalse(instanceIdentEff.equals("test"));
283 assertTrue(instanceIdentEff.equals(instanceIdentEff));
287 public void testLeafref() {
288 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
289 .getDataChildByName("leaf-leafref");
290 assertNotNull(currentLeaf.getType());
292 LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl)
293 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
295 assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().toString());
296 assertNull(leafrefEff.getBaseType());
297 assertNull(leafrefEff.getUnits());
298 assertNull(leafrefEff.getDefaultValue());
299 assertNotNull(leafrefEff.toString());
300 assertEquals("leafref", leafrefEff.getQName().getLocalName());
301 assertEquals("CURRENT", leafrefEff.getStatus().toString());
302 assertNotNull(leafrefEff.getUnknownSchemaNodes());
303 assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName());
304 assertNull(leafrefEff.getDescription());
305 assertNull(leafrefEff.getReference());
306 assertNotNull(leafrefEff.hashCode());
307 assertFalse(leafrefEff.equals(null));
308 assertFalse(leafrefEff.equals("test"));
309 assertTrue(leafrefEff.equals(leafrefEff));
313 public void testIntAll() {
314 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
315 .getDataChildByName("leaf-int8");
316 assertNotNull(currentLeaf.getType());
317 TypeEffectiveStatement<?> int8Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
318 .effectiveSubstatements().iterator().next();
319 assertNotNull(int8Eff.toString());
321 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
322 .getDataChildByName("leaf-int16");
323 assertNotNull(currentLeaf.getType());
324 TypeEffectiveStatement<?> int16Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
325 .effectiveSubstatements().iterator().next();
326 assertNotNull(int16Eff.toString());
328 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
329 .getDataChildByName("leaf-int32");
330 assertNotNull(currentLeaf.getType());
331 TypeEffectiveStatement<?> int32Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
332 .effectiveSubstatements().iterator().next();
333 assertNotNull(int32Eff.toString());
335 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
336 .getDataChildByName("leaf-int64");
337 assertNotNull(currentLeaf.getType());
338 TypeEffectiveStatement<?> int64Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
339 .effectiveSubstatements().iterator().next();
340 assertNotNull(int64Eff.toString());
342 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
343 .getDataChildByName("leaf-uint8");
344 assertNotNull(currentLeaf.getType());
345 TypeEffectiveStatement<?> uint8Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
346 .effectiveSubstatements().iterator().next();
347 assertNotNull(uint8Eff.toString());
349 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
350 .getDataChildByName("leaf-uint16");
351 assertNotNull(currentLeaf.getType());
352 TypeEffectiveStatement<?> uint16Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
354 .effectiveSubstatements().iterator().next();
355 assertNotNull(uint16Eff.toString());
357 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
358 .getDataChildByName("leaf-uint32");
359 assertNotNull(currentLeaf.getType());
360 TypeEffectiveStatement<?> uint32Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
362 .effectiveSubstatements().iterator().next();
363 assertNotNull(uint32Eff.toString());
365 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
366 .getDataChildByName("leaf-uint64");
367 assertNotNull(currentLeaf.getType());
368 TypeEffectiveStatement<?> uint64Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
370 .effectiveSubstatements().iterator().next();
371 assertNotNull(uint64Eff.toString());
375 public void testUnion() {
376 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
377 .getDataChildByName("leaf-union");
378 assertNotNull(currentLeaf.getType());
379 UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatementImpl)
380 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
382 assertEquals(2, unionEff.getTypes().size());
383 assertEquals("union", unionEff.getQName().getLocalName());
384 assertEquals("CURRENT", unionEff.getStatus().toString());
385 assertNotNull(unionEff.getUnknownSchemaNodes());
386 assertNull(unionEff.getBaseType());
387 assertNull(unionEff.getUnits());
388 assertNull(unionEff.getDefaultValue());
389 assertNull(unionEff.getDescription());
390 assertNull(unionEff.getReference());
391 assertNotNull(unionEff.toString());
392 assertNotNull(unionEff.hashCode());
393 assertFalse(unionEff.equals(null));
394 assertFalse(unionEff.equals("test"));
395 assertTrue(unionEff.equals(unionEff));
396 assertEquals("union", unionEff.getPath().getLastComponent().getLocalName());
400 public void testLengthConstraint() {
401 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
402 .getDataChildByName("leaf-length-pattern");
403 assertNotNull(currentLeaf.getType());
404 LengthConstraint lengthConstraint = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0);
405 LengthConstraint lengthConstraintThird = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0);
406 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
407 .getDataChildByName("leaf-length-pattern-second");
408 assertNotNull(currentLeaf.getType());
409 LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0);
411 assertEquals(1, lengthConstraint.getMin().intValue());
412 assertEquals(255, lengthConstraint.getMax().intValue());
413 assertNull(lengthConstraint.getReference());
414 assertNull(lengthConstraint.getDescription());
415 assertEquals("The argument is out of bounds <1, 255>", lengthConstraint.getErrorMessage());
416 assertEquals("length-out-of-specified-bounds", lengthConstraint.getErrorAppTag());
417 assertNotNull(lengthConstraint.toString());
418 assertNotNull(lengthConstraint.hashCode());
419 assertFalse(lengthConstraint.equals(null));
420 assertFalse(lengthConstraint.equals("test"));
421 assertFalse(lengthConstraint.equals(lengthConstraintSecond));
422 assertTrue(lengthConstraint.equals(lengthConstraintThird));
426 public void testPatternConstraint() {
427 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
428 .getDataChildByName("leaf-length-pattern");
429 assertNotNull(currentLeaf.getType());
430 PatternConstraintEffectiveImpl lengthConstraint = (PatternConstraintEffectiveImpl)
431 ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0);
432 PatternConstraintEffectiveImpl lengthConstraintThird = (PatternConstraintEffectiveImpl)
433 ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0);
434 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
435 .getDataChildByName("leaf-length-pattern-second");
436 assertNotNull(currentLeaf.getType());
437 PatternConstraintEffectiveImpl lengthConstraintSecond = (PatternConstraintEffectiveImpl)
438 ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0);
440 assertEquals("^[0-9a-fA-F]*$", lengthConstraint.getRegularExpression());
441 assertNull(lengthConstraint.getReference());
442 assertNull(lengthConstraint.getDescription());
443 assertEquals("String ^[0-9a-fA-F]*$ is not valid regular expression.", lengthConstraint.getErrorMessage());
444 assertEquals("invalid-regular-expression", lengthConstraint.getErrorAppTag());
445 assertNotNull(lengthConstraint.toString());
446 assertNotNull(lengthConstraint.hashCode());
447 assertFalse(lengthConstraint.equals(null));
448 assertFalse(lengthConstraint.equals("test"));
449 assertFalse(lengthConstraint.equals(lengthConstraintSecond));
450 assertTrue(lengthConstraint.equals(lengthConstraintThird));
454 public void testString() {
455 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
456 .getDataChildByName("leaf-string");
457 assertNotNull(currentLeaf.getType());
458 StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement<?>)
459 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
461 assertEquals("string", stringEff.getQName().getLocalName());
462 assertEquals("CURRENT", stringEff.getStatus().toString());
463 assertNull(stringEff.getUnits());
464 assertNull(stringEff.getDefaultValue());
465 assertNotNull(stringEff.getUnknownSchemaNodes());
466 assertNull(stringEff.getBaseType());
467 assertNull(stringEff.getDescription());
468 assertNull(stringEff.getReference());
469 assertNotNull(stringEff.toString());
470 assertNotNull(stringEff.hashCode());
471 assertFalse(stringEff.equals(null));
472 assertFalse(stringEff.equals("test"));
473 assertTrue(stringEff.equals(stringEff));
474 assertEquals("string", stringEff.getPath().getLastComponent().getLocalName());
475 assertEquals(0, stringEff.getLengthConstraints().size());
476 assertNotNull(stringEff.getPatternConstraints());