import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition
-import org.opendaylight.yangtools.yang.model.util.ExtendedType
import org.slf4j.Logger
import org.slf4j.LoggerFactory
import org.sonatype.plexus.build.incremental.BuildContext
«type.lengthConstraints.toLengthStmt»
'''
- private def dispatch toLength(ExtendedType type) '''
- «type.lengthConstraints.toLengthStmt»
- '''
-
private def dispatch toRange(TypeDefinition<?> type) {
}
«type.rangeConstraints.toRangeStmt»
'''
- private def dispatch toRange(ExtendedType type) '''
- «type.rangeConstraints.toRangeStmt»
- '''
-
def toLengthStmt(Collection<LengthConstraint> lengths) '''
«IF lengths != null && !lengths.empty»
«listItem("Length restrictions:")»
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
}
private static boolean isInnerType(final LeafSchemaNode leaf, final TypeDefinition<?> type) {
- // Deal with old parser, clearing out references to typedefs
- if (type instanceof ExtendedType) {
- return false;
- }
-
// New parser with encapsulated type
if (leaf.getPath().equals(type.getPath())) {
return true;
}
private static TypeDefinition<?> getBaseOrDeclaredType(final TypeDefinition<?> typeDef) {
- if (typeDef instanceof ExtendedType) {
- // Legacy behaviour returning ExtendedType is enough
- return typeDef;
- }
// Returns DerivedType in case of new parser.
final TypeDefinition<?> baseType = typeDef.getBaseType();
return (baseType != null && baseType.getBaseType() != null) ? baseType : typeDef;
/**
* Builds generated TO builders for <code>typeDef</code> of type
- * {@link org.opendaylight.yangtools.yang.model.util.UnionType UnionType} or
- * {@link org.opendaylight.yangtools.yang.model.api.type.BitsTypeDefinition
- * BitsTypeDefinition} which are also added to <code>typeBuilder</code> as
- * enclosing transfer object.
+ * {@link UnionTypeDefinition} or {@link BitsTypeDefinition} which are
+ * also added to <code>typeBuilder</code> as enclosing transfer object.
*
* If more then one generated TO builder is created for enclosing then all
* of the generated TO builders are added to <code>typeBuilder</code> as
builder.addAnnotation("", "Deprecated");
}
}
-}
\ No newline at end of file
+}
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.EffectiveAugmentationSchema;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
private static BiMap<String, String> getEnumMapping(final Entry<GeneratedType, Object> typeWithSchema) {
final TypeDefinition<?> typeDef = (TypeDefinition<?>) typeWithSchema.getValue();
- final EnumTypeDefinition enumType;
- if(typeDef instanceof ExtendedType) {
- enumType = (EnumTypeDefinition) ((ExtendedType) typeDef).getBaseType();
- } else {
- Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition);
- enumType = (EnumTypeDefinition) typeDef;
- }
+ Preconditions.checkArgument(typeDef instanceof EnumTypeDefinition);
+ final EnumTypeDefinition enumType = (EnumTypeDefinition) typeDef;
final HashBiMap<String, String> mappedEnums = HashBiMap.create();
import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.RevisionAwareXPathImpl;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
-import org.opendaylight.yangtools.yang.model.util.UnionType;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.CompatUtils;
import org.opendaylight.yangtools.yang.parser.util.YangValidationException;
private static final Logger LOG = LoggerFactory.getLogger(TypeProviderImpl.class);
private static final Pattern NUMBERS_PATTERN = Pattern.compile("[0-9]+\\z");
+ // Backwards compatibility: Union types used to be instantiated in YANG namespace, which is no longer
+ // the case, as unions are emitted to their correct schema path.
+ private static final SchemaPath UNION_PATH = SchemaPath.create(true,
+ org.opendaylight.yangtools.yang.model.util.BaseTypes.UNION_QNAME);
+
/**
* Contains the schema data red from YANG files.
*/
if (typeDefinition.getBaseType() == null) {
// We have to deal with differing handling of decimal64. The old parser used a fixed Decimal64 type
// and generated an enclosing ExtendedType to hold any range constraints. The new parser instantiates
- // a base type which holds these constraints -- and the class is not a Decimal64.
- if (typeDefinition instanceof DecimalTypeDefinition && !(typeDefinition instanceof Decimal64)) {
+ // a base type which holds these constraints.
+ if (typeDefinition instanceof DecimalTypeDefinition) {
final Type ret = BaseYangTypes.BASE_YANG_TYPES_PROVIDER.javaTypeForSchemaDefinitionType(typeDefinition, parentNode, r);
if (ret != null) {
return ret;
Preconditions.checkArgument(typedef != null, "typedef can't be null");
final List<PatternConstraint> patternConstraints;
- if (typedef instanceof ExtendedType) {
- final TypeDefinition<?> strTypeDef = baseTypeDefForExtendedType(typedef);
- if (strTypeDef instanceof StringTypeDefinition) {
- patternConstraints = ((ExtendedType)typedef).getPatternConstraints();
- } else {
- patternConstraints = ImmutableList.of();
- }
- } else if (typedef instanceof StringTypeDefinition) {
+ if (typedef instanceof StringTypeDefinition) {
// FIXME: run diff against base
patternConstraints = ((StringTypeDefinition) typedef).getPatternConstraints();
} else {
* definition to the base type
*/
private static int getTypeDefinitionDepth(final TypeDefinition<?> typeDefinition) {
- // FIXME: rewrite this in a non-recursive manner, without ExtendedType and UnionType
+ // FIXME: rewrite this in a non-recursive manner
if (typeDefinition == null) {
return 1;
}
Date revision = first.getRevision();
Module parentModule = schemaContext.findModuleByNamespaceAndRevision(namespace, revision);
String basePackageName = BindingMapping.getRootPackageName(parentModule.getQNameModule());
-
- // Backwards compatibility: Union types used to be instantiated in YANG namespace, which is no longer
- // the case, as unions are emitted to their correct schema path. Create a proxy instance to meet the
- // codepath's expectations
- final SchemaPath typePath;
- if (type instanceof UnionType) {
- typePath = type.getPath();
- } else {
- typePath = UnionType.create(((UnionTypeDefinition)type).getTypes()).getPath();
- }
-
- String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, typePath);
+ String packageName = BindingGeneratorUtil.packageNameForGeneratedType(basePackageName, UNION_PATH);
className = packageName + "." + BindingMapping.getClassName(node.getQName());
}
}
+++ /dev/null
-/*
- * Copyright (c) 2013 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.sal.binding.yang.types;
-
-import com.google.common.base.Function;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.collect.Sets;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.parser.util.TopologicalSort;
-import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Node;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class UnionDependencySort {
- private static final Logger LOGGER = LoggerFactory.getLogger(UnionDependencySort.class);
-
- /**
- * Sorts union types by mutual dependencies.
- *
- * At the beginning the union types are selected from
- * <code>typeDefinitions</code> and wrapped to nodes. The nodes are sorted
- * and then the wrapped payload is extracted.
- *
- * @param typeDefinitions
- * set of type definitions.
- * @return list of extended type which are sorted by mutual dependencies
- * @throws IllegalArgumentException
- * if <code>typeDefinitions</code> equals <code>null</code>
- */
- public List<ExtendedType> sort(final Set<TypeDefinition<?>> typeDefinitions) {
- if (typeDefinitions == null) {
- LOGGER.error("Set of Type Definitions cannot be NULL!");
- throw new IllegalArgumentException("Set of Type Definitions " + "cannot be NULL!");
- }
-
- final Set<ExtendedType> extUnionTypes = unionsFromTypeDefinitions(typeDefinitions);
-
- final Set<Node> unsorted = unionTypesToNodes(extUnionTypes);
-
- final List<Node> sortedNodes = TopologicalSort.sort(unsorted);
- return Lists.transform(sortedNodes, new Function<Node, ExtendedType>() {
- @Override
- public ExtendedType apply(final Node input) {
- return (ExtendedType) (((NodeWrappedType) input).getWrappedType());
- }
- });
- }
-
- /**
- * Extracts only union types from <code>typeDefinitions</code> set.
- *
- * @param typeDefinitions
- * set of all type definitions
- * @return set of extended type which are union type definition
- */
- private static Set<ExtendedType> unionsFromTypeDefinitions(final Set<TypeDefinition<?>> typeDefinitions) {
- final Set<ExtendedType> unions = Sets.newHashSet();
-
- for (final TypeDefinition<?> typedef : typeDefinitions) {
- if ((typedef != null) && (typedef.getBaseType() != null) && (typedef instanceof ExtendedType)
- && (typedef.getBaseType() instanceof UnionTypeDefinition)) {
- unions.add((ExtendedType) typedef);
- }
- }
- return unions;
- }
-
- /**
- * Wraps every extended type which represents union to node type and adds to
- * every node information about dependencies.
- *
- * The mapping from union type to node is created. For every created node
- * (next <i>nodeFrom</i>) is for its wrapped union type passed the list of
- * inner types through and only those inner types which represent union type
- * are next considered. For every inner union type is found its wrapping
- * node (next as <i>nodeTo</i>). This dependency relationship between
- * nodeFrom and all found nodesTo is modeled with creating of one edge from
- * nodeFrom to nodeTo.
- *
- *
- * @param extUnionTypes
- * set of extended types which represents union types
- * @return set of nodes which contains wrapped union types set of node where
- * each one contains wrapped one union type
- */
- private static Set<Node> unionTypesToNodes(final Set<ExtendedType> extUnionTypes) {
- final Map<ExtendedType, Node> nodeMap = Maps.newHashMap();
- final Set<Node> resultNodes = Sets.newHashSet();
-
- for (final ExtendedType unionType : extUnionTypes) {
- final Node node = new NodeWrappedType(unionType);
- nodeMap.put(unionType, node);
- resultNodes.add(node);
- }
-
- for (final Node node : resultNodes) {
- final NodeWrappedType nodeFrom = (NodeWrappedType) node;
- final ExtendedType extUnionType = (ExtendedType) nodeFrom.getWrappedType();
-
- final UnionTypeDefinition unionType = (UnionTypeDefinition) extUnionType.getBaseType();
-
- final List<TypeDefinition<?>> innerTypes = unionType.getTypes();
- for (final TypeDefinition<?> typedef : innerTypes) {
- if (extUnionTypes.contains(typedef)) {
- final Node toNode = nodeMap.get(typedef);
- nodeFrom.addEdge(toNode);
- }
- }
- }
-
- return resultNodes;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 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.sal.binding.yang.types;
-
-import static org.junit.Assert.assertNotNull;
-
-import com.google.common.base.Optional;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.rules.ExpectedException;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
-
-public class UnionDependencySortTest {
-
- @Rule
- public ExpectedException expException = ExpectedException.none();
-
- @Test
- public void testSortMethod() {
-
- final UnionDependencySort unionDependencySort = new UnionDependencySort();
- final Set<TypeDefinition<?>> typeDefs = new HashSet<>();
-
- final TypeDefinition<?> stringType = BaseTypes.stringType();
- final ExtendedType extendedType = ExtendedType.builder(QName.create("ExtendedType1"), stringType, Optional.<String> absent(), Optional.<String> absent(), SchemaPath.create(false, QName.create("Cont1"), QName.create("List1"))).build();
-
- typeDefs.add(stringType);
- typeDefs.add(extendedType);
-
- final List<ExtendedType> sortedExtendedTypes = unionDependencySort.sort(typeDefs);
- assertNotNull(sortedExtendedTypes);
-
- expException.expect(IllegalArgumentException.class);
- expException.expectMessage("Set of Type Definitions cannot be NULL!");
- unionDependencySort.sort(null);
- }
-}
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
import org.opendaylight.yangtools.yang.model.util.type.DecimalTypeBuilder;
// instantiate a temporary unconstrained type and compare them.
//
// FIXME: looking at the generated code it looks as though we need to pass the restrictions without
- // comparison and also even in the case of the old parser
- if (type instanceof DecimalTypeDefinition && !(type instanceof Decimal64)) {
+ // comparison
+ if (type instanceof DecimalTypeDefinition) {
final DecimalTypeDefinition decimal = (DecimalTypeDefinition) type;
final DecimalTypeBuilder tmpBuilder = BaseTypes.decimalTypeBuilder(decimal.getPath());
tmpBuilder.setFractionDigits(decimal.getFractionDigits());
*
* FIXME: this probably not the best solution and needs further analysis.
*/
- if (type instanceof ExtendedType) {
- final ExtendedType ext = (ExtendedType)type;
- length = ext.getLengthConstraints();
- pattern = ext.getPatternConstraints();
-
- // Interesting special-case...
- List<RangeConstraint> tmp = ext.getRangeConstraints();
- if (tmp.isEmpty()) {
- final TypeDefinition<?> base = ext.getBaseType();
- if (base instanceof IntegerTypeDefinition) {
- tmp = ((IntegerTypeDefinition)base).getRangeConstraints();
- } else if (base instanceof UnsignedIntegerTypeDefinition) {
- tmp = ((UnsignedIntegerTypeDefinition)base).getRangeConstraints();
- } else if (base instanceof DecimalTypeDefinition) {
- tmp = ((DecimalTypeDefinition)base).getRangeConstraints();
- }
- }
-
- range = tmp;
- } else if (type instanceof BinaryTypeDefinition) {
+ if (type instanceof BinaryTypeDefinition) {
final BinaryTypeDefinition binary = (BinaryTypeDefinition)type;
final BinaryTypeDefinition base = binary.getBaseType();
if (base != null && base.getBaseType() != null) {
import static org.junit.Assert.fail;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-
import com.google.common.base.Optional;
+import com.google.common.collect.ImmutableList;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
-import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.LengthConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.PatternConstraint;
-import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
import org.opendaylight.yangtools.yang.model.util.BaseConstraints;
import org.opendaylight.yangtools.yang.model.util.DataNodeIterator;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType.Builder;
import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.DerivedTypes;
+import org.opendaylight.yangtools.yang.model.util.type.RestrictedTypes;
+import org.opendaylight.yangtools.yang.model.util.type.StringTypeBuilder;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
public class BindingGeneratorUtilTest {
+ private static final SchemaPath ROOT_PATH = SchemaPath.create(true, QName.create("/root"));
@Rule
public ExpectedException expectedEx = ExpectedException.none();
@Test
public void getRestrictionsTest() {
+ final Optional<String> absent = Optional.absent();
+ final StringTypeBuilder builder =
+ RestrictedTypes.newStringBuilder(BaseTypes.stringType(), ROOT_PATH);
- Optional<String> absent = Optional.absent();
-
- Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
- BaseTypes.int16Type(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
- ArrayList<LengthConstraint> lenght = new ArrayList<LengthConstraint>();
- ArrayList<RangeConstraint> range = new ArrayList<RangeConstraint>();
- ArrayList<PatternConstraint> pattern = new ArrayList<PatternConstraint>();
+ builder.addPatternConstraint(BaseConstraints.newPatternConstraint(".*", absent, absent));
+ builder.setLengthAlternatives(ImmutableList.of(
+ BaseConstraints.newLengthConstraint(1, 2, absent, absent)));
- lenght.add(BaseConstraints.newLengthConstraint(1, 2, absent, absent));
- range.add(BaseConstraints.newRangeConstraint(1, 2, absent, absent));
- pattern.add(BaseConstraints.newPatternConstraint(".*", absent, absent));
-
- extTypeBuilder.lengths(lenght);
- extTypeBuilder.ranges(range);
- extTypeBuilder.patterns(pattern);
-
- Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extTypeBuilder.build());
+ Restrictions restrictions = BindingGeneratorUtil.getRestrictions(builder.build());
assertNotNull(restrictions);
assertEquals(1, restrictions.getLengthConstraints().size());
- assertEquals(1, restrictions.getRangeConstraints().size());
+ assertEquals(0, restrictions.getRangeConstraints().size());
assertEquals(1, restrictions.getPatternConstraints().size());
assertFalse(restrictions.isEmpty());
assertTrue(restrictions.getLengthConstraints().contains(
BaseConstraints.newLengthConstraint(1, 2, absent, absent)));
- assertTrue(restrictions.getRangeConstraints()
- .contains(BaseConstraints.newRangeConstraint(1, 2, absent, absent)));
assertTrue(restrictions.getPatternConstraints().contains(
BaseConstraints.newPatternConstraint(".*", absent, absent)));
}
@Test
public void getEmptyRestrictionsTest() {
-
- Optional<String> absent = Optional.absent();
-
- Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
- BaseTypes.stringType(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
- Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extTypeBuilder.build());
+ final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(BaseTypes.stringType(), ROOT_PATH).build();
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
assertNotNull(restrictions);
assertTrue(restrictions.isEmpty());
-
}
@Test
public void getDefaultIntegerRestrictionsTest() {
-
- Optional<String> absent = Optional.absent();
-
- Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
- BaseTypes.int16Type(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
- ExtendedType extType = extTypeBuilder.build();
- Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+ final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(BaseTypes.int16Type(), ROOT_PATH).build();
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
assertNotNull(restrictions);
assertFalse(restrictions.isEmpty());
- assertEquals(((IntegerTypeDefinition) extType.getBaseType()).getRangeConstraints(),
+ assertEquals(((IntegerTypeDefinition) type.getBaseType()).getRangeConstraints(),
restrictions.getRangeConstraints());
assertTrue(restrictions.getLengthConstraints().isEmpty());
assertTrue(restrictions.getPatternConstraints().isEmpty());
-
}
@Test
public void getDefaultUnsignedIntegerRestrictionsTest() {
-
- Optional<String> absent = Optional.absent();
-
- Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
- BaseTypes.uint16Type(), absent, absent, SchemaPath.create(true, QName.create("/root")));
-
- ExtendedType extType = extTypeBuilder.build();
- Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+ final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(BaseTypes.uint16Type(), ROOT_PATH).build();
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
assertNotNull(restrictions);
assertFalse(restrictions.isEmpty());
- assertEquals(((UnsignedIntegerTypeDefinition) extType.getBaseType()).getRangeConstraints(),
+ assertEquals(((UnsignedIntegerTypeDefinition) type.getBaseType()).getRangeConstraints(),
restrictions.getRangeConstraints());
assertTrue(restrictions.getLengthConstraints().isEmpty());
assertTrue(restrictions.getPatternConstraints().isEmpty());
@Test
public void getDefaultDecimalRestrictionsTest() {
+ final DecimalTypeDefinition base = BaseTypes.decimalTypeBuilder(ROOT_PATH).setFractionDigits(10).build();
+ final TypeDefinition<?> type = DerivedTypes.derivedTypeBuilder(base, ROOT_PATH).build();
- Optional<String> absent = Optional.absent();
- SchemaPath path = SchemaPath.create(true, QName.create("/root"));
-
- Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
- Decimal64.create(path, 10), absent, absent, path);
-
- ExtendedType extType = extTypeBuilder.build();
- Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(type);
assertNotNull(restrictions);
assertFalse(restrictions.isEmpty());
- assertEquals(((DecimalTypeDefinition) extType.getBaseType()).getRangeConstraints(),
- restrictions.getRangeConstraints());
+ assertEquals(base.getRangeConstraints(), restrictions.getRangeConstraints());
assertTrue(restrictions.getLengthConstraints().isEmpty());
assertTrue(restrictions.getPatternConstraints().isEmpty());
-
}
-
}
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
-
-import com.google.common.base.Optional;
-import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.util.EnumerationType;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
public class EnumerationBuilderImplTest {
@Test
public void testUpdateEnumPairsFromEnumTypeDef() {
- EnumTypeDefinition.EnumPair enumPair = EnumPairImpl.create(qName);
- EnumTypeDefinition enumTypeDefinition = EnumerationType.create(SchemaPath.SAME,
- Arrays.asList(enumPair), Optional.of(enumPair));
+ EnumTypeDefinition enumTypeDefinition = BaseTypes.enumerationTypeBuilder(SchemaPath.SAME)
+ .addEnum(EnumPairImpl.create(qName)).build();
enumerationBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDefinition);
}
private final String name;
private final Integer value;
- private EnumPairImpl(QName qName) {
+ private EnumPairImpl(final QName qName) {
qname = qName;
path = SchemaPath.SAME;
description = "Some Other Description";
value = 45;
}
- public static EnumPairImpl create(QName qName) {
+ public static EnumPairImpl create(final QName qName) {
return new EnumPairImpl(qName);
}