c819f8d8a5c9b24b65d526fe33036b010a57ed16
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / EffectiveStatementTypeTest.java
1 /*
2  * Copyright (c) 2016 Cisco Systems, Inc. and others.  All rights reserved.
3  *
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
7  */
8
9 package org.opendaylight.yangtools.yang.stmt;
10
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
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;
49
50 public class EffectiveStatementTypeTest {
51
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;
56
57     @Before
58     public void setup() throws ReactorException {
59         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
60         reactor.addSource(IMPORTED_MODULE);
61         effectiveSchemaContext = reactor.buildEffective();
62     }
63
64     @Test
65     public void testBinary() {
66         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
67                 .getDataChildByName("leaf-binary");
68         assertNotNull(currentLeaf.getType());
69
70         BinaryTypeDefinition binaryEff = (BinaryTypeDefinition) ((TypeEffectiveStatement<?>)
71                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
72
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());
83     }
84
85     @Test
86     public void testBits() {
87         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
88                 .getDataChildByName("leaf-bits");
89         assertNotNull(currentLeaf.getType());
90
91         List<BitsTypeDefinition.Bit> bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits();
92         BitEffectiveStatementImpl bitEff = (BitEffectiveStatementImpl) bitsEffIter.get(0);
93         BitEffectiveStatementImpl bitEffSecond = (BitEffectiveStatementImpl) bitsEffIter.get(1);
94
95         BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatementImpl)
96                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
97
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());
114
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());
129     }
130
131     @Test
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();
138
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());
149     }
150
151     @Test
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();
158
159         assertNull(decimal64Eff.getBaseType());
160         assertNull(decimal64Eff.getUnits());
161         assertNull(decimal64Eff.getDefaultValue());
162         assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
163         assertNotNull(decimal64Eff.getUnknownSchemaNodes());
164
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());
169
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());
178     }
179
180     @Test
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();
187
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());
198     }
199
200     @Test
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();
207
208         EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatementImpl)
209                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
210
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));
226
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());
235     }
236
237     @Test
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();
244
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());
255
256         // FIXME: the model is wrong, but we accept units in 'type' statement
257         assertNull(identityRefEff.getUnits());
258     }
259
260     @Test
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());
269
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));
284     }
285
286     @Test
287     public void testLeafref() {
288         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
289                 .getDataChildByName("leaf-leafref");
290         assertNotNull(currentLeaf.getType());
291
292         LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl)
293                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
294
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));
310     }
311
312     @Test
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());
320
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());
327
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());
334
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());
341
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());
348
349         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
350                 .getDataChildByName("leaf-uint16");
351         assertNotNull(currentLeaf.getType());
352         TypeEffectiveStatement<?> uint16Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
353                 currentLeaf)
354                 .effectiveSubstatements().iterator().next();
355         assertNotNull(uint16Eff.toString());
356
357         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
358                 .getDataChildByName("leaf-uint32");
359         assertNotNull(currentLeaf.getType());
360         TypeEffectiveStatement<?> uint32Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
361                 currentLeaf)
362                 .effectiveSubstatements().iterator().next();
363         assertNotNull(uint32Eff.toString());
364
365         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
366                 .getDataChildByName("leaf-uint64");
367         assertNotNull(currentLeaf.getType());
368         TypeEffectiveStatement<?> uint64Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
369                 currentLeaf)
370                 .effectiveSubstatements().iterator().next();
371         assertNotNull(uint64Eff.toString());
372     }
373
374     @Test
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();
381
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());
397     }
398
399     @Test
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);
410
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));
423     }
424
425     @Test
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);
439
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));
451     }
452
453     @Test
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();
460
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());
477     }
478 }