BUG-865: make EnumPair getQName/getSchemaPath unimplemented
[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.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());
233     }
234
235     @Test
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();
242
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());
253
254         // FIXME: the model is wrong, but we accept units in 'type' statement
255         assertNull(identityRefEff.getUnits());
256     }
257
258     @Test
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());
267
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));
282     }
283
284     @Test
285     public void testLeafref() {
286         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
287                 .getDataChildByName("leaf-leafref");
288         assertNotNull(currentLeaf.getType());
289
290         LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl)
291                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition();
292
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));
308     }
309
310     @Test
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());
318
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());
325
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());
332
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());
339
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());
346
347         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
348                 .getDataChildByName("leaf-uint16");
349         assertNotNull(currentLeaf.getType());
350         TypeEffectiveStatement<?> uint16Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
351                 currentLeaf)
352                 .effectiveSubstatements().iterator().next();
353         assertNotNull(uint16Eff.toString());
354
355         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
356                 .getDataChildByName("leaf-uint32");
357         assertNotNull(currentLeaf.getType());
358         TypeEffectiveStatement<?> uint32Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
359                 currentLeaf)
360                 .effectiveSubstatements().iterator().next();
361         assertNotNull(uint32Eff.toString());
362
363         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
364                 .getDataChildByName("leaf-uint64");
365         assertNotNull(currentLeaf.getType());
366         TypeEffectiveStatement<?> uint64Eff = (TypeEffectiveStatement<?>) ((LeafEffectiveStatementImpl)
367                 currentLeaf)
368                 .effectiveSubstatements().iterator().next();
369         assertNotNull(uint64Eff.toString());
370     }
371
372     @Test
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();
379
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());
395     }
396
397     @Test
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);
408
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));
421     }
422
423     @Test
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);
437
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));
449     }
450
451     @Test
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();
458
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());
475     }
476 }