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