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.getName());
228 assertNotNull(enumEff.getUnknownSchemaNodes());
229 assertEquals("test enum", enumEff.getDescription());
230 assertEquals("test enum ref", enumEff.getReference());
231 assertEquals("CURRENT", enumEff.getStatus().toString());
232 assertEquals("0", enumEff.getValue().toString());
236 public void testIdentityRef() {
237 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
238 .getDataChildByName("leaf-identityref");
239 assertNotNull(currentLeaf.getType());
240 IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatementImpl)
241 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
243 assertNull(identityRefEff.getDefaultValue());
244 assertEquals("identityref", identityRefEff.getQName().getLocalName());
245 assertEquals("identityref", identityRefEff.getPath().getLastComponent().getLocalName());
246 assertNull(identityRefEff.getBaseType());
247 assertNotNull(identityRefEff.getUnknownSchemaNodes());
248 assertEquals("CURRENT", identityRefEff.getStatus().toString());
249 assertEquals("test-identity", identityRefEff.getIdentity().getQName().getLocalName());
250 assertNull(identityRefEff.getDescription());
251 assertNull(identityRefEff.getReference());
252 assertNotNull(identityRefEff.toString());
254 // FIXME: the model is wrong, but we accept units in 'type' statement
255 assertNull(identityRefEff.getUnits());
259 public void testInstanceIdentifier() {
260 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
261 .getDataChildByName("leaf-instance-identifier");
262 assertNotNull(currentLeaf.getType());
263 InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition)
264 ((TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
265 .effectiveSubstatements().iterator().next()).getTypeDefinition();
266 assertNotNull(instanceIdentEff.toString());
268 assertFalse(instanceIdentEff.requireInstance());
269 assertEquals("instance-identifier", instanceIdentEff.getQName().getLocalName());
270 assertEquals("instance-identifier", instanceIdentEff.getPath().getLastComponent().getLocalName());
271 assertNull(instanceIdentEff.getBaseType());
272 assertNull(instanceIdentEff.getDefaultValue());
273 assertNotNull(instanceIdentEff.getUnknownSchemaNodes());
274 assertNull(instanceIdentEff.getDescription());
275 assertNull(instanceIdentEff.getReference());
276 assertNull(instanceIdentEff.getUnits());
277 assertEquals("CURRENT", instanceIdentEff.getStatus().toString());
278 assertNotNull(instanceIdentEff.hashCode());
279 assertFalse(instanceIdentEff.equals(null));
280 assertFalse(instanceIdentEff.equals("test"));
281 assertTrue(instanceIdentEff.equals(instanceIdentEff));
285 public void testLeafref() {
286 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
287 .getDataChildByName("leaf-leafref");
288 assertNotNull(currentLeaf.getType());
290 LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl)
291 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
293 assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().toString());
294 assertNull(leafrefEff.getBaseType());
295 assertNull(leafrefEff.getUnits());
296 assertNull(leafrefEff.getDefaultValue());
297 assertNotNull(leafrefEff.toString());
298 assertEquals("leafref", leafrefEff.getQName().getLocalName());
299 assertEquals("CURRENT", leafrefEff.getStatus().toString());
300 assertNotNull(leafrefEff.getUnknownSchemaNodes());
301 assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName());
302 assertNull(leafrefEff.getDescription());
303 assertNull(leafrefEff.getReference());
304 assertNotNull(leafrefEff.hashCode());
305 assertFalse(leafrefEff.equals(null));
306 assertFalse(leafrefEff.equals("test"));
307 assertTrue(leafrefEff.equals(leafrefEff));
311 public void testIntAll() {
312 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
313 .getDataChildByName("leaf-int8");
314 assertNotNull(currentLeaf.getType());
315 TypeEffectiveStatement<?> int8Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
316 .effectiveSubstatements().iterator().next();
317 assertNotNull(int8Eff.toString());
319 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
320 .getDataChildByName("leaf-int16");
321 assertNotNull(currentLeaf.getType());
322 TypeEffectiveStatement<?> int16Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
323 .effectiveSubstatements().iterator().next();
324 assertNotNull(int16Eff.toString());
326 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
327 .getDataChildByName("leaf-int32");
328 assertNotNull(currentLeaf.getType());
329 TypeEffectiveStatement<?> int32Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
330 .effectiveSubstatements().iterator().next();
331 assertNotNull(int32Eff.toString());
333 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
334 .getDataChildByName("leaf-int64");
335 assertNotNull(currentLeaf.getType());
336 TypeEffectiveStatement<?> int64Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
337 .effectiveSubstatements().iterator().next();
338 assertNotNull(int64Eff.toString());
340 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
341 .getDataChildByName("leaf-uint8");
342 assertNotNull(currentLeaf.getType());
343 TypeEffectiveStatement<?> uint8Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl) currentLeaf)
344 .effectiveSubstatements().iterator().next();
345 assertNotNull(uint8Eff.toString());
347 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
348 .getDataChildByName("leaf-uint16");
349 assertNotNull(currentLeaf.getType());
350 TypeEffectiveStatement<?> uint16Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
352 .effectiveSubstatements().iterator().next();
353 assertNotNull(uint16Eff.toString());
355 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
356 .getDataChildByName("leaf-uint32");
357 assertNotNull(currentLeaf.getType());
358 TypeEffectiveStatement<?> uint32Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
360 .effectiveSubstatements().iterator().next();
361 assertNotNull(uint32Eff.toString());
363 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
364 .getDataChildByName("leaf-uint64");
365 assertNotNull(currentLeaf.getType());
366 TypeEffectiveStatement<?> uint64Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
368 .effectiveSubstatements().iterator().next();
369 assertNotNull(uint64Eff.toString());
373 public void testUnion() {
374 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
375 .getDataChildByName("leaf-union");
376 assertNotNull(currentLeaf.getType());
377 UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatementImpl)
378 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
380 assertEquals(2, unionEff.getTypes().size());
381 assertEquals("union", unionEff.getQName().getLocalName());
382 assertEquals("CURRENT", unionEff.getStatus().toString());
383 assertNotNull(unionEff.getUnknownSchemaNodes());
384 assertNull(unionEff.getBaseType());
385 assertNull(unionEff.getUnits());
386 assertNull(unionEff.getDefaultValue());
387 assertNull(unionEff.getDescription());
388 assertNull(unionEff.getReference());
389 assertNotNull(unionEff.toString());
390 assertNotNull(unionEff.hashCode());
391 assertFalse(unionEff.equals(null));
392 assertFalse(unionEff.equals("test"));
393 assertTrue(unionEff.equals(unionEff));
394 assertEquals("union", unionEff.getPath().getLastComponent().getLocalName());
398 public void testLengthConstraint() {
399 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
400 .getDataChildByName("leaf-length-pattern");
401 assertNotNull(currentLeaf.getType());
402 LengthConstraint lengthConstraint = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0);
403 LengthConstraint lengthConstraintThird = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0);
404 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
405 .getDataChildByName("leaf-length-pattern-second");
406 assertNotNull(currentLeaf.getType());
407 LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0);
409 assertEquals(1, lengthConstraint.getMin().intValue());
410 assertEquals(255, lengthConstraint.getMax().intValue());
411 assertNull(lengthConstraint.getReference());
412 assertNull(lengthConstraint.getDescription());
413 assertEquals("The argument is out of bounds <1, 255>", lengthConstraint.getErrorMessage());
414 assertEquals("length-out-of-specified-bounds", lengthConstraint.getErrorAppTag());
415 assertNotNull(lengthConstraint.toString());
416 assertNotNull(lengthConstraint.hashCode());
417 assertFalse(lengthConstraint.equals(null));
418 assertFalse(lengthConstraint.equals("test"));
419 assertFalse(lengthConstraint.equals(lengthConstraintSecond));
420 assertTrue(lengthConstraint.equals(lengthConstraintThird));
424 public void testPatternConstraint() {
425 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
426 .getDataChildByName("leaf-length-pattern");
427 assertNotNull(currentLeaf.getType());
428 PatternConstraintEffectiveImpl lengthConstraint = (PatternConstraintEffectiveImpl)
429 ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0);
430 PatternConstraintEffectiveImpl lengthConstraintThird = (PatternConstraintEffectiveImpl)
431 ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0);
432 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
433 .getDataChildByName("leaf-length-pattern-second");
434 assertNotNull(currentLeaf.getType());
435 PatternConstraintEffectiveImpl lengthConstraintSecond = (PatternConstraintEffectiveImpl)
436 ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0);
438 assertEquals("^[0-9a-fA-F]*$", lengthConstraint.getRegularExpression());
439 assertNull(lengthConstraint.getReference());
440 assertNull(lengthConstraint.getDescription());
441 assertEquals("String ^[0-9a-fA-F]*$ is not valid regular expression.", lengthConstraint.getErrorMessage());
442 assertEquals("invalid-regular-expression", lengthConstraint.getErrorAppTag());
443 assertNotNull(lengthConstraint.toString());
444 assertNotNull(lengthConstraint.hashCode());
445 assertFalse(lengthConstraint.equals(null));
446 assertFalse(lengthConstraint.equals("test"));
447 assertFalse(lengthConstraint.equals(lengthConstraintSecond));
448 assertTrue(lengthConstraint.equals(lengthConstraintThird));
452 public void testString() {
453 currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
454 .getDataChildByName("leaf-string");
455 assertNotNull(currentLeaf.getType());
456 StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement<?>)
457 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
459 assertEquals("string", stringEff.getQName().getLocalName());
460 assertEquals("CURRENT", stringEff.getStatus().toString());
461 assertNull(stringEff.getUnits());
462 assertNull(stringEff.getDefaultValue());
463 assertNotNull(stringEff.getUnknownSchemaNodes());
464 assertNull(stringEff.getBaseType());
465 assertNull(stringEff.getDescription());
466 assertNull(stringEff.getReference());
467 assertNotNull(stringEff.toString());
468 assertNotNull(stringEff.hashCode());
469 assertFalse(stringEff.equals(null));
470 assertFalse(stringEff.equals("test"));
471 assertTrue(stringEff.equals(stringEff));
472 assertEquals("string", stringEff.getPath().getLastComponent().getLocalName());
473 assertEquals(0, stringEff.getLengthConstraints().size());
474 assertNotNull(stringEff.getPatternConstraints());