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