From c9a6ed1bb97f246319aec053599f66f0bd5721a3 Mon Sep 17 00:00:00 2001 From: Igor Foltin Date: Tue, 16 Aug 2016 15:06:58 +0200 Subject: [PATCH] BUG-6316: Fix Bit and EnumPair's position/value types yang.model.api.type defines the effective model of the world, where these attributes cannot ever be null, which is in contrast to yang.model.api.stmt, which is the declared model -- where they can in fact be null. Fix this discrepancy by forcing the methods to return simple types Change-Id: I27b9d6d283cd14b2044890d9ccd19bf92647f27e Signed-off-by: Robert Varga Signed-off-by: Igor Foltin Signed-off-by: Peter Kajsa --- .../model/api/type/BitsTypeDefinition.java | 16 +- .../model/api/type/EnumTypeDefinition.java | 7 +- .../yang/model/util/type/BitImpl.java | 14 +- .../yang/model/util/type/BitsTypeBuilder.java | 3 - .../yang/model/util/type/EnumPairImpl.java | 13 +- .../util/type/EnumerationTypeBuilder.java | 2 - .../type/BitEffectiveStatementImpl.java | 26 +-- ...tsSpecificationEffectiveStatementImpl.java | 35 ++-- .../type/EnumEffectiveStatementImpl.java | 16 +- ...umSpecificationEffectiveStatementImpl.java | 35 ++-- .../yangtools/yang/stmt/Bug6316.java | 105 ++++++++++ .../yang/stmt/EffectiveStatementTypeTest.java | 189 ++++++++---------- .../src/test/resources/bugs/bug6316/foo.yang | 40 ++++ 13 files changed, 312 insertions(+), 189 deletions(-) create mode 100644 yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6316.java create mode 100644 yang/yang-parser-impl/src/test/resources/bugs/bug6316/foo.yang diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/BitsTypeDefinition.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/BitsTypeDefinition.java index 7d13921ffe..bbaa5c23ef 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/BitsTypeDefinition.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/BitsTypeDefinition.java @@ -13,9 +13,7 @@ import org.opendaylight.yangtools.yang.model.api.SchemaNode; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; /** - * * Makes is possible to access to the individual bits values of this type. - * */ public interface BitsTypeDefinition extends TypeDefinition { /** @@ -33,18 +31,18 @@ public interface BitsTypeDefinition extends TypeDefinition { */ interface Bit extends SchemaNode { /** - * The position value MUST be in the range 0 to 4294967295, and it MUST - * be unique within the bits type. + * Returns the name of the concrete bit. * - * @return The position value of bit in range from 0 to 4294967295. + * @return string with the name of the concrete bit */ - Long getPosition(); + @Nonnull String getName(); /** - * Returns the name of the concrete bit. + * The position value MUST be in the range 0 to 4294967295, and it MUST + * be unique within the bits type. * - * @return string with the name of the concrete bit + * @return The position value of bit in range from 0 to 4294967295. */ - @Nonnull String getName(); + long getPosition(); } } diff --git a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java index eaa3fa6c98..770b5de84a 100644 --- a/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java +++ b/yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/type/EnumTypeDefinition.java @@ -13,10 +13,8 @@ import org.opendaylight.yangtools.yang.model.api.DocumentedNode; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; /** - * * Makes is possible to access to the individual enumeration values of this * type. - * */ public interface EnumTypeDefinition extends TypeDefinition { /** @@ -44,11 +42,10 @@ public interface EnumTypeDefinition extends TypeDefinition { /** * The "value" statement, which is optional, is used to associate an * integer value with the assigned name for the enum. This integer value - * MUST be in the range -2147483648 to 2147483647, and it MUST be unique - * within the enumeration type. + * MUST be unique within the enumeration type. * * @return integer value assigned to enumeration */ - Integer getValue(); + int getValue(); } } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitImpl.java index f7edfe22cf..8828f4dda3 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitImpl.java @@ -23,12 +23,14 @@ final class BitImpl implements Bit, Immutable { private final String description; private final String reference; private final Status status; - private final Long position; + private final long position; - BitImpl(final SchemaPath schemaPath, final Long position, final String description, + BitImpl(final SchemaPath schemaPath, final long position, final String description, final String reference, final Status status, final List unknownNodes) { this.schemaPath = Preconditions.checkNotNull(schemaPath, "Schema Path should not be null"); - this.position = Preconditions.checkNotNull(position, "Position should not be null"); + + Preconditions.checkArgument(position >= 0L && position <= 4294967295L, "Invalid position %s", position); + this.position = position; this.description = description; this.reference = reference; this.status = Preconditions.checkNotNull(status); @@ -66,7 +68,7 @@ final class BitImpl implements Bit, Immutable { } @Override - public Long getPosition() { + public long getPosition() { return position; } @@ -81,7 +83,7 @@ final class BitImpl implements Bit, Immutable { int result = 1; result = prime * result + getQName().hashCode(); result = prime * result + schemaPath.hashCode(); - result = prime * result + position.hashCode(); + result = prime * result + Long.hashCode(position); result = prime * result + unknownNodes.hashCode(); return result; } @@ -97,7 +99,7 @@ final class BitImpl implements Bit, Immutable { if (getClass() != obj.getClass()) { return false; } - Bit other = (Bit) obj; + final Bit other = (Bit) obj; return Objects.equals(schemaPath, other.getPath()); } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java index 04ee96a53f..016a5d2d1d 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/BitsTypeBuilder.java @@ -7,7 +7,6 @@ */ package org.opendaylight.yangtools.yang.model.util.type; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.util.HashMap; @@ -25,8 +24,6 @@ public final class BitsTypeBuilder extends TypeBuilder { } public BitsTypeBuilder addBit(@Nonnull final Bit item) { - Preconditions.checkArgument(item.getPosition() != null, "Bit %s has null position", item); - builder.put(item.getName(), item); return this; } diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumPairImpl.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumPairImpl.java index c2d19a0ed2..5ba72ffe69 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumPairImpl.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumPairImpl.java @@ -21,13 +21,13 @@ final class EnumPairImpl implements EnumPair, Immutable { private final String description; private final String reference; private final Status status; - private final Integer value; private final String name; + private final int value; - EnumPairImpl(final String name, final Integer value, final String description, final String reference, + EnumPairImpl(final String name, final int value, final String description, final String reference, final Status status, final List unknownSchemaNodes) { - this.value = Preconditions.checkNotNull(value); this.name = Preconditions.checkNotNull(name); + this.value = value; this.description = description; this.reference = reference; this.status = Preconditions.checkNotNull(status); @@ -60,7 +60,7 @@ final class EnumPairImpl implements EnumPair, Immutable { } @Override - public Integer getValue() { + public int getValue() { return value; } @@ -70,7 +70,7 @@ final class EnumPairImpl implements EnumPair, Immutable { int result = 1; result = prime * result + unknownSchemaNodes.hashCode(); result = prime * result + name.hashCode(); - result = prime * result + value.hashCode(); + result = prime * result + Integer.hashCode(value); return result; } @@ -87,8 +87,7 @@ final class EnumPairImpl implements EnumPair, Immutable { return false; } - return Objects.equals(value, other.getValue()) && - Objects.equals(unknownSchemaNodes, other.getUnknownSchemaNodes()); + return value == other.getValue() && Objects.equals(unknownSchemaNodes, other.getUnknownSchemaNodes()); } @Override diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java index b2658372e4..fa272b84f4 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/type/EnumerationTypeBuilder.java @@ -7,7 +7,6 @@ */ package org.opendaylight.yangtools.yang.model.util.type; -import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap.Builder; import java.util.HashMap; @@ -25,7 +24,6 @@ public final class EnumerationTypeBuilder extends TypeBuilder implements Bit { +public class BitEffectiveStatementImpl extends AbstractEffectiveDocumentedNode { private final QName qName; private final SchemaPath schemaPath; - private Long position; + private final Long declaredPosition; private final List unknownSchemaNodes; public BitEffectiveStatementImpl(final StmtContext ctx) { super(ctx); - List unknownSchemaNodesInit = new ArrayList<>(); - qName = ctx.getStatementArgument(); schemaPath = ctx.getSchemaPath().get(); + final List unknownSchemaNodesInit = new ArrayList<>(); + Long declaredPositionInit = null; for (final EffectiveStatement effectiveStatement : effectiveSubstatements()) { if (effectiveStatement instanceof PositionEffectiveStatementImpl) { - position = ((PositionEffectiveStatementImpl) effectiveStatement).argument(); + declaredPositionInit = ((PositionEffectiveStatementImpl) effectiveStatement).argument(); } if (effectiveStatement instanceof UnknownSchemaNode) { unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement); } } + declaredPosition = declaredPositionInit; unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit); } - @Override - public Long getPosition() { - return position; + public Long getDeclaredPosition() { + return declaredPosition; } - @Override public String getName() { return qName.getLocalName(); } - @Override public QName getQName() { return qName; } - @Override public SchemaPath getPath() { return schemaPath; } @@ -80,7 +76,7 @@ public class BitEffectiveStatementImpl extends AbstractEffectiveDocumentedNode> ctx) { + public BitsSpecificationEffectiveStatementImpl( + final StmtContext> ctx) { super(ctx); final BitsTypeBuilder builder = BaseTypes.bitsTypeBuilder(ctx.getSchemaPath().get()); Long highestPosition = null; for (final EffectiveStatement stmt : effectiveSubstatements()) { - if (stmt instanceof Bit) { - Bit b = (Bit) stmt; + if (stmt instanceof BitEffectiveStatementImpl) { + final BitEffectiveStatementImpl bitSubStmt = (BitEffectiveStatementImpl) stmt; - if (b.getPosition() == null) { - final Long newPos; - if (highestPosition == null) { - newPos = 0L; - } else if (highestPosition != 4294967295L) { - newPos = highestPosition + 1; + final long effectivePos; + if (bitSubStmt.getDeclaredPosition() == null) { + if (highestPosition != null) { + SourceException.throwIf(highestPosition == 4294967295L, ctx.getStatementSourceReference(), + "Bit %s must have a position statement", bitSubStmt); + effectivePos = highestPosition + 1; } else { - throw new SourceException(ctx.getStatementSourceReference(), - "Bit %s must have a position statement", b); + effectivePos = 0L; } - - b = BitBuilder.create(b.getPath(), newPos).setDescription(b.getDescription()) - .setReference(b.getReference()).setStatus(b.getStatus()) - .setUnknownSchemaNodes(b.getUnknownSchemaNodes()).build(); + } else { + effectivePos = bitSubStmt.getDeclaredPosition(); } + final Bit b = BitBuilder.create(bitSubStmt.getPath(), effectivePos) + .setDescription(bitSubStmt.getDescription()).setReference(bitSubStmt.getReference()) + .setStatus(bitSubStmt.getStatus()).setUnknownSchemaNodes(bitSubStmt.getUnknownSchemaNodes()) + .build(); + SourceException.throwIf(b.getPosition() < 0L && b.getPosition() > 4294967295L, ctx.getStatementSourceReference(), "Bit %s has illegal position", b); @@ -60,7 +63,7 @@ public final class BitsSpecificationEffectiveStatementImpl extends builder.addBit(b); } if (stmt instanceof UnknownEffectiveStatementImpl) { - builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt); + builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl) stmt); } } diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumEffectiveStatementImpl.java index a9497b5454..dafa786f16 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumEffectiveStatementImpl.java @@ -13,16 +13,14 @@ import java.util.List; import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement; import org.opendaylight.yangtools.yang.model.api.stmt.EnumStatement; -import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.AbstractEffectiveDocumentedNode; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.ValueEffectiveStatementImpl; -public class EnumEffectiveStatementImpl extends AbstractEffectiveDocumentedNode - implements EnumPair { +public class EnumEffectiveStatementImpl extends AbstractEffectiveDocumentedNode { private final List unknownSchemaNodes; private final String name; - private Integer value; + private final Integer declaredValue; public EnumEffectiveStatementImpl(final StmtContext ctx) { super(ctx); @@ -30,26 +28,26 @@ public class EnumEffectiveStatementImpl extends AbstractEffectiveDocumentedNode< name = ctx.rawStatementArgument(); final List unknownSchemaNodesInit = new ArrayList<>(); + Integer declaredValueInit = null; for (final EffectiveStatement effectiveStatement : effectiveSubstatements()) { if (effectiveStatement instanceof ValueEffectiveStatementImpl) { - value = ((ValueEffectiveStatementImpl) effectiveStatement).argument(); + declaredValueInit = ((ValueEffectiveStatementImpl) effectiveStatement).argument(); } if (effectiveStatement instanceof UnknownSchemaNode) { unknownSchemaNodesInit.add((UnknownSchemaNode) effectiveStatement); } } + declaredValue = declaredValueInit; unknownSchemaNodes = ImmutableList.copyOf(unknownSchemaNodesInit); } - @Override public String getName() { return name; } - @Override - public Integer getValue() { - return value; + public Integer getDeclaredValue() { + return declaredValue; } @Override diff --git a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumSpecificationEffectiveStatementImpl.java b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumSpecificationEffectiveStatementImpl.java index 09937c15b5..425d6e74e8 100644 --- a/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumSpecificationEffectiveStatementImpl.java +++ b/yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/effective/type/EnumSpecificationEffectiveStatementImpl.java @@ -26,31 +26,34 @@ public final class EnumSpecificationEffectiveStatementImpl extends private final EnumTypeDefinition typeDefinition; - public EnumSpecificationEffectiveStatementImpl(final StmtContext> ctx) { + public EnumSpecificationEffectiveStatementImpl( + final StmtContext> ctx) { super(ctx); final EnumerationTypeBuilder builder = BaseTypes.enumerationTypeBuilder(ctx.getSchemaPath().get()); Integer highestValue = null; for (final EffectiveStatement stmt : effectiveSubstatements()) { - if (stmt instanceof EnumPair) { - EnumPair p = (EnumPair) stmt; + if (stmt instanceof EnumEffectiveStatementImpl) { + final EnumEffectiveStatementImpl enumSubStmt = (EnumEffectiveStatementImpl) stmt; - if (p.getValue() == null) { - final Integer newValue; - if (highestValue == null) { - newValue = 0; - } else if (highestValue != 2147483647) { - newValue = highestValue + 1; + final int effectiveValue; + if (enumSubStmt.getDeclaredValue() == null) { + if (highestValue != null) { + SourceException.throwIf(highestValue == 2147483647, ctx.getStatementSourceReference(), + "Enum '%s' must have a value statement", enumSubStmt); + effectiveValue = highestValue + 1; } else { - throw new SourceException(ctx.getStatementSourceReference(), - "Enum '%s' must have a value statement", p); + effectiveValue = 0; } - - p = EnumPairBuilder.create(p.getName(), newValue).setDescription(p.getDescription()) - .setReference(p.getReference()).setStatus(p.getStatus()) - .setUnknownSchemaNodes(p.getUnknownSchemaNodes()).build(); + } else { + effectiveValue = enumSubStmt.getDeclaredValue(); } + final EnumPair p = EnumPairBuilder.create(enumSubStmt.getName(), effectiveValue) + .setDescription(enumSubStmt.getDescription()).setReference(enumSubStmt.getReference()) + .setStatus(enumSubStmt.getStatus()).setUnknownSchemaNodes(enumSubStmt.getUnknownSchemaNodes()) + .build(); + if (highestValue == null || highestValue < p.getValue()) { highestValue = p.getValue(); } @@ -58,7 +61,7 @@ public final class EnumSpecificationEffectiveStatementImpl extends builder.addEnum(p); } if (stmt instanceof UnknownEffectiveStatementImpl) { - builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl)stmt); + builder.addUnknownSchemaNode((UnknownEffectiveStatementImpl) stmt); } } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6316.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6316.java new file mode 100644 index 0000000000..eb60e0a974 --- /dev/null +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug6316.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License v1.0 which accompanies this distribution, + * and is available at http://www.eclipse.org/legal/epl-v10.html + */ +package org.opendaylight.yangtools.yang.stmt; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.FileNotFoundException; +import java.net.URISyntaxException; +import java.util.List; +import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; +import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.SchemaContext; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit; +import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; +import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; +import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; + +public class Bug6316 { + @Test + public void test() throws SourceException, FileNotFoundException, ReactorException, URISyntaxException { + final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6316"); + assertNotNull(context); + verifyEnumTypedefinition(context); + verifyBitsTypedefinition(context); + } + + private void verifyEnumTypedefinition(final SchemaContext context) { + final DataSchemaNode dataChildByName = context.getDataChildByName(QName + .create("foo", "1970-01-01", "enum-leaf")); + assertTrue(dataChildByName instanceof LeafSchemaNode); + final LeafSchemaNode enumLeaf = (LeafSchemaNode) dataChildByName; + final TypeDefinition> type = enumLeaf.getType(); + assertTrue(type instanceof EnumTypeDefinition); + final EnumTypeDefinition myEnumeration = (EnumTypeDefinition) type; + final List values = myEnumeration.getValues(); + for (final EnumPair enumPair : values) { + final String name = enumPair.getName(); + switch (name) { + case "zero": + assertEquals(0, enumPair.getValue()); + break; + case "twenty": + assertEquals(20, enumPair.getValue()); + break; + case "twenty-one": + assertEquals(21, enumPair.getValue()); + break; + case "two": + assertEquals(2, enumPair.getValue()); + break; + case "twenty-two": + assertEquals(22, enumPair.getValue()); + break; + default: + fail("Unexpected enum name."); + } + } + } + + private void verifyBitsTypedefinition(final SchemaContext context) { + final DataSchemaNode dataChildByName = context.getDataChildByName(QName + .create("foo", "1970-01-01", "bits-leaf")); + assertTrue(dataChildByName instanceof LeafSchemaNode); + final LeafSchemaNode bitsLeaf = (LeafSchemaNode) dataChildByName; + final TypeDefinition> type = bitsLeaf.getType(); + assertTrue(type instanceof BitsTypeDefinition); + final BitsTypeDefinition myBits = (BitsTypeDefinition) type; + final List positions = myBits.getBits(); + for (final Bit bit : positions) { + final String name = bit.getName(); + switch (name) { + case "zero": + assertEquals(0, bit.getPosition()); + break; + case "twenty": + assertEquals(20, bit.getPosition()); + break; + case "twenty-one": + assertEquals(21, bit.getPosition()); + break; + case "two": + assertEquals(2, bit.getPosition()); + break; + case "twenty-two": + assertEquals(22, bit.getPosition()); + break; + default: + fail("Unexpected bit name."); + } + } + } +} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java index 529d2a9926..b839c2b8b6 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/EffectiveStatementTypeTest.java @@ -17,14 +17,18 @@ import static org.junit.Assert.assertTrue; import java.util.List; import org.junit.Before; import org.junit.Test; +import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.stmt.TypeEffectiveStatement; import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition.Bit; import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition; +import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair; import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition; import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; @@ -37,10 +41,8 @@ import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.EffectiveSchemaContext; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.LeafEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitEffectiveStatementImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.BitsSpecificationEffectiveStatementImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.Decimal64SpecificationEffectiveStatementImpl; -import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumEffectiveStatementImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.EnumSpecificationEffectiveStatementImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.IdentityRefSpecificationEffectiveStatementImpl; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective.type.LeafrefSpecificationEffectiveStatementImpl; @@ -53,22 +55,24 @@ public class EffectiveStatementTypeTest { "/type-tests/types.yang", false); private static EffectiveSchemaContext effectiveSchemaContext; private static LeafSchemaNode currentLeaf; + private static Module types; @Before public void setup() throws ReactorException { - CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); + final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild(); reactor.addSource(IMPORTED_MODULE); effectiveSchemaContext = reactor.buildEffective(); + types = effectiveSchemaContext.findModuleByName("types", null); + assertNotNull(types); } @Test public void testBinary() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-binary"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-binary")); assertNotNull(currentLeaf.getType()); - BinaryTypeDefinition binaryEff = (BinaryTypeDefinition) ((TypeEffectiveStatement) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final BinaryTypeDefinition binaryEff = (BinaryTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(binaryEff.getBaseType()); assertNull(binaryEff.getUnits()); @@ -84,16 +88,15 @@ public class EffectiveStatementTypeTest { @Test public void testBits() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-bits"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-bits")); assertNotNull(currentLeaf.getType()); - List bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits(); - BitEffectiveStatementImpl bitEff = (BitEffectiveStatementImpl) bitsEffIter.get(0); - BitEffectiveStatementImpl bitEffSecond = (BitEffectiveStatementImpl) bitsEffIter.get(1); + final List bitsEffIter = ((BitsTypeDefinition) currentLeaf.getType()).getBits(); + final Bit bitEff = bitsEffIter.get(0); + final Bit bitEffSecond = bitsEffIter.get(1); - BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatementImpl) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final BitsTypeDefinition bitsEff = ((BitsSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(bitsEff.getBaseType()); assertNotNull(bitsEff.getQName()); @@ -124,17 +127,15 @@ public class EffectiveStatementTypeTest { assertNotNull(bitEff.toString()); assertEquals("one", bitEff.getName()); assertNotNull(bitEff.getQName()); - assertEquals("0", bitEff.getPosition().toString()); - assertEquals(0, bitEff.getPosition().longValue()); + assertEquals(0, bitEff.getPosition()); } @Test public void testBoolean() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-boolean"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-boolean")); assertNotNull(currentLeaf.getType()); - BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final BooleanTypeDefinition booleanEff = (BooleanTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(booleanEff.getBaseType()); assertNull(booleanEff.getUnits()); @@ -150,11 +151,10 @@ public class EffectiveStatementTypeTest { @Test public void testDecimal64() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-decimal64"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-decimal64")); assertNotNull(currentLeaf.getType()); - DecimalTypeDefinition decimal64Eff = ((Decimal64SpecificationEffectiveStatementImpl) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final DecimalTypeDefinition decimal64Eff = ((Decimal64SpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(decimal64Eff.getBaseType()); assertNull(decimal64Eff.getUnits()); @@ -162,7 +162,8 @@ public class EffectiveStatementTypeTest { assertEquals("decimal64", decimal64Eff.getQName().getLocalName()); assertNotNull(decimal64Eff.getUnknownSchemaNodes()); - // FIXME: The model is wrong: description/reference/status are not allowed under 'type', how come we parse it? + // FIXME: The yang model api is wrong: description/reference/status are not allowed under 'type', how come we parse it? + // allowed under 'type', how come we parse it? assertNull(decimal64Eff.getDescription()); assertNull(decimal64Eff.getReference()); assertEquals("CURRENT", decimal64Eff.getStatus().toString()); @@ -179,11 +180,10 @@ public class EffectiveStatementTypeTest { @Test public void testEmpty() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-empty"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-empty")); assertNotNull(currentLeaf.getType()); - EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final EmptyTypeDefinition emptyEff = (EmptyTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(emptyEff.getUnits()); assertNull(emptyEff.getDefaultValue()); @@ -199,14 +199,13 @@ public class EffectiveStatementTypeTest { @Test public void testEnum() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-enum"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-enum")); assertNotNull(currentLeaf.getType()); - List enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues(); - EnumEffectiveStatementImpl enumEff = (EnumEffectiveStatementImpl) enumEffIter.iterator().next(); + final List enumEffIter = ((EnumTypeDefinition) currentLeaf.getType()).getValues(); + final EnumPair enumEff = enumEffIter.iterator().next(); - EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatementImpl) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final EnumTypeDefinition enumSpecEff = ((EnumSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertEquals("enumeration", enumSpecEff.getQName().getLocalName()); assertEquals("enumeration", enumSpecEff.getPath().getLastComponent().getLocalName()); @@ -229,16 +228,16 @@ public class EffectiveStatementTypeTest { assertEquals("test enum", enumEff.getDescription()); assertEquals("test enum ref", enumEff.getReference()); assertEquals("CURRENT", enumEff.getStatus().toString()); - assertEquals("0", enumEff.getValue().toString()); + assertEquals(0, enumEff.getValue()); } @Test public void testIdentityRef() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-identityref"); + currentLeaf = (LeafSchemaNode) types + .getDataChildByName(QName.create(types.getQNameModule(), "leaf-identityref")); assertNotNull(currentLeaf.getType()); - IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatementImpl) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final IdentityrefTypeDefinition identityRefEff = ((IdentityRefSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNull(identityRefEff.getDefaultValue()); assertEquals("identityref", identityRefEff.getQName().getLocalName()); @@ -257,12 +256,11 @@ public class EffectiveStatementTypeTest { @Test public void testInstanceIdentifier() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-instance-identifier"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), + "leaf-instance-identifier")); assertNotNull(currentLeaf.getType()); - InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition) - ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) - .effectiveSubstatements().iterator().next()).getTypeDefinition(); + final InstanceIdentifierTypeDefinition instanceIdentEff = (InstanceIdentifierTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertNotNull(instanceIdentEff.toString()); assertFalse(instanceIdentEff.requireInstance()); @@ -283,12 +281,11 @@ public class EffectiveStatementTypeTest { @Test public void testLeafref() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-leafref"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-leafref")); assertNotNull(currentLeaf.getType()); - LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl) - ((LeafEffectiveStatementImpl) currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final LeafrefTypeDefinition leafrefEff = ((LeafrefSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertEquals("/container-test/leaf-test", leafrefEff.getPathStatement().toString()); assertNull(leafrefEff.getBaseType()); @@ -309,73 +306,61 @@ public class EffectiveStatementTypeTest { @Test public void testIntAll() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-int8"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int8")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement int8Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + final TypeEffectiveStatement int8Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(int8Eff.toString()); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-int16"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int16")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement int16Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + final TypeEffectiveStatement int16Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(int16Eff.toString()); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-int32"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int32")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement int32Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + final TypeEffectiveStatement int32Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(int32Eff.toString()); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-int64"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-int64")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement int64Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + final TypeEffectiveStatement int64Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(int64Eff.toString()); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-uint8"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint8")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement uint8Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + final TypeEffectiveStatement uint8Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(uint8Eff.toString()); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-uint16"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint16")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement uint16Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) - currentLeaf) + final TypeEffectiveStatement uint16Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(uint16Eff.toString()); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-uint32"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint32")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement uint32Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) - currentLeaf) + final TypeEffectiveStatement uint32Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(uint32Eff.toString()); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-uint64"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-uint64")); assertNotNull(currentLeaf.getType()); - TypeEffectiveStatement uint64Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) - currentLeaf) + final TypeEffectiveStatement uint64Eff = (TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) .effectiveSubstatements().iterator().next(); assertNotNull(uint64Eff.toString()); } @Test public void testUnion() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-union"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-union")); assertNotNull(currentLeaf.getType()); - UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatementImpl) - ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final UnionTypeDefinition unionEff = ((UnionSpecificationEffectiveStatementImpl) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertEquals(2, unionEff.getTypes().size()); assertEquals("union", unionEff.getQName().getLocalName()); @@ -396,15 +381,18 @@ public class EffectiveStatementTypeTest { @Test public void testLengthConstraint() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-length-pattern"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), + "leaf-length-pattern")); assertNotNull(currentLeaf.getType()); - LengthConstraint lengthConstraint = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0); - LengthConstraint lengthConstraintThird = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-length-pattern-second"); + final LengthConstraint lengthConstraint = ((StringTypeDefinition) (currentLeaf.getType())) + .getLengthConstraints().get(0); + final LengthConstraint lengthConstraintThird = ((StringTypeDefinition) (currentLeaf.getType())) + .getLengthConstraints().get(0); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), + "leaf-length-pattern-second")); assertNotNull(currentLeaf.getType()); - LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) (currentLeaf.getType())).getLengthConstraints().get(0); + final LengthConstraint lengthConstraintSecond = ((StringTypeDefinition) (currentLeaf.getType())) + .getLengthConstraints().get(0); assertEquals(1, lengthConstraint.getMin().intValue()); assertEquals(255, lengthConstraint.getMax().intValue()); @@ -422,18 +410,18 @@ public class EffectiveStatementTypeTest { @Test public void testPatternConstraint() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-length-pattern"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), + "leaf-length-pattern")); assertNotNull(currentLeaf.getType()); - PatternConstraintEffectiveImpl lengthConstraint = (PatternConstraintEffectiveImpl) - ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0); - PatternConstraintEffectiveImpl lengthConstraintThird = (PatternConstraintEffectiveImpl) - ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0); - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-length-pattern-second"); + final PatternConstraintEffectiveImpl lengthConstraint = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf + .getType())).getPatternConstraints().get(0); + final PatternConstraintEffectiveImpl lengthConstraintThird = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf + .getType())).getPatternConstraints().get(0); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), + "leaf-length-pattern-second")); assertNotNull(currentLeaf.getType()); - PatternConstraintEffectiveImpl lengthConstraintSecond = (PatternConstraintEffectiveImpl) - ((StringTypeDefinition) (currentLeaf.getType())).getPatternConstraints().get(0); + final PatternConstraintEffectiveImpl lengthConstraintSecond = (PatternConstraintEffectiveImpl) ((StringTypeDefinition) (currentLeaf + .getType())).getPatternConstraints().get(0); assertEquals("^[0-9a-fA-F]*$", lengthConstraint.getRegularExpression()); assertNull(lengthConstraint.getReference()); @@ -450,11 +438,10 @@ public class EffectiveStatementTypeTest { @Test public void testString() { - currentLeaf = (LeafSchemaNode) effectiveSchemaContext.findModuleByName("types", null) - .getDataChildByName("leaf-string"); + currentLeaf = (LeafSchemaNode) types.getDataChildByName(QName.create(types.getQNameModule(), "leaf-string")); assertNotNull(currentLeaf.getType()); - StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement) - ((LeafEffectiveStatementImpl)currentLeaf).effectiveSubstatements().iterator().next()).getTypeDefinition(); + final StringTypeDefinition stringEff = (StringTypeDefinition) ((TypeEffectiveStatement) ((LeafEffectiveStatementImpl) currentLeaf) + .effectiveSubstatements().iterator().next()).getTypeDefinition(); assertEquals("string", stringEff.getQName().getLocalName()); assertEquals("CURRENT", stringEff.getStatus().toString()); diff --git a/yang/yang-parser-impl/src/test/resources/bugs/bug6316/foo.yang b/yang/yang-parser-impl/src/test/resources/bugs/bug6316/foo.yang new file mode 100644 index 0000000000..1a56c0550a --- /dev/null +++ b/yang/yang-parser-impl/src/test/resources/bugs/bug6316/foo.yang @@ -0,0 +1,40 @@ +module foo { + namespace "foo"; + prefix foo; + + typedef my-enumeration { + type enumeration { + enum zero; + enum twenty { + value 20; + } + enum twenty-one; + enum two { + value 2; + } + enum twenty-two; + } + } + + typedef my-bits { + type bits { + bit zero; + bit twenty { + position 20; + } + bit twenty-one; + bit two { + position 2; + } + bit twenty-two; + } + } + + leaf enum-leaf { + type my-enumeration; + } + + leaf bits-leaf { + type my-bits; + } +} -- 2.36.6