BUG-4658: fix default value in BooleanType
[yangtools.git] / yang / yang-parser-impl / src / test / java / org / opendaylight / yangtools / yang / stmt / effective / build / test / EffectiveStatementTypeTest.java
1 /*
2  * Copyright (c) 2015 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.effective.build.test;
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.type.BitsTypeDefinition;
22 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
23 import org.opendaylight.yangtools.yang.model.util.BitsType;
24 import org.opendaylight.yangtools.yang.model.util.EnumerationType;
25 import org.opendaylight.yangtools.yang.model.util.ExtendedType;
26 import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
27 import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
28 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
29 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl;
30 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext;
31 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.IdentityEffectiveStatementImpl;
32 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl;
33 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BinaryEffectiveStatementImpl;
34 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitEffectiveStatementImpl;
35 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitsSpecificationEffectiveStatementImpl;
36 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BooleanEffectiveStatementImpl;
37 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Decimal64SpecificationEffectiveStatementImpl;
38 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EmptyEffectiveStatementImpl;
39 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumEffectiveStatementImpl;
40 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumSpecificationEffectiveStatementImpl;
41 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IdentityRefSpecificationEffectiveStatementImpl;
42 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.InstanceIdentifierSpecificationEffectiveStatementImpl;
43 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int16EffectiveStatementImpl;
44 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int32EffectiveStatementImpl;
45 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int64EffectiveStatementImpl;
46 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Int8EffectiveStatementImpl;
47 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl;
48 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LengthConstraintEffectiveImpl;
49 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.PatternConstraintEffectiveImpl;
50 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.StringEffectiveStatementImpl;
51 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt16EffectiveStatementImpl;
52 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt32EffectiveStatementImpl;
53 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt64EffectiveStatementImpl;
54 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UInt8EffectiveStatementImpl;
55 import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.UnionSpecificationEffectiveStatementImpl;
56
57 public class EffectiveStatementTypeTest {
58
59     private static final YangStatementSourceImpl IMPORTED_MODULE = new YangStatementSourceImpl(
60             "/type-tests/types.yang", false);
61     private static EffectiveSchemaContext effectiveSchemaContext;
62     private static LeafSchemaNode currentLeaf;
63
64     @Before
65     public void setup() throws ReactorException {
66         CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
67         reactor.addSource(IMPORTED_MODULE);
68         effectiveSchemaContext = reactor.buildEffective();
69     }
70
71     @Test
72     public void testBinary() {
73         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
74                 .getDataChildByName("leaf-binary");
75         assertNotNull(currentLeaf.getType());
76
77         BinaryEffectiveStatementImpl binaryEff = (BinaryEffectiveStatementImpl)
78                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
79
80         assertNull(binaryEff.getBaseType());
81         assertEquals("", binaryEff.getUnits());
82         assertNull(binaryEff.getDefaultValue());
83         assertEquals("binary", binaryEff.getQName().getLocalName());
84         assertEquals(0, binaryEff.getLengthConstraints().get(0).getMin());
85         assertEquals("CURRENT", binaryEff.getStatus().toString());
86         assertEquals("binary", binaryEff.getPath().getPathFromRoot().iterator().next().getLocalName());
87         assertNotNull(binaryEff.getUnknownSchemaNodes());
88         assertNotNull(binaryEff.getDescription());
89         assertNotNull(binaryEff.getReference());
90     }
91
92     @Test
93     public void testBits() {
94         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
95                 .getDataChildByName("leaf-bits");
96         assertNotNull(currentLeaf.getType());
97
98         List<BitsTypeDefinition.Bit> bitsEffIter = ((BitsType) currentLeaf.getType()).getBits();
99         BitEffectiveStatementImpl bitEff = (BitEffectiveStatementImpl) bitsEffIter.get(0);
100         BitEffectiveStatementImpl bitEffSecond = (BitEffectiveStatementImpl) bitsEffIter.get(1);
101
102         BitsSpecificationEffectiveStatementImpl bitsEff = (BitsSpecificationEffectiveStatementImpl)
103                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
104         BitsSpecificationEffectiveStatementImpl bitsEffSecond = (BitsSpecificationEffectiveStatementImpl)
105                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
106
107         assertNull(bitsEff.getBaseType());
108         assertNotNull(bitsEff.getQName());
109         assertEquals("bits", bitsEff.getQName().getLocalName());
110         assertEquals("bits", bitsEff.getPath().getLastComponent().getLocalName());
111         assertNotNull(bitsEff.getUnknownSchemaNodes());
112         assertNotNull(bitsEff.getDescription());
113         assertNotNull(bitsEff.getReference());
114         assertEquals("CURRENT", bitsEff.getStatus().toString());
115         assertEquals("", bitsEff.getUnits());
116         assertNotNull(bitsEff.toString());
117         assertNotNull(bitsEff.hashCode());
118         assertFalse(bitsEff.equals(null));
119         assertFalse(bitsEff.equals("test"));
120         assertTrue(bitsEff.equals(bitsEffSecond));
121         assertEquals(3, bitsEff.getBits().size());
122         assertNull(bitsEff.getDefaultValue());
123
124         assertNotNull(bitEff.getPath());
125         assertNotNull(bitEff.getUnknownSchemaNodes());
126         assertEquals("test bit", bitEff.getDescription());
127         assertEquals("test bit ref", bitEff.getReference());
128         assertEquals("CURRENT", bitEff.getStatus().toString());
129         assertNotNull(bitEff.hashCode());
130         assertFalse(bitEff.equals(null));
131         assertFalse(bitEff.equals("test"));
132         assertFalse(bitEff.equals(bitEffSecond));
133         assertNotNull(bitEff.toString());
134         assertEquals("one", bitEff.getName());
135         assertNotNull(bitEff.getQName());
136         assertEquals("0", bitEff.getPosition().toString());
137         assertEquals(0, bitEff.getPosition().longValue());
138     }
139
140     @Test
141     public void testBoolean() {
142         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
143                 .getDataChildByName("leaf-boolean");
144         assertNotNull(currentLeaf.getType());
145         BooleanEffectiveStatementImpl booleanEff = (BooleanEffectiveStatementImpl)
146                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
147
148         assertNull(booleanEff.getBaseType());
149         assertEquals("", booleanEff.getUnits());
150         assertNull(booleanEff.getDefaultValue());
151         assertEquals("boolean", booleanEff.getQName().getLocalName());
152         assertNull(booleanEff.getPath().getParent().getParent());
153         assertNotNull(booleanEff.getUnknownSchemaNodes());
154         assertNotNull(booleanEff.getDescription());
155         assertNotNull(booleanEff.getReference());
156         assertEquals("CURRENT", booleanEff.getStatus().toString());
157         assertNotNull(booleanEff.toString());
158     }
159
160     @Test
161     public void testDecimal64() {
162         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
163                 .getDataChildByName("leaf-decimal64");
164         assertNotNull(currentLeaf.getType());
165         Decimal64SpecificationEffectiveStatementImpl decimal64Eff = (Decimal64SpecificationEffectiveStatementImpl)
166                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
167         Decimal64SpecificationEffectiveStatementImpl decimal64EffSecond = (Decimal64SpecificationEffectiveStatementImpl)
168                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
169
170         assertEquals("decimal64", decimal64Eff.getBaseType().getQName().getLocalName());
171         assertEquals("", decimal64Eff.getUnits());
172         assertNull(decimal64Eff.getDefaultValue());
173         assertEquals("decimal64", decimal64Eff.getQName().getLocalName());
174         assertNotNull(decimal64Eff.getUnknownSchemaNodes());
175         assertNotNull(decimal64Eff.getDescription());
176         assertNotNull(decimal64Eff.getReference());
177         assertEquals("CURRENT", decimal64Eff.getStatus().toString());
178         assertEquals(3, decimal64Eff.getRangeConstraints().size());
179         assertNotNull(decimal64Eff.toString());
180         assertNotNull(decimal64Eff.hashCode());
181         assertTrue(decimal64Eff.getFractionDigits().equals(2));
182         assertTrue(decimal64Eff.isExtended());
183         assertFalse(decimal64Eff.equals(null));
184         assertFalse(decimal64Eff.equals("test"));
185         assertTrue(decimal64Eff.equals(decimal64EffSecond));
186         assertEquals("decimal64", decimal64Eff.getPath().getLastComponent().getLocalName());
187     }
188
189     @Test
190     public void testEmpty() {
191         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
192                 .getDataChildByName("leaf-empty");
193         assertNotNull(currentLeaf.getType());
194         EmptyEffectiveStatementImpl emptyEff = (EmptyEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
195                 .effectiveSubstatements().iterator().next();
196
197         assertNull(emptyEff.getUnits());
198         assertNull(emptyEff.getDefaultValue());
199         assertNull(emptyEff.getBaseType());
200         assertEquals("empty", emptyEff.getQName().getLocalName());
201         assertNull(emptyEff.getPath().getParent().getParent());
202         assertNotNull(emptyEff.getUnknownSchemaNodes());
203         assertNotNull(emptyEff.getDescription());
204         assertNotNull(emptyEff.getReference());
205         assertEquals("CURRENT", emptyEff.getStatus().toString());
206         assertNotNull(emptyEff.toString());
207     }
208
209     @Test
210     public void testEnum() {
211         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
212                 .getDataChildByName("leaf-enum");
213         assertNotNull(currentLeaf.getType());
214         List<EnumTypeDefinition.EnumPair> enumEffIter = ((EnumerationType) currentLeaf.getType()).getValues();
215         EnumEffectiveStatementImpl enumEff = (EnumEffectiveStatementImpl) enumEffIter.iterator().next();
216
217         EnumSpecificationEffectiveStatementImpl enumSpecEff = (EnumSpecificationEffectiveStatementImpl)
218                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
219         EnumSpecificationEffectiveStatementImpl enumSpecEffSecond = (EnumSpecificationEffectiveStatementImpl)
220                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
221
222         assertEquals("enumeration", enumSpecEff.getQName().getLocalName());
223         assertEquals("enumeration", enumSpecEff.getPath().getLastComponent().getLocalName());
224         assertNull(enumSpecEff.getDefaultValue());
225         assertEquals(3, enumSpecEff.getValues().size());
226         assertNull(enumSpecEff.getBaseType());
227         assertNotNull(enumSpecEff.getUnknownSchemaNodes());
228         assertEquals("CURRENT", enumSpecEff.getStatus().toString());
229         assertNotNull(enumSpecEff.getDescription());
230         assertNotNull(enumSpecEff.getReference());
231         assertEquals("", enumSpecEff.getUnits());
232         assertNotNull(enumSpecEff.toString());
233         assertNotNull(enumSpecEff.hashCode());
234         assertFalse(enumSpecEff.equals(null));
235         assertFalse(enumSpecEff.equals("test"));
236         assertTrue(enumSpecEff.equals(enumSpecEffSecond));
237
238         assertEquals("zero", enumEff.getQName().getLocalName());
239         assertEquals("zero", enumEff.getName());
240         assertNotNull(enumEff.getPath());
241         assertNotNull(enumEff.getUnknownSchemaNodes());
242         assertEquals("test enum", enumEff.getDescription());
243         assertEquals("test enum ref", enumEff.getReference());
244         assertEquals("CURRENT", enumEff.getStatus().toString());
245         assertEquals("0", enumEff.getValue().toString());
246     }
247
248     @Test
249     public void testIdentityRef() {
250         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
251                 .getDataChildByName("leaf-identityref");
252         assertNotNull(currentLeaf.getType());
253         IdentityRefSpecificationEffectiveStatementImpl identityRefEff = (IdentityRefSpecificationEffectiveStatementImpl)
254                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
255
256         assertTrue(identityRefEff.getDefaultValue() instanceof IdentityEffectiveStatementImpl);
257         assertEquals("identityref", identityRefEff.getQName().getLocalName());
258         assertEquals("identityref", identityRefEff.getPath().getLastComponent().getLocalName());
259         assertNull(identityRefEff.getBaseType());
260         assertNotNull(identityRefEff.getUnknownSchemaNodes());
261         assertEquals("CURRENT", identityRefEff.getStatus().toString());
262         assertEquals("test-identity", identityRefEff.getIdentity().getQName().getLocalName());
263         assertNotNull(identityRefEff.getDescription());
264         assertNotNull(identityRefEff.getReference());
265         assertEquals("", identityRefEff.getUnits());
266         assertNotNull(identityRefEff.toString());
267     }
268
269     @Test
270     public void testInstanceIdentifier() {
271         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
272                 .getDataChildByName("leaf-instance-identifier");
273         assertNotNull(currentLeaf.getType());
274         InstanceIdentifierSpecificationEffectiveStatementImpl instanceIdentEff =
275                 (InstanceIdentifierSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
276                 .effectiveSubstatements().iterator().next();
277         InstanceIdentifierSpecificationEffectiveStatementImpl instanceIdentEffSecond =
278                 (InstanceIdentifierSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
279                 .effectiveSubstatements().iterator().next();
280         assertNotNull(instanceIdentEff.toString());
281
282         assertFalse(instanceIdentEff.requireInstance());
283         assertEquals("instance-identifier", instanceIdentEff.getQName().getLocalName());
284         assertEquals("instance-identifier", instanceIdentEff.getPath().getLastComponent().getLocalName());
285         assertNull(instanceIdentEff.getBaseType());
286         assertNull(instanceIdentEff.getDefaultValue());
287         assertNull(instanceIdentEff.getPathStatement());
288         assertNotNull(instanceIdentEff.getUnknownSchemaNodes());
289         assertNotNull(instanceIdentEff.getDescription());
290         assertNotNull(instanceIdentEff.getReference());
291         assertEquals("", instanceIdentEff.getUnits());
292         assertEquals("CURRENT", instanceIdentEff.getStatus().toString());
293         assertNotNull(instanceIdentEff.hashCode());
294         assertFalse(instanceIdentEff.equals(null));
295         assertFalse(instanceIdentEff.equals("test"));
296         assertTrue(instanceIdentEff.equals(instanceIdentEffSecond));
297     }
298
299     @Test
300     public void testLeafref() {
301         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
302                 .getDataChildByName("leaf-leafref");
303         assertNotNull(currentLeaf.getType());
304         LeafrefSpecificationEffectiveStatementImpl leafrefEff = (LeafrefSpecificationEffectiveStatementImpl)
305                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
306
307         LeafrefSpecificationEffectiveStatementImpl leafrefEffSecond = (LeafrefSpecificationEffectiveStatementImpl)
308                 ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next();
309
310         assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().toString());
311         assertNull(leafrefEff.getBaseType());
312         assertEquals("", leafrefEff.getUnits());
313         assertNull("leafref", leafrefEff.getDefaultValue());
314         assertNotNull(leafrefEff.toString());
315         assertEquals("leafref", leafrefEff.getQName().getLocalName());
316         assertEquals("CURRENT", leafrefEff.getStatus().toString());
317         assertNotNull(leafrefEff.getUnknownSchemaNodes());
318         assertEquals("leafref", leafrefEff.getPath().getLastComponent().getLocalName());
319         assertNotNull(leafrefEff.getDescription());
320         assertNotNull(leafrefEff.getReference());
321         assertNotNull(leafrefEff.hashCode());
322         assertFalse(leafrefEff.equals(null));
323         assertFalse(leafrefEff.equals("test"));
324         assertTrue(leafrefEff.equals(leafrefEffSecond));
325     }
326
327     @Test
328     public void testIntAll() {
329         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
330                 .getDataChildByName("leaf-int8");
331         assertNotNull(currentLeaf.getType());
332         Int8EffectiveStatementImpl int8Eff = (Int8EffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
333                 .effectiveSubstatements().iterator().next();
334         assertNotNull(int8Eff.toString());
335
336         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
337                 .getDataChildByName("leaf-int16");
338         assertNotNull(currentLeaf.getType());
339         Int16EffectiveStatementImpl int16Eff = (Int16EffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
340                 .effectiveSubstatements().iterator().next();
341         assertNotNull(int16Eff.toString());
342
343         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
344                 .getDataChildByName("leaf-int32");
345         assertNotNull(currentLeaf.getType());
346         Int32EffectiveStatementImpl int32Eff = (Int32EffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
347                 .effectiveSubstatements().iterator().next();
348         assertNotNull(int32Eff.toString());
349
350         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
351                 .getDataChildByName("leaf-int64");
352         assertNotNull(currentLeaf.getType());
353         Int64EffectiveStatementImpl int64Eff = (Int64EffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
354                 .effectiveSubstatements().iterator().next();
355         assertNotNull(int64Eff.toString());
356
357         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
358                 .getDataChildByName("leaf-uint8");
359         assertNotNull(currentLeaf.getType());
360         UInt8EffectiveStatementImpl uint8Eff = (UInt8EffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf)
361                 .effectiveSubstatements().iterator().next();
362         assertNotNull(uint8Eff.toString());
363
364         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
365                 .getDataChildByName("leaf-uint16");
366         assertNotNull(currentLeaf.getType());
367         UInt16EffectiveStatementImpl uint16Eff = (UInt16EffectiveStatementImpl) ((LeafEffectiveStatementImpl)
368                 currentLeaf)
369                 .effectiveSubstatements().iterator().next();
370         assertNotNull(uint16Eff.toString());
371
372         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
373                 .getDataChildByName("leaf-uint32");
374         assertNotNull(currentLeaf.getType());
375         UInt32EffectiveStatementImpl uint32Eff = (UInt32EffectiveStatementImpl) ((LeafEffectiveStatementImpl)
376                 currentLeaf)
377                 .effectiveSubstatements().iterator().next();
378         assertNotNull(uint32Eff.toString());
379
380         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
381                 .getDataChildByName("leaf-uint64");
382         assertNotNull(currentLeaf.getType());
383         UInt64EffectiveStatementImpl uint64Eff = (UInt64EffectiveStatementImpl) ((LeafEffectiveStatementImpl)
384                 currentLeaf)
385                 .effectiveSubstatements().iterator().next();
386         assertNotNull(uint64Eff.toString());
387     }
388
389     @Test
390     public void testUnion() {
391         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
392                 .getDataChildByName("leaf-union");
393         assertNotNull(currentLeaf.getType());
394         UnionSpecificationEffectiveStatementImpl unionEff = (UnionSpecificationEffectiveStatementImpl)
395                 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next();
396         UnionSpecificationEffectiveStatementImpl unionEffSecond = (UnionSpecificationEffectiveStatementImpl)
397                 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next();
398
399         assertEquals(2, unionEff.getTypes().size());
400         assertEquals("union", unionEff.getQName().getLocalName());
401         assertEquals("CURRENT", unionEff.getStatus().toString());
402         assertNotNull(unionEff.getUnknownSchemaNodes());
403         assertNull(unionEff.getBaseType());
404         assertNull(unionEff.getUnits());
405         assertNull(unionEff.getDefaultValue());
406         assertNotNull(unionEff.getDescription());
407         assertNotNull(unionEff.getReference());
408         assertNotNull(unionEff.toString());
409         assertNotNull(unionEff.hashCode());
410         assertFalse(unionEff.equals(null));
411         assertFalse(unionEff.equals("test"));
412         assertTrue(unionEff.equals(unionEffSecond));
413         assertEquals("union", unionEff.getPath().getLastComponent().getLocalName());
414     }
415
416     @Test
417     public void testLengthConstraint() {
418         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
419                 .getDataChildByName("leaf-length-pattern");
420         assertNotNull(currentLeaf.getType());
421         LengthConstraintEffectiveImpl lengthConstraint = (LengthConstraintEffectiveImpl)
422                 ((ExtendedType) (currentLeaf.getType())).getLengthConstraints().get(0);
423         LengthConstraintEffectiveImpl lengthConstraintThird = (LengthConstraintEffectiveImpl)
424                 ((ExtendedType) (currentLeaf.getType())).getLengthConstraints().get(0);
425         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
426                 .getDataChildByName("leaf-length-pattern-second");
427         assertNotNull(currentLeaf.getType());
428         LengthConstraintEffectiveImpl lengthConstraintSecond = (LengthConstraintEffectiveImpl)
429                 ((ExtendedType) (currentLeaf.getType())).getLengthConstraints().get(0);
430
431         assertEquals(1, lengthConstraint.getMin().intValue());
432         assertEquals(255, lengthConstraint.getMax().intValue());
433         assertNull(lengthConstraint.getReference());
434         assertNull(lengthConstraint.getDescription());
435         assertEquals("The argument is out of bounds <1, 255>", lengthConstraint.getErrorMessage());
436         assertEquals("length-out-of-specified-bounds", lengthConstraint.getErrorAppTag());
437         assertNotNull(lengthConstraint.toString());
438         assertNotNull(lengthConstraint.hashCode());
439         assertFalse(lengthConstraint.equals(null));
440         assertFalse(lengthConstraint.equals("test"));
441         assertFalse(lengthConstraint.equals(lengthConstraintSecond));
442         assertTrue(lengthConstraint.equals(lengthConstraintThird));
443     }
444
445     @Test
446     public void testPatternConstraint() {
447         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
448                 .getDataChildByName("leaf-length-pattern");
449         assertNotNull(currentLeaf.getType());
450         PatternConstraintEffectiveImpl lengthConstraint = (PatternConstraintEffectiveImpl)
451                 ((ExtendedType) (currentLeaf.getType())).getPatternConstraints().get(0);
452         PatternConstraintEffectiveImpl lengthConstraintThird = (PatternConstraintEffectiveImpl)
453                 ((ExtendedType) (currentLeaf.getType())).getPatternConstraints().get(0);
454         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
455                 .getDataChildByName("leaf-length-pattern-second");
456         assertNotNull(currentLeaf.getType());
457         PatternConstraintEffectiveImpl lengthConstraintSecond = (PatternConstraintEffectiveImpl)
458                 ((ExtendedType) (currentLeaf.getType())).getPatternConstraints().get(0);
459
460         assertEquals("^[0-9a-fA-F]*$", lengthConstraint.getRegularExpression());
461         assertNotNull(lengthConstraint.getReference());
462         assertNotNull(lengthConstraint.getDescription());
463         assertEquals("String ^[0-9a-fA-F]*$ is not valid regular expression.", lengthConstraint.getErrorMessage());
464         assertEquals("invalid-regular-expression", lengthConstraint.getErrorAppTag());
465         assertNotNull(lengthConstraint.toString());
466         assertNotNull(lengthConstraint.hashCode());
467         assertFalse(lengthConstraint.equals(null));
468         assertFalse(lengthConstraint.equals("test"));
469         assertFalse(lengthConstraint.equals(lengthConstraintSecond));
470         assertTrue(lengthConstraint.equals(lengthConstraintThird));
471     }
472
473     @Test
474     public void testString() {
475         currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null)
476                 .getDataChildByName("leaf-string");
477         assertNotNull(currentLeaf.getType());
478         StringEffectiveStatementImpl stringEff = (StringEffectiveStatementImpl)
479                 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next();
480         StringEffectiveStatementImpl stringEffSecond = (StringEffectiveStatementImpl)
481                 ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next();
482
483         assertEquals("string", stringEff.getQName().getLocalName());
484         assertEquals("CURRENT", stringEff.getStatus().toString());
485         assertEquals("", stringEff.getUnits());
486         assertNull(stringEff.getDefaultValue());
487         assertNotNull(stringEff.getUnknownSchemaNodes());
488         assertNull(stringEff.getBaseType());
489         assertNotNull(stringEff.getDescription());
490         assertNotNull(stringEff.getReference());
491         assertNotNull(stringEff.toString());
492         assertNotNull(stringEff.hashCode());
493         assertFalse(stringEff.equals(null));
494         assertFalse(stringEff.equals("test"));
495         assertTrue(stringEff.equals(stringEffSecond));
496         assertEquals("string", stringEff.getPath().getLastComponent().getLocalName());
497         assertEquals(1, stringEff.getLengthConstraints().size());
498         assertNotNull(stringEff.getPatternConstraints());
499     }
500 }