bin
xtend-gen
target
+.DS_Store
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../common/parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>benchmarks</artifactId>
<properties>
- <yangtools.version>0.6.2-SNAPSHOT</yangtools.version>
- <yang.maven.plugin.version>0.6.2-SNAPSHOT</yang.maven.plugin.version>
+ <yangtools.version>0.7.0-SNAPSHOT</yangtools.version>
+ <yang.maven.plugin.version>0.7.0-SNAPSHOT</yang.maven.plugin.version>
<java.source.version>1.7</java.source.version>
<java.target.version>1.7</java.target.version>
<jmh.version>0.9.7</jmh.version>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
import org.opendaylight.yangtools.concepts.Codec;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.sal.binding.generator.util.BindingRuntimeContext;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.util.ClassLoaderUtils;
import org.opendaylight.yangtools.yang.binding.BaseIdentity;
import org.opendaylight.yangtools.yang.binding.BindingMapping;
import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
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;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
} catch (Exception e) {
throw new IllegalStateException("Unable to load codec for " + valueType, e);
}
+ } else if(rootType instanceof LeafrefTypeDefinition) {
+ Entry<GeneratedType, Object> typeWithSchema = context.getTypeWithSchema(valueType);
+ Object schema = typeWithSchema.getValue();
+ Preconditions.checkState(schema instanceof TypeDefinition<?>);
+ return getCodec(valueType, (TypeDefinition<?>) schema);
}
return ValueTypeCodec.getCodecFor(valueType, instantiatedType);
}
Map<Class<?>, DataContainerCodecPrototype<?>> byCaseChildClassBuilder = new HashMap<>();
Set<Class<?>> potentialSubstitutions = new HashSet<>();
// Walks all cases for supplied choice in current runtime context
- for (Class<?> caze : factory().getRuntimeContext().getCases(bindingClass())) {
+ for (Class caze : factory().getRuntimeContext().getCases(bindingClass())) {
// We try to load case using exact match thus name
// and original schema must equals
DataContainerCodecPrototype<ChoiceCaseNode> cazeDef = loadCase(caze);
if (cazeDef != null) {
byClassBuilder.put(cazeDef.getBindingClass(), cazeDef);
// Updates collection of case children
- for (Class<? extends DataObject> cazeChild : BindingReflections.getChildrenClasses((Class) caze)) {
+ for (Class<? extends DataObject> cazeChild : BindingReflections.getChildrenClasses((Class<? extends DataObject>) caze)) {
byCaseChildClassBuilder.put(cazeChild, cazeDef);
}
// Updates collection of YANG instance identifier to case
return byCaseChildClass.get(type).get();
}
-}
\ No newline at end of file
+}
--- /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.binding.data.codec.test;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Map.Entry;
+import javassist.ClassPool;
+import org.junit.Test;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.augment.rev140709.ThirdParty;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.augment.rev140709.TreeComplexLeaves;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.augment.rev140709.TreeComplexLeavesBuilder;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.binding.rev140701.Int32StringUnion;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.binding.rev140701.Top;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.binding.rev140701.two.level.list.TopLevelList;
+import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.binding.rev140701.two.level.list.TopLevelListKey;
+import org.opendaylight.yangtools.binding.data.codec.gen.impl.StreamWriterGenerator;
+import org.opendaylight.yangtools.binding.data.codec.impl.BindingNormalizedNodeCodecRegistry;
+import org.opendaylight.yangtools.sal.binding.generator.util.JavassistUtils;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+
+
+public class LeafReferenceTest extends AbstractBindingRuntimeTest {
+
+ private static final TopLevelListKey TOP_FOO_KEY = new TopLevelListKey("foo");
+ private static final InstanceIdentifier<TreeComplexLeaves> BA_TOP_LEVEL_LIST = InstanceIdentifier.builder(Top.class)
+ .child(TopLevelList.class, TOP_FOO_KEY).augmentation(TreeComplexLeaves.class).toInstance();
+
+ private BindingNormalizedNodeCodecRegistry registry;
+
+ @Override
+ public void setup() {
+ super.setup();
+ JavassistUtils utils = JavassistUtils.forClassPool(ClassPool.getDefault());
+ registry = new BindingNormalizedNodeCodecRegistry(StreamWriterGenerator.create(utils));
+ registry.onBindingRuntimeContextUpdated(getRuntimeContext());
+ }
+
+ @Test
+ public void testCaseWithLeafReferencesType() {
+ TreeComplexLeaves binding = new TreeComplexLeavesBuilder()
+ .setIdentity(ThirdParty.class)
+ .setIdentityRef(ThirdParty.class)
+ .setSimpleType(10)
+ .setSimpleTypeRef(10)
+ .setSchemaUnawareUnion(new Int32StringUnion("foo"))
+ .setSchemaUnawareUnionRef(new Int32StringUnion(10))
+ .build();
+ Entry<YangInstanceIdentifier, NormalizedNode<?, ?>> dom = registry.toNormalizedNode(BA_TOP_LEVEL_LIST, binding);
+ Entry<InstanceIdentifier<?>, DataObject> readed = registry.fromNormalizedNode(dom.getKey(),dom.getValue());
+ TreeComplexLeaves readedAugment = ((TreeComplexLeaves) readed.getValue());
+
+ assertEquals(binding,readedAugment);
+
+ }
+
+
+
+}
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findNodeInSchemaContext;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
-
import com.google.common.base.Splitter;
import com.google.common.collect.Iterables;
import com.google.common.collect.Sets;
final Type type = ((TypeProviderImpl) typeProvider).generatedTypeForExtendedDefinitionType(typedef,
typedef);
if (type != null) {
- genCtx.get(module).addTypedefType(typedef.getPath(), type);
+ final ModuleContext ctx = genCtx.get(module);
+ ctx.addTypedefType(typedef.getPath(), type);
+ ctx.addTypeToSchema(type,typedef);
}
}
}
genCtx.get(module).addChoiceToCaseMapping(refChoiceType, caseTypeBuilder, caseNode);
final Iterable<DataSchemaNode> caseChildNodes = caseNode.getChildNodes();
if (caseChildNodes != null) {
- Object parentNode = null;
final SchemaPath nodeSp = choiceNode.getPath();
- parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
+ final Object parentNode = findDataSchemaNode(schemaContext, nodeSp.getParent());
SchemaNode parent;
if (parentNode instanceof AugmentationSchema) {
final SchemaPath sp = choiceNode.getPath();
parent = findDataSchemaNode(schemaContext, sp.getParent());
}
- GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
- if (childOfType == null) {
- childOfType = findGroupingByPath(parent.getPath());
+ if (parent != null) {
+ GeneratedTypeBuilder childOfType = findChildNodeByPath(parent.getPath());
+ if (childOfType == null) {
+ childOfType = findGroupingByPath(parent.getPath());
+ }
+ resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
}
- resolveDataSchemaNodes(module, basePackageName, caseTypeBuilder, childOfType, caseChildNodes);
}
}
-
processUsesAugments(caseNode, module);
}
}
}
final GeneratedPropertyBuilder genPropBuilder = resultTOBuilder.addProperty("value");
- genPropBuilder.setReturnType(Types.primitiveType("char[]", null));
+ genPropBuilder.setReturnType(Types.CHAR_ARRAY);
resultTOBuilder.addEqualsIdentity(genPropBuilder);
resultTOBuilder.addHashIdentity(genPropBuilder);
resultTOBuilder.addToStringProperty(genPropBuilder);
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
public final class ModuleContext {
private GeneratedTypeBuilder moduleNode;
return Collections.unmodifiableMap(typeToSchema);
}
+ protected void addTypeToSchema(Type type, TypeDefinition<?> typedef) {
+ typeToSchema.put(type, typedef);
+ }
+
}
]
method(Object, "fromDomValue", Object) [
modifiers = PUBLIC + FINAL + STATIC
- val sortedBits = typeDef.bits.sort[o1, o2|o1.propertyName.compareTo(o2.propertyName)]
+ val sortedBits = IterableExtensions.sort(typeDef.bits, [o1, o2|o1.propertyName.compareTo(o2.propertyName)])
val body = '''
{
//System.out.println("«inputType.simpleName»#fromDomValue: "+$1);
+/*
+ * 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.generator.util;
import com.google.common.base.Optional;
import com.google.common.collect.HashMultimap;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Multimap;
-
import java.util.AbstractMap;
import java.util.AbstractMap.SimpleEntry;
import java.util.Collection;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
-
import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
import org.opendaylight.yangtools.concepts.Immutable;
import org.opendaylight.yangtools.sal.binding.generator.api.ClassLoadingStrategy;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.util.SchemaNodeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
for (ModuleContext ctx : modules.values()) {
augmentationToSchema.putAll(ctx.getTypeToAugmentation());
typeToDefiningSchema.putAll(ctx.getTypeToSchema());
+
+ ctx.getTypedefs();
augmentableToAugmentations.putAll(ctx.getAugmentableToAugmentations());
choiceToCases.putAll(ctx.getChoiceToCases());
identities.putAll(ctx.getIdentities());
return new ReferencedTypeImpl(type.getPackage().getName(), type.getSimpleName());
}
+ /**
+ * Returns schema ({@link DataSchemaNode}, {@link AugmentationSchema} or {@link TypeDefinition})
+ * from which supplied class was generated. Returned schema may be augmented with
+ * additional information, which was not available at compile type
+ * (e.g. third party augmentations).
+ *
+ * @param type Binding Class for which schema should be retrieved.
+ * @return Instance of generated type (definition of Java API), along with
+ * {@link DataSchemaNode}, {@link AugmentationSchema} or {@link TypeDefinition}
+ * which was used to generate supplied class.
+ */
public Entry<GeneratedType, Object> getTypeWithSchema(final Class<?> type) {
Object schema = typeToDefiningSchema.get(referencedType(type));
Type definedType = typeToDefiningSchema.inverse().get(schema);
Preconditions.checkNotNull(schema);
Preconditions.checkNotNull(definedType);
+ if(definedType instanceof GeneratedTypeBuilder) {
+ return new SimpleEntry<>(((GeneratedTypeBuilder) definedType).toInstance(), schema);
+ }
+ Preconditions.checkArgument(definedType instanceof GeneratedType,"Type {} is not GeneratedType",type);
+ return new SimpleEntry<>((GeneratedType) definedType,schema);
- return new SimpleEntry<>(((GeneratedTypeBuilder) definedType).toInstance(), schema);
}
public ImmutableMap<Type, Entry<Type, Type>> getChoiceCaseChildren(final DataNodeContainer schema) {
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
*/
package org.opendaylight.yangtools.binding.generator.util;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.cache.CacheLoader;
+import com.google.common.cache.LoadingCache;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import org.opendaylight.yangtools.yang.binding.Augmentation;
public final class Types {
+ private static final CacheLoader<Class<?>, ConcreteType> TYPE_LOADER =
+ new CacheLoader<Class<?>, ConcreteType>() {
+ @Override
+ public ConcreteType load(final Class<?> key) {
+ return new ConcreteTypeImpl(key.getPackage().getName(), key.getSimpleName(), null);
+ }
+ };
+ private static final LoadingCache<Class<?>, ConcreteType> TYPE_CACHE =
+ CacheBuilder.newBuilder().weakKeys().softValues().build(TYPE_LOADER);
+
private static final Type SET_TYPE = typeForClass(Set.class);
private static final Type LIST_TYPE = typeForClass(List.class);
private static final Type MAP_TYPE = typeForClass(Map.class);
public static final ConcreteType FUTURE = typeForClass(Future.class);
public static final ConcreteType STRING = typeForClass(String.class);
public static final ConcreteType VOID = typeForClass(Void.class);
+ public static final ConcreteType BYTE_ARRAY = primitiveType("byte[]", null);
+ public static final ConcreteType CHAR_ARRAY = primitiveType("char[]", null);
/**
* It is not desirable to create instance of this class
* doesn't exist.
*
* @param primitiveType
- * string containing programaticall construction based on
+ * string containing programmatic construction based on
* primitive type (e.g byte[])
- * @return <code>ConcreteType</code> instance which represents programatic
+ * @return <code>ConcreteType</code> instance which represents programmatic
* construction with primitive JAVA type
*/
- public static Type primitiveType(final String primitiveType, final Restrictions restrictions) {
+ public static ConcreteType primitiveType(final String primitiveType, final Restrictions restrictions) {
return new ConcreteTypeImpl("", primitiveType, restrictions);
}
* Class to describe
* @return Description of class
*/
- public static ConcreteType typeForClass(Class<?> cls) {
- return typeForClass(cls, null);
+ public static ConcreteType typeForClass(final Class<?> cls) {
+ return TYPE_CACHE.getUnchecked(cls);
}
- public static ConcreteType typeForClass(Class<?> cls, Restrictions restrictions) {
- return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions);
+ public static ConcreteType typeForClass(final Class<?> cls, final Restrictions restrictions) {
+ if (restrictions != null) {
+ return new ConcreteTypeImpl(cls.getPackage().getName(), cls.getSimpleName(), restrictions);
+ } else {
+ return typeForClass(cls);
+ }
}
/**
* Value Type
* @return Description of generic type instance
*/
- public static ParameterizedType mapTypeFor(Type keyType, Type valueType) {
+ public static ParameterizedType mapTypeFor(final Type keyType, final Type valueType) {
return parameterizedTypeFor(MAP_TYPE, keyType, valueType);
}
* Value Type
* @return Description of generic type instance of Set
*/
- public static ParameterizedType setTypeFor(Type valueType) {
+ public static ParameterizedType setTypeFor(final Type valueType) {
return parameterizedTypeFor(SET_TYPE, valueType);
}
* Value Type
* @return Description of type instance of List
*/
- public static ParameterizedType listTypeFor(Type valueType) {
+ public static ParameterizedType listTypeFor(final Type valueType) {
return parameterizedTypeFor(LIST_TYPE, valueType);
}
* @return <code>ParametrizedType</code> reprezentation of <code>type</code>
* and its parameters <code>parameters</code>
*/
- public static ParameterizedType parameterizedTypeFor(Type type, Type... parameters) {
+ public static ParameterizedType parameterizedTypeFor(final Type type, final Type... parameters) {
return new ParametrizedTypeImpl(type, parameters);
}
* string with the package name
* @param typeName
* string with the type name
- * @return <code>WildcardType</code> reprezentation of
+ * @return <code>WildcardType</code> representation of
* <code>packageName</code> and <code>typeName</code>
*/
- public static WildcardType wildcardTypeFor(String packageName, String typeName) {
+ public static WildcardType wildcardTypeFor(final String packageName, final String typeName) {
return new WildcardTypeImpl(packageName, typeName);
}
*
* @param valueType
* JAVA <code>Type</code> with actual parameter
- * @return <code>ParametrizedType</code> reprezentation of raw type
+ * @return <code>ParametrizedType</code> representation of raw type
* <code>Augmentable</code> with actual parameter
* <code>valueType</code>
*/
- public static ParameterizedType augmentableTypeFor(Type valueType) {
+ public static ParameterizedType augmentableTypeFor(final Type valueType) {
final Type augmentable = typeForClass(Augmentable.class);
return parameterizedTypeFor(augmentable, valueType);
}
* <code>Augmentation</code> with actual parameter
* <code>valueType</code>
*/
- public static ParameterizedType augmentationTypeFor(Type valueType) {
+ public static ParameterizedType augmentationTypeFor(final Type valueType) {
final Type augmentation = typeForClass(Augmentation.class);
return parameterizedTypeFor(augmentation, valueType);
}
* @param name
* string with the name of the type
*/
- private ConcreteTypeImpl(String pkName, String name, Restrictions restrictions) {
+ private ConcreteTypeImpl(final String pkName, final String name, final Restrictions restrictions) {
super(pkName, name);
this.restrictions = restrictions;
}
/**
* Array of JAVA actual type parameters.
*/
- private Type[] actualTypes;
+ private final Type[] actualTypes;
/**
* JAVA raw type (like List, Set, Map...)
*/
- private Type rawType;
+ private final Type rawType;
@Override
public Type[] getActualTypeArguments() {
* @param actTypes
* array of actual parameters
*/
- public ParametrizedTypeImpl(Type rawType, Type[] actTypes) {
+ public ParametrizedTypeImpl(final Type rawType, final Type[] actTypes) {
super(rawType.getPackageName(), rawType.getName());
this.rawType = rawType;
this.actualTypes = Arrays.copyOf(actTypes, actTypes.length);
* @param typeName
* string with the name of type
*/
- public WildcardTypeImpl(String packageName, String typeName) {
+ public WildcardTypeImpl(final String packageName, final String typeName) {
super(packageName, typeName);
}
}
Preconditions.checkArgument(name != null, "Name for Enclosing Generated Transfer Object cannot be null!");
GeneratedTOBuilder builder = new GeneratedTOBuilderImpl(getFullyQualifiedName(), name);
+ Preconditions.checkArgument(!enclosedTransferObjects.contains(builder), "This generated type already contains equal enclosing transfer object.");
enclosedTransferObjects = LazyCollections.lazyAdd(enclosedTransferObjects, builder);
return builder;
}
@Override
public T addEnclosingTransferObject(final GeneratedTOBuilder genTOBuilder) {
Preconditions.checkArgument(genTOBuilder != null, "Parameter genTOBuilder cannot be null!");
+ Preconditions.checkArgument(!enclosedTransferObjects.contains(genTOBuilder), "This generated type already contains equal enclosing transfer object.");
enclosedTransferObjects = LazyCollections.lazyAdd(enclosedTransferObjects, genTOBuilder);
return thisInstance();
}
Preconditions.checkArgument(name != null, "Name of Annotation Type cannot be null!");
final AnnotationTypeBuilder builder = new AnnotationTypeBuilderImpl(packageName, name);
+
+ Preconditions.checkArgument(!annotationBuilders.contains(builder), "This generated type already contains equal annotation.");
annotationBuilders = LazyCollections.lazyAdd(annotationBuilders, builder);
return builder;
}
@Override
public T addImplementsType(final Type genType) {
Preconditions.checkArgument(genType != null, "Type cannot be null");
+ Preconditions.checkArgument(!implementsTypes.contains(genType), "This generated type already contains equal implements type.");
implementsTypes = LazyCollections.lazyAdd(implementsTypes, genType);
return thisInstance();
}
public Constant addConstant(final Type type, final String name, final Object value) {
Preconditions.checkArgument(type != null, "Returning Type for Constant cannot be null!");
Preconditions.checkArgument(name != null, "Name of constant cannot be null!");
+ Preconditions.checkArgument(!containsConstant(name), "This generated type already contains constant with the same name.");
final Constant constant = new ConstantImpl(this, type, name, value);
constants = LazyCollections.lazyAdd(constants, constant);
return constant;
}
+ public boolean containsConstant(final String name) {
+ Preconditions.checkArgument(name != null, "Parameter name can't be null");
+ for (Constant constant : constants) {
+ if (name.equals(constant.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
@Override
public EnumBuilder addEnumeration(final String name) {
Preconditions.checkArgument(name != null, "Name of enumeration cannot be null!");
final EnumBuilder builder = new EnumerationBuilderImpl(getFullyQualifiedName(), name);
+
+ Preconditions.checkArgument(!enumDefinitions.contains(builder), "This generated type already contains equal enumeration.");
enumDefinitions = LazyCollections.lazyAdd(enumDefinitions, builder);
return builder;
}
@Override
public GeneratedPropertyBuilder addProperty(final String name) {
+ Preconditions.checkArgument(name != null, "Parameter name can't be null");
+ Preconditions.checkArgument(!containsProperty(name), "This generated type already contains property with the same name.");
+
final GeneratedPropertyBuilder builder = new GeneratedPropertyBuilderImpl(name);
builder.setAccessModifier(AccessModifier.PUBLIC);
properties = LazyCollections.lazyAdd(properties, builder);
if (getClass() != obj.getClass()) {
return false;
}
- MethodSignatureBuilderImpl other = (MethodSignatureBuilderImpl) obj;
+ AbstractTypeMemberBuilder<?> other = (AbstractTypeMemberBuilder<?>) obj;
if (getName() == null) {
if (other.getName() != null) {
return false;
*/
package org.opendaylight.yangtools.binding.generator.util;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
+import static org.junit.Assert.*;
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 java.util.Set;
+
+import com.google.common.base.Optional;
+
import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTypeBuilderImpl;
+import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
+import org.opendaylight.yangtools.sal.binding.model.api.Restrictions;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
import org.opendaylight.yangtools.yang.binding.BindingMapping;
+import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
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.parser.api.YangContextParser;
+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.Int16;
+import org.opendaylight.yangtools.yang.model.util.StringType;
+import org.opendaylight.yangtools.yang.model.util.Uint16;
import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
BindingGeneratorUtil.parseToValidParamName(" 0some-testing_parameter name "));
}
+ @Test
+ public void computeDefaultSUIDTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ MethodSignatureBuilder method = generatedTypeBuilder.addMethod("myMethodName");
+ method.setAccessModifier(AccessModifier.PUBLIC);
+ generatedTypeBuilder.addProperty("myProperty");
+ generatedTypeBuilder.addImplementsType(Types.typeForClass(Serializable.class));
+
+ assertEquals(6788238694991761868L, BindingGeneratorUtil.computeDefaultSUID(generatedTypeBuilder));
+
+ }
+
+ @Test
+ public void getRestrictionsTest() {
+
+ Optional<String> absent = Optional.absent();
+
+ Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
+ Int16.getInstance(), 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>();
+
+ 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());
+
+ assertNotNull(restrictions);
+
+ assertEquals(1, restrictions.getLengthConstraints().size());
+ assertEquals(1, 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"),
+ StringType.getInstance(), absent, absent, SchemaPath.create(true, QName.create("/root")));
+
+ Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extTypeBuilder.build());
+
+ assertNotNull(restrictions);
+ assertTrue(restrictions.isEmpty());
+
+ }
+
+ @Test
+ public void getDefaultIntegerRestrictionsTest() {
+
+ Optional<String> absent = Optional.absent();
+
+ Builder extTypeBuilder = ExtendedType.builder(new QName(URI.create("namespace"), "localName"),
+ Int16.getInstance(), absent, absent, SchemaPath.create(true, QName.create("/root")));
+
+ ExtendedType extType = extTypeBuilder.build();
+ Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+
+ assertNotNull(restrictions);
+ assertFalse(restrictions.isEmpty());
+ assertEquals(((IntegerTypeDefinition) extType.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"),
+ Uint16.getInstance(), absent, absent, SchemaPath.create(true, QName.create("/root")));
+
+ ExtendedType extType = extTypeBuilder.build();
+ Restrictions restrictions = BindingGeneratorUtil.getRestrictions(extType);
+
+ assertNotNull(restrictions);
+ assertFalse(restrictions.isEmpty());
+ assertEquals(((UnsignedIntegerTypeDefinition) extType.getBaseType()).getRangeConstraints(),
+ restrictions.getRangeConstraints());
+ assertTrue(restrictions.getLengthConstraints().isEmpty());
+ assertTrue(restrictions.getPatternConstraints().isEmpty());
+ }
+
+ @Test
+ public void getDefaultDecimalRestrictionsTest() {
+
+ 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);
+
+ assertNotNull(restrictions);
+ assertFalse(restrictions.isEmpty());
+ assertEquals(((DecimalTypeDefinition) extType.getBaseType()).getRangeConstraints(),
+ restrictions.getRangeConstraints());
+ assertTrue(restrictions.getLengthConstraints().isEmpty());
+ assertTrue(restrictions.getPatternConstraints().isEmpty());
+
+ }
+
}
--- /dev/null
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import java.io.Serializable;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.Types;
+
+public class AbstractGeneratedTypeBuilderTest {
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addPropertyIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addProperty(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addPropertyIllegalArgumentTest2() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addProperty("myName");
+ generatedTypeBuilder.addProperty("myName");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addEnclosingTransferObjectArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addEnclosingTransferObject(new GeneratedTOBuilderImpl("my.package", "myName"));
+ generatedTypeBuilder.addEnclosingTransferObject(new GeneratedTOBuilderImpl("my.package", "myName"));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addEnclosingTransferObjectArgumentTest2() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addEnclosingTransferObject("myName");
+ generatedTypeBuilder.addEnclosingTransferObject("myName");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addImplementsTypeIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addImplementsType(Types.typeForClass(Serializable.class));
+ generatedTypeBuilder.addImplementsType(Types.typeForClass(Serializable.class));
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addConstantIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addConstant(Types.STRING, "myName", "Value");
+ generatedTypeBuilder.addConstant(Types.BOOLEAN, "myName", true);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addAnnotationIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addAnnotation("my.package", "myName");
+ generatedTypeBuilder.addAnnotation("my.package", "myName");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addEnumerationIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addEnumeration("myName");
+ generatedTypeBuilder.addEnumeration("myName");
+ }
+
+}
*/
package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.opendaylight.yangtools.binding.generator.util.Types;
import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
+import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType.Parameter;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
import org.opendaylight.yangtools.sal.binding.model.api.type.builder.AnnotationTypeBuilder;
@Test
public void generatedTypeAnnotationTest() {
- final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl(
- "org.opendaylight.controller", "AnnotInterface");
+ final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl("org.opendaylight.controller",
+ "AnnotInterface");
genTypeBuilder.addAnnotation("javax.management", "MXBean");
- final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation(
- "javax.management", "Description");
+ final AnnotationTypeBuilder annotDesc = genTypeBuilder.addAnnotation("javax.management", "Description");
annotDesc.addParameter("description", "some sort of interface");
final GeneratedType genType = genTypeBuilder.toInstance();
int annotCount = 0;
for (final AnnotationType annotation : genType.getAnnotations()) {
- if (annotation.getPackageName().equals("javax.management")
- && annotation.getName().equals("MXBean")) {
+ if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("MXBean")) {
annotCount++;
assertEquals(0, annotation.getParameters().size());
}
- if (annotation.getPackageName().equals("javax.management")
- && annotation.getName().equals("Description")) {
+ if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("Description")) {
annotCount++;
assertEquals(1, annotation.getParameters().size());
- AnnotationType.Parameter param = annotation
- .getParameter("description");
+ AnnotationType.Parameter param = annotation.getParameter("description");
assertNotNull(param);
assertEquals("description", param.getName());
assertNotNull(param.getValue());
@Test
public void methodSignatureAnnotationTest() {
- final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl(
- "org.opendaylight.controller", "TransferObject");
+ final GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl("org.opendaylight.controller",
+ "TransferObject");
- final MethodSignatureBuilder methodBuilder = genTypeBuilder
- .addMethod("simpleMethod");
+ final MethodSignatureBuilder methodBuilder = genTypeBuilder.addMethod("simpleMethod");
methodBuilder.setReturnType(Types.typeForClass(Integer.class));
- final AnnotationTypeBuilder annotManAttr = methodBuilder
- .addAnnotation("org.springframework.jmx.export.annotation",
- "ManagedAttribute");
+ final AnnotationTypeBuilder annotManAttr = methodBuilder.addAnnotation(
+ "org.springframework.jmx.export.annotation", "ManagedAttribute");
annotManAttr.addParameter("description", "\"The Name Attribute\"");
annotManAttr.addParameter("currencyTimeLimit", "20");
annotManAttr.addParameter("defaultValue", "\"bar\"");
annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
- final AnnotationTypeBuilder annotManProp = methodBuilder
- .addAnnotation("org.springframework.jmx.export.annotation",
- "ManagedOperation");
+ final AnnotationTypeBuilder annotManProp = methodBuilder.addAnnotation(
+ "org.springframework.jmx.export.annotation", "ManagedOperation");
final List<String> typeValues = new ArrayList<String>();
typeValues.add("\"val1\"");
assertNotNull(genType.getMethodDefinitions());
assertNotNull(genType.getMethodDefinitions().get(0));
assertNotNull(genType.getMethodDefinitions().get(0).getAnnotations());
- final List<AnnotationType> annotations = genType.getMethodDefinitions()
- .get(0).getAnnotations();
+ final List<AnnotationType> annotations = genType.getMethodDefinitions().get(0).getAnnotations();
assertEquals(2, annotations.size());
int annotCount = 0;
@Test
public void generatedPropertyAnnotationTest() {
- final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl(
- "org.opendaylight.controller", "AnnotInterface");
+ final GeneratedTOBuilder genTOBuilder = new GeneratedTOBuilderImpl("org.opendaylight.controller",
+ "AnnotInterface");
- final GeneratedPropertyBuilder propertyBuilder = genTOBuilder
- .addProperty("simpleProperty");
+ final GeneratedPropertyBuilder propertyBuilder = genTOBuilder.addProperty("simpleProperty");
propertyBuilder.setReturnType(Types.typeForClass(Integer.class));
- final AnnotationTypeBuilder annotManAttr = propertyBuilder
- .addAnnotation("org.springframework.jmx.export.annotation",
- "ManagedAttribute");
+ final AnnotationTypeBuilder annotManAttr = propertyBuilder.addAnnotation(
+ "org.springframework.jmx.export.annotation", "ManagedAttribute");
annotManAttr.addParameter("description", "\"The Name Attribute\"");
annotManAttr.addParameter("currencyTimeLimit", "20");
annotManAttr.addParameter("defaultValue", "\"bar\"");
annotManAttr.addParameter("persistPolicy", "\"OnUpdate\"");
- final AnnotationTypeBuilder annotManProp = propertyBuilder
- .addAnnotation("org.springframework.jmx.export.annotation",
- "ManagedOperation");
+ final AnnotationTypeBuilder annotManProp = propertyBuilder.addAnnotation(
+ "org.springframework.jmx.export.annotation", "ManagedOperation");
final List<String> typeValues = new ArrayList<String>();
typeValues.add("\"val1\"");
assertNotNull(genTransObj.getProperties());
assertNotNull(genTransObj.getProperties().get(0));
assertNotNull(genTransObj.getProperties().get(0).getAnnotations());
- final List<AnnotationType> annotations = genTransObj.getProperties()
- .get(0).getAnnotations();
+ final List<AnnotationType> annotations = genTransObj.getProperties().get(0).getAnnotations();
assertEquals(2, annotations.size());
int annotCount = 0;
@Test
public void generatedTransfeObjectAnnotationTest() {
- final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
- "org.opendaylight.controller", "AnnotClassCache");
+ final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl("org.opendaylight.controller",
+ "AnnotClassCache");
genTypeBuilder.addAnnotation("javax.management", "MBean");
- final AnnotationTypeBuilder annotNotify = genTypeBuilder.addAnnotation(
- "javax.management", "NotificationInfo");
+ final AnnotationTypeBuilder annotNotify = genTypeBuilder.addAnnotation("javax.management", "NotificationInfo");
final List<String> notifyList = new ArrayList<String>();
notifyList.add("\"my.notif.type\"");
annotNotify.addParameters("types", notifyList);
- annotNotify.addParameter("description",
- "@Description(\"my notification\")");
+ annotNotify.addParameter("description", "@Description(\"my notification\")");
GeneratedTransferObject genTO = genTypeBuilder.toInstance();
int annotCount = 0;
for (final AnnotationType annotation : genTO.getAnnotations()) {
- if (annotation.getPackageName().equals("javax.management")
- && annotation.getName().equals("MBean")) {
+ if (annotation.getPackageName().equals("javax.management") && annotation.getName().equals("MBean")) {
annotCount++;
assertEquals(0, annotation.getParameters().size());
}
&& annotation.getName().equals("NotificationInfo")) {
annotCount++;
assertEquals(2, annotation.getParameters().size());
- AnnotationType.Parameter param = annotation
- .getParameter("types");
+ AnnotationType.Parameter param = annotation.getParameter("types");
assertNotNull(param);
assertEquals("types", param.getName());
assertNull(param.getValue());
assertNotNull(param);
assertEquals("description", param.getName());
assertNotNull(param.getValue());
- assertEquals("@Description(\"my notification\")",
- param.getValue());
+ assertEquals("@Description(\"my notification\")", param.getValue());
}
}
assertEquals(2, annotCount);
}
+
+ @Test
+ public void annotationTypeBuilderAddAnnotationTest() {
+ AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
+
+ assertNull(annotationTypeBuilder.addAnnotation("my.package", null));
+ assertNull(annotationTypeBuilder.addAnnotation(null, "MyName"));
+
+ assertNotNull(annotationTypeBuilder.addAnnotation("", ""));
+
+ assertNotNull(annotationTypeBuilder.addAnnotation("my.package2", "MyName2"));
+ assertNull(annotationTypeBuilder.addAnnotation("my.package2", "MyName2"));
+
+ AnnotationType annotationTypeInstance = annotationTypeBuilder.toInstance();
+
+ assertEquals(2, annotationTypeInstance.getAnnotations().size());
+
+ assertEquals("my.package", annotationTypeInstance.getPackageName());
+ assertEquals("MyName", annotationTypeInstance.getName());
+
+ }
+
+ @Test
+ public void annotationTypeBuilderEqualsTest() {
+ AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
+ AnnotationTypeBuilder annotationTypeBuilder2 = new AnnotationTypeBuilderImpl("my.package2", "MyName");
+ AnnotationTypeBuilder annotationTypeBuilder3 = new AnnotationTypeBuilderImpl("my.package", "MyName2");
+ AnnotationTypeBuilder annotationTypeBuilder4 = new AnnotationTypeBuilderImpl("my.package", "MyName");
+
+ assertFalse(annotationTypeBuilder.equals(null));
+ assertFalse(annotationTypeBuilder.equals(new Object()));
+
+ assertTrue(annotationTypeBuilder.equals(annotationTypeBuilder));
+
+ assertTrue(annotationTypeBuilder.equals(annotationTypeBuilder4));
+ assertFalse(annotationTypeBuilder.equals(annotationTypeBuilder2));
+ assertFalse(annotationTypeBuilder.equals(annotationTypeBuilder3));
+
+ AnnotationType instance = annotationTypeBuilder.toInstance();
+ AnnotationType instance2 = annotationTypeBuilder2.toInstance();
+ AnnotationType instance3 = annotationTypeBuilder3.toInstance();
+ AnnotationType instance4 = annotationTypeBuilder4.toInstance();
+
+ assertFalse(instance.equals(null));
+ assertFalse(instance.equals(new Object()));
+ assertTrue(instance.equals(instance));
+
+ assertFalse(instance.equals(instance2));
+ assertFalse(instance.equals(instance3));
+ assertTrue(instance.equals(instance4));
+
+ annotationTypeBuilder.addParameter("myName", "myValue1");
+ annotationTypeBuilder.addParameter("myName2", "myValue2");
+ annotationTypeBuilder2.addParameter("myName", "myValue3");
+
+ instance = annotationTypeBuilder.toInstance();
+ instance2 = annotationTypeBuilder2.toInstance();
+
+ Parameter parameter = instance.getParameter("myName");
+ Parameter parameter2 = instance.getParameter("myName2");
+ Parameter parameter3 = instance2.getParameter("myName");
+
+ assertFalse(parameter.equals(null));
+ assertFalse(parameter.equals(new Object()));
+ assertTrue(parameter.equals(parameter));
+ assertTrue(parameter.equals(parameter3));
+ assertFalse(parameter.equals(parameter2));
+ }
+
+ @Test
+ public void annotationTypeBuilderHashCodeTest() {
+ AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
+ AnnotationTypeBuilder annotationTypeBuilder2 = new AnnotationTypeBuilderImpl("my.package2", "MyName");
+ AnnotationTypeBuilder annotationTypeBuilder3 = new AnnotationTypeBuilderImpl("my.package", "MyName2");
+ AnnotationTypeBuilder annotationTypeBuilder4 = new AnnotationTypeBuilderImpl("my.package", "MyName");
+
+ assertFalse(annotationTypeBuilder.hashCode() == annotationTypeBuilder2.hashCode());
+ assertFalse(annotationTypeBuilder.hashCode() == annotationTypeBuilder3.hashCode());
+
+ assertTrue(annotationTypeBuilder.hashCode() == annotationTypeBuilder4.hashCode());
+ assertTrue(annotationTypeBuilder.hashCode() == annotationTypeBuilder.hashCode());
+
+ AnnotationType instance = annotationTypeBuilder.toInstance();
+ AnnotationType instance2 = annotationTypeBuilder2.toInstance();
+ AnnotationType instance3 = annotationTypeBuilder3.toInstance();
+ AnnotationType instance4 = annotationTypeBuilder4.toInstance();
+
+ assertFalse(instance.hashCode() == instance2.hashCode());
+ assertFalse(instance.hashCode() == instance3.hashCode());
+
+ assertTrue(instance.hashCode() == instance4.hashCode());
+ assertTrue(instance.hashCode() == instance.hashCode());
+
+ annotationTypeBuilder.addParameter("myName", "myValue1");
+ annotationTypeBuilder.addParameter("myName2", "myValue2");
+ annotationTypeBuilder2.addParameter("myName", "myValue3");
+
+ instance = annotationTypeBuilder.toInstance();
+ instance2 = annotationTypeBuilder2.toInstance();
+
+ Parameter parameter = instance.getParameter("myName");
+ Parameter parameter2 = instance.getParameter("myName2");
+ Parameter parameter3 = instance2.getParameter("myName");
+
+ assertTrue(parameter.hashCode() == parameter.hashCode());
+ assertTrue(parameter.hashCode() == parameter3.hashCode());
+ assertFalse(parameter.hashCode() == parameter2.hashCode());
+
+ }
+
+ @Test
+ public void annotationTypeBuilderAddParameterTest() {
+ AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyName");
+
+ assertFalse(annotationTypeBuilder.addParameter(null, "myValue"));
+ assertFalse(annotationTypeBuilder.addParameter("myName", null));
+
+ assertFalse(annotationTypeBuilder.addParameters(null, new ArrayList<String>()));
+ assertFalse(annotationTypeBuilder.addParameters("myName", null));
+
+ assertTrue(annotationTypeBuilder.addParameter("myName", "myValue"));
+ assertFalse(annotationTypeBuilder.addParameter("myName", "myValue"));
+ assertFalse(annotationTypeBuilder.addParameters("myName", new ArrayList<String>()));
+
+ ArrayList<String> values = new ArrayList<String>();
+ values.add("myValue");
+ assertTrue(annotationTypeBuilder.addParameters("myName2", values));
+
+ AnnotationType annotationTypeInstance = annotationTypeBuilder.toInstance();
+ assertTrue(annotationTypeInstance.containsParameters());
+ assertEquals(2, annotationTypeInstance.getParameters().size());
+ assertEquals(2, annotationTypeInstance.getParameterNames().size());
+ assertTrue(annotationTypeInstance.getParameterNames().contains("myName"));
+ assertTrue(annotationTypeInstance.getParameterNames().contains("myName2"));
+ assertFalse(annotationTypeInstance.getParameterNames().contains("myName3"));
+
+ Parameter parameter = annotationTypeInstance.getParameter("myName");
+ Parameter parameter2 = annotationTypeInstance.getParameter("myName2");
+ Parameter parameter3 = annotationTypeInstance.getParameter("myName3");
+
+ assertNotNull(parameter);
+ assertNotNull(parameter2);
+ assertNull(parameter3);
+
+ assertEquals(parameter.getValue(), "myValue");
+ assertTrue(parameter.getValues().isEmpty());
+
+ assertEquals(1, parameter2.getValues().size());
+ assertTrue(parameter2.getValues().contains("myValue"));
+
+ }
+
+ @Test
+ public void annotationTypeBuilderToStringTest() {
+ AnnotationTypeBuilder annotationTypeBuilder = new AnnotationTypeBuilderImpl("my.package", "MyAnnotationName");
+ annotationTypeBuilder.addAnnotation("my.package", "MySubAnnotationName");
+ annotationTypeBuilder.addParameter("MyParameter", "myValue");
+
+ assertEquals(
+ "AnnotationTypeBuilder [packageName=my.package, name=MyAnnotationName, annotationBuilders=[AnnotationTypeBuilder [packageName=my.package, name=MySubAnnotationName, annotationBuilders=[], parameters=[]]], parameters=[ParameterImpl [name=MyParameter, value=myValue, values=[]]]]",
+ annotationTypeBuilder.toString());
+
+ AnnotationType annotationTypeInstance = annotationTypeBuilder.toInstance();
+
+ assertEquals("my.package.MyAnnotationName", annotationTypeInstance.getFullyQualifiedName());
+ assertEquals(
+ "AnnotationType [packageName=my.package, name=MyAnnotationName, annotations=[AnnotationType [packageName=my.package, name=MySubAnnotationName, annotations=[], parameters=[]]], parameters=[ParameterImpl [name=MyParameter, value=myValue, values=[]]]]",
+ annotationTypeInstance.toString());
+
+ }
+
}
--- /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.binding.generator.util.generated.type.builder;
+
+import com.google.common.base.Optional;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
+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.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.EnumerationType;
+
+import java.util.Collections;
+import java.util.Arrays;
+import java.util.List;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class EnumerationBuilderImplTest {
+
+ private EnumerationBuilderImpl enumerationBuilder;
+ private EnumerationBuilderImpl enumerationBuilderSame;
+ private EnumerationBuilderImpl enumerationBuilderOtherName;
+ private EnumerationBuilderImpl enumerationBuilderOtherPackage;
+ private final String DESCRIPTION = "Test description of Enum";
+ private final String packageName = "org.opendaylight.test";
+ private final String name = "TestName";
+ private final String moduleName = "TestModuleName";
+ private final String reference = "TestRef";
+ private final String valueName = "TestValue";
+ private final String valueDescription = "Value used for test";
+ private int value = 12;
+ private Enumeration enumeration;
+ private QName qName = QName.create("TestQName", "10-10-2014", "TestLocalQName");
+
+
+ @Before
+ public void setup() {
+ enumerationBuilder = new EnumerationBuilderImpl(packageName, name);
+ enumerationBuilder.setDescription(DESCRIPTION);
+ enumerationBuilder.setModuleName(moduleName);
+ enumerationBuilder.setReference(reference);
+ enumerationBuilder.setSchemaPath(Collections.singletonList(qName));
+ enumerationBuilder.addValue(valueName, value, valueDescription);
+ enumerationBuilder.addAnnotation(packageName, "TestAnnotation");
+ enumerationBuilderSame = new EnumerationBuilderImpl(packageName, name);
+ enumerationBuilderOtherName = new EnumerationBuilderImpl(packageName, "SomeOtherName");
+ enumerationBuilderOtherPackage = new EnumerationBuilderImpl("org.opendaylight.other", name);
+ enumeration = enumerationBuilder.toInstance(enumerationBuilder);
+ }
+
+ @Test
+ public void testAddNullAnnotation() {
+ assertNull(enumerationBuilder.addAnnotation(null, null));
+ assertNull(enumerationBuilder.addAnnotation(null, "test"));
+ assertNull(enumerationBuilder.addAnnotation(packageName, null));
+ }
+
+ @Test
+ public void testEnumerationBuilder() {
+ assertEquals(packageName + "." + name, enumerationBuilder.getFullyQualifiedName());
+ assertEquals(name , enumerationBuilder.getName());
+ assertEquals(packageName, enumerationBuilder.getPackageName());
+
+ assertNotEquals(enumerationBuilder, null);
+ assertEquals(enumerationBuilder, enumerationBuilder);
+ assertNotEquals(enumerationBuilder, "string");
+ assertNotEquals(enumerationBuilder, enumerationBuilderOtherName);
+ assertNotEquals(enumerationBuilder, enumerationBuilderOtherPackage);
+ assertEquals(enumerationBuilder,enumerationBuilderSame);
+ }
+
+ @Test
+ public void testEnumeration() {
+ assertEquals(name, enumeration.getName());
+ assertEquals(packageName, enumeration.getPackageName());
+ assertEquals(null, enumeration.getComment());
+ assertEquals(enumerationBuilder, enumeration.getParentType());
+ assertEquals(DESCRIPTION, enumeration.getDescription());
+ assertEquals(moduleName, enumeration.getModuleName());
+ assertEquals(packageName + '.' + name, enumeration.getFullyQualifiedName());
+ assertEquals(reference, enumeration.getReference());
+ assertEquals(Collections.singletonList(qName), enumeration.getSchemaPath());
+ assertEquals(Collections.EMPTY_LIST, enumeration.getEnclosedTypes());
+ assertEquals(Collections.EMPTY_LIST, enumeration.getEnumerations());
+ assertEquals(Collections.EMPTY_LIST, enumeration.getMethodDefinitions());
+ assertEquals(Collections.EMPTY_LIST, enumeration.getConstantDefinitions());
+ assertEquals(Collections.EMPTY_LIST, enumeration.getProperties());
+ assertEquals(Collections.EMPTY_LIST, enumeration.getImplements());
+ assertNotNull(enumeration.getValues());
+ assertNotNull(enumeration.getAnnotations());
+
+ assertFalse(enumeration.isAbstract());
+ assertNotEquals(enumeration, null);
+ assertEquals(enumeration, enumeration);
+ assertNotEquals(enumeration, "string");
+
+ Enumeration enumerationOtherPackage = enumerationBuilderOtherPackage.toInstance(enumerationBuilderOtherPackage);
+ assertNotEquals(enumeration, enumerationOtherPackage);
+
+ Enumeration enumerationOtherName = enumerationBuilderOtherName.toInstance(enumerationBuilderOtherName);
+ assertNotEquals(enumeration, enumerationOtherName);
+
+ enumerationBuilderSame.addValue(valueName, value, valueDescription);
+ Enumeration enumerationSame = enumerationBuilderSame.toInstance(enumerationBuilderSame);
+ assertEquals(enumeration, enumerationSame);
+
+ EnumerationBuilderImpl enumerationBuilderSame1 = new EnumerationBuilderImpl(packageName, name);
+ Enumeration enumerationSame1 = enumerationBuilderSame1.toInstance(enumerationBuilderSame1);
+ enumerationBuilderSame1.addValue(valueName, 14, valueDescription);
+ assertNotEquals(enumeration, enumerationSame1);
+ }
+
+ @Test
+ public void testEnumerationToString() {
+ String formattedString =
+ "public enum " + name + " {\n" +
+ "\t TestValue " + "(12 );\n" +
+ "}";
+ String s = "Enumeration [packageName="+packageName+", definingType="+packageName+"."+name+", name="+name+
+ ", values=[EnumPair [name=TestValue, value=12]]]";
+
+ assertEquals(s, enumeration.toString());
+ assertEquals(formattedString, enumeration.toFormattedString());
+
+ assertEquals("EnumerationBuilderImpl " +
+ "[packageName=org.opendaylight.test, name=TestName, " +
+ "values=[EnumPair [name=TestValue, value=12]]]",
+ enumerationBuilder.toString());
+ }
+
+ @Test
+ public void testUpdateEnumPairsFromEnumTypeDef() {
+ EnumTypeDefinition.EnumPair enumPair = EnumPairImpl.create(qName);
+ EnumTypeDefinition enumTypeDefinition = EnumerationType.create(SchemaPath.SAME,
+ Arrays.asList(enumPair), Optional.of(enumPair));
+ enumerationBuilder.updateEnumPairsFromEnumTypeDef(enumTypeDefinition);
+ }
+
+ /**
+ * Internal implementation of EnumPair.
+ */
+ private static class EnumPairImpl implements EnumTypeDefinition.EnumPair {
+ private QName qname;
+ private SchemaPath path;
+ private String description;
+ private String reference;
+ private Status status;
+ private final List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
+ private String name;
+ private Integer value;
+
+ private EnumPairImpl(QName qName) {
+ qname = qName;
+ path = SchemaPath.SAME;
+ description = "Some Other Description";
+ reference = "Some other reference";
+ status = Status.CURRENT;
+ name = "SomeName";
+ value = 45;
+ }
+
+ public static EnumPairImpl create(QName qName) {
+ return new EnumPairImpl(qName);
+ }
+
+ @Override
+ public QName getQName() {
+ return qname;
+ }
+
+ @Override
+ public SchemaPath getPath() {
+ return path;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public String getReference() {
+ return reference;
+ }
+
+ @Override
+ public Status getStatus() {
+ return status;
+ }
+
+ @Override
+ public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return unknownNodes;
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ @Override
+ public Integer getValue() {
+ return value;
+ }
+
+ @Override
+ public int hashCode() {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((qname == null) ? 0 : qname.hashCode());
+ result = prime * result + ((path == null) ? 0 : path.hashCode());
+ result = prime * result + ((unknownNodes == null) ? 0 : unknownNodes.hashCode());
+ result = prime * result + ((name == null) ? 0 : name.hashCode());
+ result = prime * result + ((value == null) ? 0 : value.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null) {
+ return false;
+ }
+ if (getClass() != obj.getClass()) {
+ return false;
+ }
+ EnumPairImpl other = (EnumPairImpl) obj;
+ if (qname == null) {
+ if (other.qname != null) {
+ return false;
+ }
+ } else if (!qname.equals(other.qname)) {
+ return false;
+ }
+ if (path == null) {
+ if (other.path != null) {
+ return false;
+ }
+ } else if (!path.equals(other.path)) {
+ return false;
+ }
+ if (unknownNodes == null) {
+ if (other.unknownNodes != null) {
+ return false;
+ }
+ } else if (!unknownNodes.equals(other.unknownNodes)) {
+ return false;
+ }
+ if (name == null) {
+ if (other.name != null) {
+ return false;
+ }
+ } else if (!name.equals(other.name)) {
+ return false;
+ }
+ if (value == null) {
+ if (other.value != null) {
+ return false;
+ }
+ } else if (!value.equals(other.value)) {
+ return false;
+ }
+ return true;
+ }
+
+ @Override
+ public String toString() {
+ return EnumTypeDefinition.EnumPair.class.getSimpleName() + "[name=" + name + ", value=" + value + "]";
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.Types;
+import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+
+public class GeneratedPropertyBuilderImplTest {
+
+ @Test
+ public void generatedPropertyBuilderImplTest() {
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl = new GeneratedPropertyBuilderImpl("myPropertyName");
+ generatedPropertyBuilderImpl.setValue("myValue");
+ generatedPropertyBuilderImpl.setReadOnly(false);
+ generatedPropertyBuilderImpl.setStatic(true);
+ generatedPropertyBuilderImpl.setComment(null);
+ generatedPropertyBuilderImpl.setFinal(true);
+ generatedPropertyBuilderImpl.setAccessModifier(AccessModifier.PUBLIC);
+ generatedPropertyBuilderImpl.setReturnType(Types.BOOLEAN);
+
+ assertEquals(
+ "GeneratedPropertyImpl [name=myPropertyName, annotations=[], comment=null, returnType=Type (java.lang.Boolean), isFinal=true, isReadOnly=false, modifier=PUBLIC]",
+ generatedPropertyBuilderImpl.toString());
+
+ GeneratedProperty instance = generatedPropertyBuilderImpl.toInstance(null);
+
+ assertNotNull(instance);
+
+ assertTrue(instance.isFinal());
+ assertTrue(instance.isStatic());
+ assertFalse(instance.isReadOnly());
+ assertEquals("myValue", instance.getValue());
+ assertEquals(null, instance.getComment());
+ assertEquals(AccessModifier.PUBLIC, instance.getAccessModifier());
+ assertEquals(Types.BOOLEAN, instance.getReturnType());
+
+ }
+
+ @Test
+ public void generatedPropertyBuilderImplEqualsAndHashCodeTest() {
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl = new GeneratedPropertyBuilderImpl("myPropertyName");
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl2 = new GeneratedPropertyBuilderImpl("myPropertyName");
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl3 = new GeneratedPropertyBuilderImpl("myPropertyName3");
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl4 = new GeneratedPropertyBuilderImpl("myPropertyName");
+
+ assertNotNull(generatedPropertyBuilderImpl);
+ assertNotNull(generatedPropertyBuilderImpl2);
+ assertNotNull(generatedPropertyBuilderImpl3);
+ assertNotNull(generatedPropertyBuilderImpl4);
+
+ generatedPropertyBuilderImpl.setReturnType(Types.BOOLEAN);
+ generatedPropertyBuilderImpl2.setReturnType(Types.BOOLEAN);
+ generatedPropertyBuilderImpl3.setReturnType(Types.BOOLEAN);
+ generatedPropertyBuilderImpl4.setReturnType(Types.STRING);
+
+ assertFalse(generatedPropertyBuilderImpl.equals(null));
+ assertFalse(generatedPropertyBuilderImpl.equals(new Object()));
+ assertTrue(generatedPropertyBuilderImpl.equals(generatedPropertyBuilderImpl));
+ assertTrue(generatedPropertyBuilderImpl.equals(generatedPropertyBuilderImpl2));
+ assertFalse(generatedPropertyBuilderImpl.equals(generatedPropertyBuilderImpl3));
+ assertFalse(generatedPropertyBuilderImpl.equals(generatedPropertyBuilderImpl4));
+
+ assertTrue(generatedPropertyBuilderImpl.hashCode() == generatedPropertyBuilderImpl.hashCode());
+ assertTrue(generatedPropertyBuilderImpl.hashCode() == generatedPropertyBuilderImpl2.hashCode());
+ assertFalse(generatedPropertyBuilderImpl.hashCode() == generatedPropertyBuilderImpl3.hashCode());
+ assertFalse(generatedPropertyBuilderImpl.hashCode() == generatedPropertyBuilderImpl4.hashCode());
+ }
+
+}
--- /dev/null
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.*;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.Types;
+import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
+
+public class GeneratedPropertyImplTest {
+
+ @Test
+ public void generatedPropertyImplTest() {
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl = new GeneratedPropertyBuilderImpl("myPropertyName");
+ generatedPropertyBuilderImpl.setValue("myValue");
+ generatedPropertyBuilderImpl.setReadOnly(false);
+ generatedPropertyBuilderImpl.setStatic(true);
+ generatedPropertyBuilderImpl.setComment("myComment");
+ generatedPropertyBuilderImpl.setFinal(true);
+ generatedPropertyBuilderImpl.setAccessModifier(AccessModifier.PUBLIC);
+ generatedPropertyBuilderImpl.setReturnType(Types.BOOLEAN);
+
+ GeneratedProperty instance = generatedPropertyBuilderImpl.toInstance(new GeneratedTypeBuilderImpl("my.package",
+ "myTypeName").toInstance());
+
+ assertNotNull(instance);
+
+ assertTrue(instance.isFinal());
+ assertTrue(instance.isStatic());
+ assertFalse(instance.isReadOnly());
+ assertEquals("myValue", instance.getValue());
+ assertEquals("myComment", instance.getComment());
+ assertEquals(AccessModifier.PUBLIC, instance.getAccessModifier());
+ assertEquals(Types.BOOLEAN, instance.getReturnType());
+
+ assertEquals(
+ "GeneratedPropertyImpl [name=myPropertyName, annotations=[], comment=myComment, parent=my.package.myTypeName, returnType=Type (java.lang.Boolean), isFinal=true, isReadOnly=false, modifier=PUBLIC]",
+ instance.toString());
+
+ }
+
+ @Test
+ public void generatedPropertyImplEqualsAndHashCodeTest() {
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl = new GeneratedPropertyBuilderImpl("myPropertyName");
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl2 = new GeneratedPropertyBuilderImpl("myPropertyName");
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl3 = new GeneratedPropertyBuilderImpl("myPropertyName3");
+ GeneratedPropertyBuilderImpl generatedPropertyBuilderImpl4 = new GeneratedPropertyBuilderImpl("myPropertyName");
+
+ generatedPropertyBuilderImpl.setReturnType(Types.BOOLEAN);
+ generatedPropertyBuilderImpl2.setReturnType(Types.BOOLEAN);
+ generatedPropertyBuilderImpl3.setReturnType(Types.BOOLEAN);
+ generatedPropertyBuilderImpl4.setReturnType(Types.STRING);
+
+ GeneratedProperty property = generatedPropertyBuilderImpl.toInstance(null);
+ GeneratedProperty property2 = generatedPropertyBuilderImpl2.toInstance(null);
+ GeneratedProperty property3 = generatedPropertyBuilderImpl3.toInstance(null);
+ GeneratedProperty property4 = generatedPropertyBuilderImpl4.toInstance(null);
+
+ assertNotNull(property);
+ assertNotNull(property2);
+ assertNotNull(property3);
+ assertNotNull(property4);
+
+ assertFalse(property.equals(null));
+ assertFalse(property.equals(new Object()));
+ assertTrue(property.equals(property));
+ assertTrue(property.equals(property2));
+ assertFalse(property.equals(property3));
+ assertFalse(property.equals(property4));
+
+ assertTrue(property.hashCode() == property.hashCode());
+ assertTrue(property.hashCode() == property2.hashCode());
+ assertFalse(property.hashCode() == property3.hashCode());
+ assertFalse(property.hashCode() == property4.hashCode());
+ }
+
+}
--- /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.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedTransferObject;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
+
+public class GeneratedTOBuilderTest {
+
+ @Test
+ public void testBuilder() {
+ final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
+ "org.opendaylight.controller", "AnnotClassCache");
+
+ genTypeBuilder.setSUID(genTypeBuilder.addProperty("SUID"));
+ genTypeBuilder.addMethod("addCount");
+
+ GeneratedTransferObject genTO = genTypeBuilder.toInstance();
+ genTypeBuilder.setExtendsType(genTO);
+
+ GeneratedPropertyBuilder property = genTypeBuilder
+ .addProperty("customProperty");
+ genTypeBuilder.addHashIdentity(property);
+
+ genTypeBuilder.addEqualsIdentity(property);
+
+ genTypeBuilder.addToStringProperty(property);
+
+ assertNotNull(genTO);
+ assertNotNull(genTO.getProperties());
+ }
+
+ @Test
+ public void testToString() {
+ final GeneratedTOBuilder genTypeBuilder = new GeneratedTOBuilderImpl(
+ "org.opendaylight.controller", "AnnotClassCache");
+ String toString = genTypeBuilder.toString();
+ assertTrue(toString.contains("GeneratedTransferObject"));
+ }
+
+ @Test
+ public void testTransferBuilderToString() {
+ final GeneratedTOBuilder genTypeBuilder1 = new GeneratedTOBuilderImpl(
+ "org.opendaylight.controller", "AnnotClassCache");
+
+ genTypeBuilder1.setTypedef(true);
+ GeneratedTransferObject genTO = genTypeBuilder1.toInstance();
+ String toString = genTO.toString();
+ assertFalse(toString.contains("GeneratedTransferObject"));
+
+ final GeneratedTOBuilder genTypeBuilder2 = new GeneratedTOBuilderImpl(
+ "org.opendaylight.controller", "AnnotClassCache");
+
+ genTypeBuilder2.setTypedef(false);
+ genTO = genTypeBuilder2.toInstance();
+ toString = genTO.toString();
+
+ assertTrue(toString.contains("GeneratedTransferObject"));
+ }
+}
--- /dev/null
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ */
+package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.*;
+
+import java.io.Serializable;
+import java.util.List;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
+import org.opendaylight.yangtools.binding.generator.util.Types;
+import org.opendaylight.yangtools.sal.binding.model.api.Constant;
+import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedProperty;
+import org.opendaylight.yangtools.sal.binding.model.api.GeneratedType;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.EnumBuilder;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedPropertyBuilder;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTypeBuilder;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+
+public class GeneratedTypeBuilderTest {
+
+ @Test
+ public void addConstantTest() {
+ GeneratedTypeBuilder generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ // assertNotNull(generatedTypeBuilder.addComment("My comment ..."));
+
+ Constant constant = generatedTypeBuilder.addConstant(Types.typeForClass(String.class), "myConstant",
+ "myConstantValue");
+ // Constant constantx =
+ // generatedTypeBuilder.addConstant(Types.typeForClass(String.class),
+ // "myConstant", "myConstantValue");
+ Constant constant2 = generatedTypeBuilder.addConstant(
+ Types.primitiveType("int", BindingGeneratorUtil.getRestrictions(null)), "myIntConstant", 1);
+
+ Constant constant3 = new ConstantImpl(generatedTypeBuilder, Types.typeForClass(String.class), "myConstant",
+ "myConstantValue");
+ Constant constant4 = new ConstantImpl(generatedTypeBuilder, Types.typeForClass(String.class), "myConstant2",
+ "myConstantValue");
+ Constant constant5 = new ConstantImpl(generatedTypeBuilder, Types.typeForClass(String.class), "myConstant",
+ "myConstantValue2");
+
+ assertNotNull(constant);
+ assertNotNull(constant2);
+ assertNotNull(constant3);
+ assertNotNull(constant4);
+ assertNotNull(constant5);
+ // assertNotNull(constantx);
+ // assertTrue(constant!=constantx);
+
+ assertFalse(constant.equals(null));
+ assertFalse(constant.equals(new Object()));
+ assertTrue(constant.equals(constant));
+ assertTrue(constant.equals(constant3));
+ assertFalse(constant.equals(constant2));
+ assertFalse(constant.equals(constant4));
+ assertFalse(constant.equals(constant5));
+
+ assertTrue(constant.hashCode() == constant.hashCode());
+ assertTrue(constant.hashCode() == constant3.hashCode());
+ assertFalse(constant.hashCode() == constant2.hashCode());
+ assertFalse(constant.hashCode() == constant4.hashCode());
+ assertTrue(constant.hashCode() == constant5.hashCode());
+
+ assertEquals(
+ "Constant [type=Type (java.lang.String), name=myConstant, value=myConstantValue, definingType=my.package.MyName]",
+ constant.toString());
+
+ assertEquals("Type (java.lang.String) myConstant myConstantValue", constant.toFormattedString());
+
+ GeneratedType instance = generatedTypeBuilder.toInstance();
+ List<Constant> constantDefinitions = instance.getConstantDefinitions();
+ assertNotNull(constantDefinitions);
+ assertEquals(2, constantDefinitions.size());
+ assertTrue(constantDefinitions.contains(constant));
+ assertTrue(constantDefinitions.contains(constant2));
+ assertTrue(constantDefinitions.contains(constant3));
+ assertFalse(constantDefinitions.contains(constant4));
+ assertFalse(constantDefinitions.contains(constant5));
+
+ assertEquals("myConstant", constant.getName());
+ assertEquals("myConstantValue", constant.getValue());
+ assertEquals(Types.typeForClass(String.class), constant.getType());
+ assertEquals(generatedTypeBuilder, constant.getDefiningType());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addConstantIllegalArgumentTest() {
+ GeneratedTypeBuilder generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ Constant constant = generatedTypeBuilder.addConstant(Types.typeForClass(String.class), null, "myConstantValue");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addConstantIllegalArgumentTest2() {
+ GeneratedTypeBuilder generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ Constant constant = generatedTypeBuilder.addConstant(null, "myConstantName", "myConstantValue");
+ }
+
+ @Test
+ public void generatedTypeBuilderEqualsAndHashCodeTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+ GeneratedTypeBuilderImpl generatedTypeBuilder2 = new GeneratedTypeBuilderImpl("my.package", "MyName");
+ GeneratedTypeBuilderImpl generatedTypeBuilder3 = new GeneratedTypeBuilderImpl("my.package", "MyName2");
+ GeneratedTypeBuilderImpl generatedTypeBuilder4 = new GeneratedTypeBuilderImpl("my.package2", "MyName");
+
+ assertFalse(generatedTypeBuilder.equals(null));
+ assertFalse(generatedTypeBuilder.equals(new Object()));
+ assertTrue(generatedTypeBuilder.equals(generatedTypeBuilder));
+ assertTrue(generatedTypeBuilder.equals(generatedTypeBuilder2));
+
+ assertTrue(generatedTypeBuilder.hashCode() == generatedTypeBuilder.hashCode());
+ assertTrue(generatedTypeBuilder.hashCode() == generatedTypeBuilder2.hashCode());
+ assertFalse(generatedTypeBuilder.hashCode() == generatedTypeBuilder3.hashCode());
+ assertFalse(generatedTypeBuilder.hashCode() == generatedTypeBuilder4.hashCode());
+
+ }
+
+ @Test
+ public void addPropertyTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ GeneratedPropertyBuilder propertyBuilder = generatedTypeBuilder.addProperty("myProperty");
+ GeneratedPropertyBuilder propertyBuilder2 = generatedTypeBuilder.addProperty("myProperty2");
+ // GeneratedPropertyBuilder propertyBuilderNull =
+ // generatedTypeBuilder.addProperty(null);
+
+ assertNotNull(propertyBuilder);
+ assertNotNull(propertyBuilder2);
+ // assertNotNull(propertyBuilderNull);
+
+ assertTrue(generatedTypeBuilder.containsProperty("myProperty"));
+ assertTrue(generatedTypeBuilder.containsProperty("myProperty2"));
+ assertFalse(generatedTypeBuilder.containsProperty("myProperty3"));
+
+ GeneratedType instance = generatedTypeBuilder.toInstance();
+ List<GeneratedProperty> properties = instance.getProperties();
+
+ assertEquals(2, properties.size());
+
+ assertTrue(properties.contains(propertyBuilder.toInstance(instance)));
+ assertTrue(properties.contains(propertyBuilder2.toInstance(instance)));
+ // assertTrue(properties.contains(propertyBuilderNull.toInstance(instance)));
+ assertFalse(properties.contains(new GeneratedPropertyBuilderImpl("myProperty3").toInstance(instance)));
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addMethodIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addMethod(null);
+ }
+
+ @Test
+ public void addMethodTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ MethodSignatureBuilder methodBuilder = generatedTypeBuilder.addMethod("myMethodName");
+ MethodSignatureBuilder methodBuilder2 = generatedTypeBuilder.addMethod("myMethodName2");
+
+ assertNotNull(methodBuilder);
+ assertNotNull(methodBuilder2);
+
+ assertTrue(generatedTypeBuilder.containsMethod("myMethodName"));
+ assertTrue(generatedTypeBuilder.containsMethod("myMethodName2"));
+ assertFalse(generatedTypeBuilder.containsMethod("myMethodName3"));
+
+ GeneratedType instance = generatedTypeBuilder.toInstance();
+ List<MethodSignature> methodDefinitions = instance.getMethodDefinitions();
+
+ assertEquals(2, methodDefinitions.size());
+
+ assertTrue(methodDefinitions.contains(methodBuilder.toInstance(instance)));
+ assertTrue(methodDefinitions.contains(methodBuilder2.toInstance(instance)));
+ assertFalse(methodDefinitions.contains(new MethodSignatureBuilderImpl("myMethodName3").toInstance(instance)));
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addEnumerationIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addEnumeration(null);
+ }
+
+ @Test
+ public void addEnumerationTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ EnumBuilder enumBuilder = generatedTypeBuilder.addEnumeration("myEnumName");
+ EnumBuilder enumBuilder2 = generatedTypeBuilder.addEnumeration("myEnumName2");
+
+ assertNotNull(enumBuilder);
+ assertNotNull(enumBuilder2);
+
+ GeneratedType instance = generatedTypeBuilder.toInstance();
+ List<Enumeration> enumerations = instance.getEnumerations();
+
+ assertEquals(2, enumerations.size());
+
+ assertTrue(enumerations.contains(enumBuilder.toInstance(instance)));
+ assertTrue(enumerations.contains(enumBuilder2.toInstance(instance)));
+ assertFalse(enumerations.contains(new EnumerationBuilderImpl("my.package", "myEnumName3").toInstance(instance)));
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addImplementsTypeIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addImplementsType(null);
+ }
+
+ @Test
+ public void addImplementsTypeTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ assertEquals(generatedTypeBuilder,
+ generatedTypeBuilder.addImplementsType(Types.typeForClass(Serializable.class)));
+ assertEquals(generatedTypeBuilder, generatedTypeBuilder.addImplementsType(Types.typeForClass(Runnable.class)));
+
+ GeneratedType instance = generatedTypeBuilder.toInstance();
+ List<Type> implementTypes = instance.getImplements();
+
+ assertEquals(2, implementTypes.size());
+
+ assertTrue(implementTypes.contains(Types.typeForClass(Serializable.class)));
+ assertTrue(implementTypes.contains(Types.typeForClass(Runnable.class)));
+ assertFalse(implementTypes.contains(Types.typeForClass(Throwable.class)));
+
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addEnclosingTransferObjectIllegalArgumentTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addEnclosingTransferObject((String) null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void addEnclosingTransferObjectIllegalArgumentTest2() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.addEnclosingTransferObject((GeneratedTOBuilder) null);
+ }
+
+ @Test
+ public void addEnclosingTransferObjectTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ GeneratedTOBuilder enclosingTransferObject = generatedTypeBuilder.addEnclosingTransferObject("myTOName");
+ GeneratedTOBuilder enclosingTransferObject2 = generatedTypeBuilder.addEnclosingTransferObject("myTOName2");
+ assertEquals(generatedTypeBuilder, generatedTypeBuilder.addEnclosingTransferObject(new GeneratedTOBuilderImpl(
+ generatedTypeBuilder.getFullyQualifiedName(), "myTOName3")));
+
+ assertNotNull(enclosingTransferObject);
+ assertNotNull(enclosingTransferObject2);
+
+ GeneratedType instance = generatedTypeBuilder.toInstance();
+ List<GeneratedType> enclosedTypes = instance.getEnclosedTypes();
+
+ assertEquals(3, enclosedTypes.size());
+
+ assertTrue(enclosedTypes.contains(enclosingTransferObject.toInstance()));
+ assertTrue(enclosedTypes.contains(enclosingTransferObject2.toInstance()));
+ assertTrue(enclosedTypes.contains(new GeneratedTOBuilderImpl(generatedTypeBuilder.getFullyQualifiedName(),
+ "myTOName3").toInstance()));
+ assertFalse(enclosedTypes.contains(new GeneratedTOBuilderImpl(generatedTypeBuilder.getFullyQualifiedName(),
+ "myTOName4").toInstance()));
+
+ }
+
+ @Test
+ public void generatedTypeTest() {
+ GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
+
+ generatedTypeBuilder.setDescription("My description ...");
+ generatedTypeBuilder.setModuleName("myModuleName");
+ generatedTypeBuilder.setReference("myReference");
+ generatedTypeBuilder.setSchemaPath(SchemaPath.create(true, QName.create("/path")).getPathFromRoot());
+ assertNotNull(generatedTypeBuilder.addComment("My comment.."));
+
+ assertEquals(
+ "GeneratedTransferObject [packageName=my.package, name=MyName, comment=My comment.., annotations=[], implements=[], enclosedTypes=[], constants=[], enumerations=[], properties=, methods=[]]",
+ generatedTypeBuilder.toString());
+
+ GeneratedType instance = generatedTypeBuilder.toInstance();
+
+ assertEquals("My description ...", instance.getDescription());
+ assertEquals("myModuleName", instance.getModuleName());
+ assertEquals("myReference", instance.getReference());
+ assertEquals(SchemaPath.create(true, QName.create("/path")).getPathFromRoot(), instance.getSchemaPath());
+ assertEquals("My comment..", instance.getComment());
+ }
+
+}
--- /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.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.Types;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+
+public class MethodParameterImplTest {
+
+ MethodParameterImpl parameter1, parameter2, parameter3, parameter4;
+ int hash1, hash2, hash3, hash4;
+
+ @Before
+ public void Setup() {
+ String name = "customParameter";
+ Type type = Types.STRING;
+ parameter1 = new MethodParameterImpl(name, type);
+ parameter2 = new MethodParameterImpl(name, type);
+ parameter3 = new MethodParameterImpl(name, null);
+ parameter4 = new MethodParameterImpl(null, type);
+
+ hash1 = parameter1.hashCode();
+ hash2 = parameter2.hashCode();
+ hash3 = parameter3.hashCode();
+ hash4 = parameter4.hashCode();
+ }
+
+ @Test
+ public void testToString() {
+ String toString = parameter1.toString();
+ assertTrue(toString.contains("MethodParameter"));
+ }
+
+ @Test
+ public void testEquals() {
+ assertTrue(parameter1.equals(parameter1));
+ assertTrue(parameter1.equals(parameter2));
+ assertFalse(parameter1.equals("string"));
+ assertFalse(parameter1.equals(null));
+ assertFalse(parameter1.equals(parameter3));
+ assertFalse(parameter2.equals(parameter4));
+ assertFalse(parameter4.equals(parameter2));
+ assertFalse(parameter3.equals(parameter2));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(hash1,hash2);
+ assertTrue(!(hash1 == hash3));
+ assertTrue(!(hash1 == hash4));
+ }
+
+}
--- /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.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.Types;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.MethodSignatureBuilder;
+
+public class MethodSignatureBuilderTest {
+
+ MethodSignatureBuilder builder1, builder2, builder3, builder4;
+ int hash1, hash2, hash3;
+
+ @Before
+ public void setup() {
+ builder1 = new MethodSignatureBuilderImpl("methodSignature");
+ builder2 = new MethodSignatureBuilderImpl("otherMethodSignature");
+ builder2.setReturnType(Types.STRING);
+ builder3 = new MethodSignatureBuilderImpl(null);
+ builder3.setAbstract(false);
+ builder4 = new MethodSignatureBuilderImpl("otherMethodSignature");
+ builder4.setReturnType(Types.BOOLEAN);
+
+ hash1 = builder1.hashCode();
+ hash2 = builder2.hashCode();
+ hash3 = builder3.hashCode();
+ }
+
+ @Test
+ public void testAddParameter() {
+ Type type = Types.STRING;
+ String name = "customParam";
+ builder1.addParameter(type, name);
+ Type methodType = Types.voidType();
+ MethodSignature signature = builder1.toInstance(methodType);
+ assertNotNull(signature);
+ }
+
+ @Test
+ public void testToString() {
+ String toString = builder1.toString();
+ assertTrue(toString.contains("MethodSignatureBuilderImpl"));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(hash1, hash1);
+ }
+
+ @Test
+ public void testEquals() {
+ assertTrue(builder1.equals(builder1));
+ assertFalse(builder1.equals(builder2));
+ assertFalse(builder1.equals(null));
+ assertFalse(builder1.equals("string"));
+ assertFalse(builder3.equals(builder2));
+ assertFalse(builder4.equals(builder2));
+ }
+}
--- /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.binding.generator.util.generated.type.builder;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.List;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.binding.generator.util.Types;
+import org.opendaylight.yangtools.sal.binding.model.api.AccessModifier;
+import org.opendaylight.yangtools.sal.binding.model.api.AnnotationType;
+import org.opendaylight.yangtools.sal.binding.model.api.MethodSignature.Parameter;
+import org.opendaylight.yangtools.sal.binding.model.api.Type;
+
+public class MethodSignatureImplTest {
+
+ MethodSignatureImpl signature1, signature2, signature3, signature4;
+ int hash1, hash4;
+
+ @Before
+ public void setup() {
+ Type type = Types.STRING;
+ String name = "customMethod";
+ List<AnnotationType> annotations = new ArrayList<>();
+ String comment = "This is just a comment";
+ AccessModifier accessModifier = AccessModifier.PUBLIC;
+ Type returnType = Types.STRING;
+ List<Parameter> params = new ArrayList<>();
+ boolean isFinal = false;
+ boolean isAbstract = false;
+ boolean isStatic = false;
+
+ signature1 = new MethodSignatureImpl(type, name, annotations, comment,
+ accessModifier, returnType, params, isFinal, isAbstract,
+ isStatic);
+ signature2 = new MethodSignatureImpl(type, name, annotations, comment,
+ accessModifier, returnType, params, isFinal, isAbstract,
+ isStatic);
+ returnType = null;
+ signature3 = new MethodSignatureImpl(type, name, annotations, comment,
+ accessModifier, returnType, params, isFinal, isAbstract,
+ isStatic);
+ name = null;
+ signature4 = new MethodSignatureImpl(type, name, annotations, comment,
+ accessModifier, returnType, params, isFinal, isAbstract,
+ isStatic);
+
+ hash1 = signature1.hashCode();
+ hash4 = signature4.hashCode();
+ }
+
+ @Test
+ public void testToString() {
+ String toString = signature1.toString();
+ assertTrue(toString.contains("MethodSignatureImpl"));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertEquals(hash1, hash1);
+ assertTrue(!(hash1 == hash4));
+ }
+
+ @Test
+ public void testEquals() {
+ assertTrue(signature1.equals(signature1));
+ assertTrue(signature1.equals(signature2));
+ assertFalse(signature1.equals(signature3));
+ assertFalse(signature3.equals(signature1));
+ assertFalse(signature1.equals(null));
+ assertFalse(signature1.equals(signature4));
+ assertFalse(signature4.equals(signature1));
+ assertFalse(signature1.equals(Types.STRING));
+ }
+
+}
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
--- /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.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.yangtools.test.binding.rev140701;
+
+
+/**
+ * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
+ * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
+ * The reason behind putting it under src/main/java is:
+ * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
+ * loss of user code.
+ */
+public class Int32StringUnionBuilder {
+
+ public static Int32StringUnion getDefaultInstance(final String defaultValue) {
+ try {
+ return new Int32StringUnion(Integer.parseInt(defaultValue));
+ } catch (NumberFormatException e) {
+ return new Int32StringUnion(defaultValue);
+ }
+ }
+
+}
"Test model for testing data broker with nested lists.";
}
+ identity third-party {
+ base test:test-root;
+ }
+
grouping leaf-from-grouping {
leaf leaf-from-grouping {
type string;
type string;
}
}
-
}
augment "/test:top/test:top-level-list" {
uses leaf-from-grouping;
}
+ augment "/test:top/test:top-level-list" {
+ ext:augment-identifier tree-complex-leaves;
+ leaf simple-type {
+ type int32;
+ }
+ leaf identity {
+ type test:test-identityref;
+ }
+ leaf schema-unaware-union {
+ type test:int32-string-union;
+ }
+
+ leaf simple-type-ref {
+ type leafref {
+ path "../simple-type";
+ }
+ }
+ leaf identity-ref {
+ type leafref {
+ path "../identity";
+ }
+ }
+ leaf schema-unaware-union-ref {
+ type leafref {
+ path "../schema-unaware-union";
+ }
+ }
+ }
+
+
augment "/test:put-top/test:input/test:top-level-list" {
ext:augment-identifier rpc-leaf-only-uses-augment;
uses leaf-from-grouping;
"Test model for testing data broker with nested lists.";
}
+ typedef int32-string-union {
+ type union {
+ type int32;
+ type string;
+ }
+ }
+
+ identity test-root;
+
+ identity test-one {
+ base test-root;
+ }
+
+ identity test-two {
+ base test-root;
+ }
+
+ typedef test-identityref {
+ type identityref {
+ base test-root;
+ }
+ }
+
grouping two-level-list {
list top-level-list {
description
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ </dependency>
</dependencies>
</project>
* @return java <code>Type</code> representation of <code>type</code>
*/
@Override
- public Type javaTypeForYangType(String type) {
+ public Type javaTypeForYangType(final String type) {
return typeMap.get(type);
}
* returned.
*/
@Override
- public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode) {
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode) {
if (type != null) {
return typeMap.get(type.getQName().getLocalName());
}
}
@Override
- public Type javaTypeForSchemaDefinitionType(TypeDefinition<?> type, SchemaNode parentNode,
- Restrictions restrictions) {
+ public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> type, final SchemaNode parentNode,
+ final Restrictions restrictions) {
String typeName = type.getQName().getLocalName();
switch (typeName) {
case "binary":
- return Types.primitiveType("byte[]", restrictions);
+ return restrictions == null ? Types.BYTE_ARRAY : Types.primitiveType("byte[]", restrictions);
case "decimal64":
return Types.typeForClass(BigDecimal.class, restrictions);
case "enumeration":
}
@Override
- public String getTypeDefaultConstruction(LeafSchemaNode node) {
+ public String getTypeDefaultConstruction(final LeafSchemaNode node) {
return null;
}
@Override
- public String getConstructorPropertyName(SchemaNode node) {
+ public String getConstructorPropertyName(final SchemaNode node) {
return null;
}
@Override
- public String getParamNameFromType(TypeDefinition<?> type) {
+ public String getParamNameFromType(final TypeDefinition<?> type) {
return "_" + BindingGeneratorUtil.parseToValidParamName(type.getQName().getLocalName());
}
};
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNode;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findDataSchemaNodeForRelativeXPath;
import static org.opendaylight.yangtools.yang.model.util.SchemaContextUtil.findParentModule;
-
import com.google.common.base.Preconditions;
import com.google.common.collect.Sets;
import com.google.common.io.BaseEncoding;
@Override
public Type javaTypeForSchemaDefinitionType(final TypeDefinition<?> typeDefinition, final SchemaNode parentNode,
final Restrictions r) {
- Type returnType = null;
+ Type returnType;
Preconditions.checkArgument(typeDefinition != null, "Type Definition cannot be NULL!");
Preconditions.checkArgument(typeDefinition.getQName() != null,
"Type Definition cannot have non specified QName (QName cannot be NULL!)");
.getLocalName());
}
}
- // TODO: add throw exception when we will be able to resolve ALL yang
- // types!
- // if (returnType == null) {
- // throw new IllegalArgumentException("Type Provider can't resolve " +
- // "type for specified Type Definition " + typedefName);
- // }
return returnType;
}
- private GeneratedTransferObject shadedTOWithRestrictions(GeneratedTransferObject gto, Restrictions r) {
+ private GeneratedTransferObject shadedTOWithRestrictions(final GeneratedTransferObject gto, final Restrictions r) {
GeneratedTOBuilder gtob = new GeneratedTOBuilderImpl(gto.getPackageName(), gto.getName());
GeneratedTransferObject parent = gto.getSuperType();
if (parent != null) {
private Type javaTypeForExtendedType(final TypeDefinition<?> typeDefinition) {
final String typedefName = typeDefinition.getQName().getLocalName();
final TypeDefinition<?> baseTypeDef = baseTypeDefForExtendedType(typeDefinition);
- Type returnType = null;
- returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition);
+ Type returnType = javaTypeForLeafrefOrIdentityRef(baseTypeDef, typeDefinition);
if (returnType == null) {
if (baseTypeDef instanceof EnumTypeDefinition) {
final EnumTypeDefinition enumTypeDef = (EnumTypeDefinition) baseTypeDef;
}
}
return returnType;
- // TODO: add throw exception when we will be able to resolve ALL yang
- // types!
- // if (returnType == null) {
- // throw new IllegalArgumentException("Type Provider can't resolve " +
- // "type for specified Type Definition " + typedefName);
- // }
}
/**
*
* @param basePackageName
* string with name of package to which the module belongs
- * @param moduleName
+ * @param module
* string with the name of the module for to which the
* <code>typedef</code> belongs
* @param typedef
}
final GeneratedPropertyBuilder genPropBuilder = resultTOBuilder.addProperty("value");
- genPropBuilder.setReturnType(Types.primitiveType("char[]", null));
+ genPropBuilder.setReturnType(Types.CHAR_ARRAY);
resultTOBuilder.addEqualsIdentity(genPropBuilder);
resultTOBuilder.addHashIdentity(genPropBuilder);
resultTOBuilder.addToStringProperty(genPropBuilder);
*
* In this case the new generated TO is created for union subtype (recursive
* call of method
- * {@link #provideGeneratedTOBuildersForUnionTypeDef(String, TypeDefinition, String)
+ * {@link #provideGeneratedTOBuildersForUnionTypeDef(String, UnionTypeDefinition,
+ * String, SchemaNode)}
* provideGeneratedTOBuilderForUnionTypeDef} and in parent TO builder
* <code>parentUnionGenTOBuilder</code> is created property which type is
* equal to new generated TO.
* @param unionSubtype
* type definition of the <code>ExtendedType</code> type which
* represents union subtype
- * @param unionTypeName
- * string with the name for <code>unionSubtype</code>
* @param regularExpressions
* list of strings with the regular expressions
+ * @param parentNode
+ * parent Schema Node for Extended Subtype
+ *
*/
private void resolveExtendedSubtypeAsUnion(final GeneratedTOBuilder parentUnionGenTOBuilder,
final ExtendedType unionSubtype, final List<String> regularExpressions, final SchemaNode parentNode) {
* {@link TypeProviderImpl#genTypeDefsContextMap genTypeDefsContextMap} to
* be possible set it as extended type for the returning generated TO.
*
+ * @param typedef
+ * Type Definition
* @param innerExtendedType
* extended type which is part of some other extended type
* @param basePackageName
* string with the package name of the module
- * @param typedefName
- * string with the name for the generated TO
+ * @param moduleName
+ * Module Name
* @return generated TO which extends generated TO for
* <code>innerExtendedType</code>
* @throws IllegalArgumentException
Iterator<QName> path = node.getPath().getPathFromRoot().iterator();
path.next();
if (!(path.hasNext())) {
- parentName = BindingMapping.getClassName((parent).getName()) + "Data";
+ parentName = BindingMapping.getClassName(parent.getName()) + "Data";
String basePackageName = BindingGeneratorUtil.moduleNamespaceToPackageName(parent);
className = basePackageName + "." + parentName + "." + BindingMapping.getClassName(node.getQName());
} else {
String basePackageName = BindingGeneratorUtil.moduleNamespaceToPackageName(parent);
String packageName = packageNameForGeneratedType(basePackageName, type.getPath());
- parentName = BindingMapping.getClassName(((SchemaNode) parent).getQName());
+ parentName = BindingMapping.getClassName(parent.getName());
className = packageName + "." + parentName + "." + BindingMapping.getClassName(node.getQName());
}
result = bitsToDef((BitsTypeDefinition) base, className, defaultValue, type instanceof ExtendedType);
} else if (base instanceof Int64) {
result = typeToDef(Long.class, defaultValue);
} else if (base instanceof LeafrefTypeDefinition) {
- result = leafrefToDef(node, (LeafrefTypeDefinition) base);
+ result = leafrefToDef(node, (LeafrefTypeDefinition) base, defaultValue);
} else if (base instanceof StringTypeDefinition) {
result = "\"" + defaultValue + "\"";
} else if (base instanceof Uint8) {
return schemaContext.findModuleByNamespaceAndRevision(namespace, revision);
}
- private String leafrefToDef(final LeafSchemaNode parentNode, final LeafrefTypeDefinition leafrefType) {
+ private String leafrefToDef(final LeafSchemaNode parentNode, final LeafrefTypeDefinition leafrefType, final String defaultValue) {
Preconditions.checkArgument(leafrefType != null, "Leafref Type Definition reference cannot be NULL!");
Preconditions.checkArgument(leafrefType.getPathStatement() != null,
"The Path Statement for Leafref Type Definition cannot be NULL!");
} else {
dataNode = findDataSchemaNodeForRelativeXPath(schemaContext, module, parentNode, xpath);
}
- String result = getTypeDefaultConstruction((LeafSchemaNode) dataNode, parentNode.getDefault());
+ String result = getTypeDefaultConstruction((LeafSchemaNode) dataNode, defaultValue);
return result;
}
} else {
private static void initTypeDefinitionsFromSchemaContext() {
Set<TypeDefinition<?>> typedefs = schemaContext.getTypeDefinitions();
- assertEquals(16, typedefs.size());
+ assertTrue(!typedefs.isEmpty());
for (final TypeDefinition<?> typedef : typedefs) {
assertNotNull(typedef);
--- /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 java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+
+/**
+ * Mock LeafrefDypeDefinition implementation with non-null referenced RevisionAwareXPath.
+ *
+ * Although RevisionAwareXPath has implemented Override for toString to return null value to reach specific branch
+ * in TypeProviderImpl#provideTypeForLeafref method.
+ *
+ * Created by lukas on 9/17/14.
+ */
+public class LeafrefTypeWithNullToStringInXpath implements LeafrefTypeDefinition {
+ @Override public RevisionAwareXPath getPathStatement() {
+ return new RevisionAwareXPath() {
+ @Override
+ public boolean isAbsolute() {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return null;
+ }
+ };
+ }
+
+ @Override public LeafrefTypeDefinition getBaseType() {
+ return null;
+ }
+
+ @Override public String getUnits() {
+ return null;
+ }
+
+ @Override public Object getDefaultValue() {
+ return null;
+ }
+
+ @Override public QName getQName() {
+ return null;
+ }
+
+ @Override public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return null;
+ }
+
+ @Override public String getDescription() {
+ return null;
+ }
+
+ @Override public String getReference() {
+ return null;
+ }
+
+ @Override public Status getStatus() {
+ return null;
+ }
+}
--- /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 java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.RevisionAwareXPath;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+
+/**
+ * Mock LeafrefDypeDefinition implementation with RevisionAwareXPath null reference
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class LeafrefTypeWithNullXpath implements LeafrefTypeDefinition {
+ @Override public RevisionAwareXPath getPathStatement() {
+ return null;
+ }
+
+ @Override public LeafrefTypeDefinition getBaseType() {
+ return null;
+ }
+
+ @Override public String getUnits() {
+ return null;
+ }
+
+ @Override public Object getDefaultValue() {
+ return null;
+ }
+
+ @Override public QName getQName() {
+ return null;
+ }
+
+ @Override public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return null;
+ }
+
+ @Override public String getDescription() {
+ return null;
+ }
+
+ @Override public String getReference() {
+ return null;
+ }
+
+ @Override public Status getStatus() {
+ return null;
+ }
+}
--- /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 java.util.List;
+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.UnknownSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.type.IntegerTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+
+/**
+ * Mock Integer Type Definition designated to increase branch coverage in test cases.
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+final class TestIntegerTypeDefinition implements IntegerTypeDefinition {
+
+ @Override public List<RangeConstraint> getRangeConstraints() {
+ return null;
+ }
+
+ @Override public IntegerTypeDefinition getBaseType() {
+ return null;
+ }
+
+ @Override public String getUnits() {
+ return null;
+ }
+
+ @Override public Object getDefaultValue() {
+ return null;
+ }
+
+ @Override public QName getQName() {
+ return null;
+ }
+
+ @Override public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return null;
+ }
+
+ @Override public String getDescription() {
+ return null;
+ }
+
+ @Override public String getReference() {
+ return null;
+ }
+
+ @Override public Status getStatus() {
+ return null;
+ }
+}
--- /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 java.util.List;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.*;
+
+/**
+ * Mock Leaf Schema Node designated to increase branch coverage in test cases.
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+public class TestLeafSchemaNode implements LeafSchemaNode {
+ @Override public TypeDefinition<?> getType() {
+ return null;
+ }
+
+ @Override public String getDefault() {
+ return null;
+ }
+
+ @Override public String getUnits() {
+ return null;
+ }
+
+ @Override public boolean isAugmenting() {
+ return false;
+ }
+
+ @Override public boolean isAddedByUses() {
+ return false;
+ }
+
+ @Override public boolean isConfiguration() {
+ return false;
+ }
+
+ @Override public ConstraintDefinition getConstraints() {
+ return null;
+ }
+
+ @Override public QName getQName() {
+ return null;
+ }
+
+ @Override public SchemaPath getPath() {
+ return null;
+ }
+
+ @Override public List<UnknownSchemaNode> getUnknownSchemaNodes() {
+ return null;
+ }
+
+ @Override public String getDescription() {
+ return null;
+ }
+
+ @Override public String getReference() {
+ return null;
+ }
+
+ @Override public Status getStatus() {
+ return null;
+ }
+}
--- /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 java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl;
+
+/**
+ * Test Model Provider designated to load test resources and provide Schema Context
+ * for testing of TypeProviderImpl
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+final class TypeProviderModel {
+
+ public static final String TEST_TYPE_PROVIDER_MODULE_NAME = "test-type-provider";
+
+ private static final String BASE_YANG_TYPES_PATH = "/base-yang-types.yang";
+ private static final String TEST_TYPE_PROVIDER_PATH = "/"+TEST_TYPE_PROVIDER_MODULE_NAME+".yang";
+ private static final String TEST_TYPE_PROVIDER_B_PATH = "/test-type-provider-b.yang";
+
+ private static InputStream getInputStream(final String resourceName) {
+ return TypeProviderModel.class.getResourceAsStream(resourceName);
+ }
+
+ private static List<InputStream> provideTestModelStreams() {
+ final List<InputStream> arrayList = new ArrayList<>();
+
+ arrayList.add(getInputStream(BASE_YANG_TYPES_PATH));
+ arrayList.add(getInputStream(TEST_TYPE_PROVIDER_PATH));
+ arrayList.add(getInputStream(TEST_TYPE_PROVIDER_B_PATH));
+ return arrayList;
+ }
+
+ public static SchemaContext createTestContext() {
+ YangParserImpl parser = new YangParserImpl();
+ Set<Module> modules = parser.parseYangModelsFromStreams(provideTestModelStreams());
+ return parser.resolveSchemaContext(modules);
+ }
+}
--- /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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigInteger;
+import java.util.List;
+import java.util.Set;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.binding.generator.util.BindingGeneratorUtil;
+import org.opendaylight.yangtools.binding.generator.util.ReferencedTypeImpl;
+import org.opendaylight.yangtools.binding.generator.util.generated.type.builder.GeneratedTOBuilderImpl;
+import org.opendaylight.yangtools.sal.binding.generator.spi.TypeProvider;
+import org.opendaylight.yangtools.sal.binding.model.api.*;
+import org.opendaylight.yangtools.sal.binding.model.api.type.builder.GeneratedTOBuilder;
+import org.opendaylight.yangtools.yang.model.api.*;
+import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
+import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+
+/**
+ * Test suite for testing public methods in TypeProviderImpl class
+ *
+ * @see org.opendaylight.yangtools.sal.binding.yang.types.TypeProviderImpl
+ *
+ * @author Lukas Sedlak <lsedlak@cisco.com>
+ */
+@RunWith(JUnit4.class)
+public class TypeProviderTest {
+
+ private SchemaContext schemaContext;
+ private Set<Module> schemaModules;
+ private Module testTypeProviderModule;
+
+ @Mock
+ private SchemaPath schemaPath;
+
+ @Mock
+ private SchemaNode schemaNode;
+
+ @Before
+ public void setUp() {
+ MockitoAnnotations.initMocks(this);
+ schemaContext = TypeProviderModel.createTestContext();
+ assertNotNull(schemaContext);
+ schemaModules = schemaContext.getModules();
+ assertNotNull(schemaModules);
+ testTypeProviderModule = resolveModule(TypeProviderModel.TEST_TYPE_PROVIDER_MODULE_NAME);
+ assertNotNull(testTypeProviderModule);
+ }
+
+ private Module resolveModule(final String moduleName) {
+ assertNotNull(moduleName);
+ for (Module m : schemaModules) {
+ if (moduleName.equals(m.getName())) {
+ return m;
+ }
+ }
+ assertTrue("Unable to resolve module " + moduleName + ". No module present within Schema Context!" , false);
+ return null;
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void typeProviderInstanceWithNullSchemaContextTest() {
+ final TypeProvider provider = new TypeProviderImpl(null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void putReferencedTypeWithNullSchemaPathParamTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ ((TypeProviderImpl) provider).putReferencedType(null, null);
+ ((TypeProviderImpl) provider).putReferencedType(schemaPath, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void putReferencedTypeWithNullRefTypeParamTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ ((TypeProviderImpl) provider).putReferencedType(schemaPath, null);
+ }
+
+ @Test
+ public void getAdditionalTypesTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ assertNotNull(((TypeProviderImpl) provider).getAdditionalTypes());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void javaTypeForSchemaDefinitionTypeNullTypedefTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ provider.javaTypeForSchemaDefinitionType(null, null, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void javaTypeForSchemaDefinitionTypeTypedefNullQNameTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ TestIntegerTypeDefinition testTypedef = new TestIntegerTypeDefinition();
+ provider.javaTypeForSchemaDefinitionType(testTypedef, null, null);
+ }
+
+ private LeafSchemaNode provideLeafNodeFromTopLevelContainer(final Module module, final String containerName, final String leafNodeName) {
+ final DataSchemaNode rootNode = module.getDataChildByName(containerName);
+ assertNotNull("Container foo is not present in root of module "+ module.getName(), rootNode);
+ assertTrue(rootNode instanceof DataNodeContainer);
+
+ final DataNodeContainer rootContainer = (DataNodeContainer) rootNode;
+ final DataSchemaNode node = rootContainer.getDataChildByName(leafNodeName);
+ assertNotNull(node);
+ assertTrue(node instanceof LeafSchemaNode);
+ return (LeafSchemaNode) node;
+ }
+
+ private LeafListSchemaNode provideLeafListNodeFromTopLevelContainer(final Module module, final String containerName, final String leafListNodeName) {
+ final DataSchemaNode rootNode = module.getDataChildByName(containerName);
+ assertNotNull("Container foo is not present in root of module "+ module.getName(), rootNode);
+ assertTrue(rootNode instanceof DataNodeContainer);
+
+ final DataNodeContainer rootContainer = (DataNodeContainer) rootNode;
+ final DataSchemaNode node = rootContainer.getDataChildByName(leafListNodeName);
+ assertNotNull(node);
+ assertTrue(node instanceof LeafListSchemaNode);
+ return (LeafListSchemaNode) node;
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionExtTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type");
+
+ final TypeDefinition<?> leafType = leaf.getType();
+ final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) result;
+ assertEquals("base-yang-types", genTO.getModuleName());
+ assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914", genTO.getPackageName());
+ assertEquals("YangInt8", genTO.getName());
+ assertTrue(genTO.getProperties().size() == 1);
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionRestrictedExtTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "restricted-int8-type");
+
+ final TypeDefinition<?> leafType = leaf.getType();
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(leafType);
+
+ final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf, restrictions);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+
+ final GeneratedTransferObject genTO = (GeneratedTransferObject) result;
+ assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914", genTO.getPackageName());
+ assertEquals("YangInt8Restricted", genTO.getName());
+ assertTrue(genTO.getProperties().size() == 1);
+ final List<RangeConstraint> rangeConstraints = genTO.getRestrictions().getRangeConstraints();
+
+ assertTrue(!rangeConstraints.isEmpty());
+ final RangeConstraint constraint = rangeConstraints.get(0);
+ assertEquals(BigInteger.ONE, constraint.getMin());
+ assertEquals(BigInteger.valueOf(100), constraint.getMax());
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionEmptyStringPatternTypeTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final Module testTypeProvider = resolveModule("test-type-provider");
+ final TypeDefinition<?> emptyPatternString = resolveTypeDefinitionFromModule(testTypeProvider, "empty-pattern-string");
+
+ assertNotNull(emptyPatternString);
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(emptyPatternString);
+
+ Type result = provider.javaTypeForSchemaDefinitionType(emptyPatternString, emptyPatternString, restrictions);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+
+ result = provider.generatedTypeForExtendedDefinitionType(emptyPatternString, emptyPatternString);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+ }
+
+ private TypeDefinition<?> resolveTypeDefinitionFromModule(final Module module, final String typedefName) {
+ TypeDefinition<?> result = null;
+ final Set<TypeDefinition<?>> typeDefs = module.getTypeDefinitions();
+ for (final TypeDefinition<?> typedef : typeDefs) {
+ if (typedef.getQName().getLocalName().equals(typedefName)) {
+ result = typedef;
+ }
+ }
+ return result;
+ }
+
+ /**
+ * FIXME: Remove @Ignore annotation once the bug https://bugs.opendaylight.org/show_bug.cgi?id=1862 is fixed
+ */
+ @Ignore
+ @Test
+ public void bug1862RestrictedTypedefTransformationTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "bug-1862-restricted-typedef");
+
+ final TypeDefinition<?> leafType = leaf.getType();
+ final Restrictions restrictions = BindingGeneratorUtil.getRestrictions(leafType);
+ final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf, restrictions);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+ //TODO: complete test after bug 1862 is fixed
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionEnumExtTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "resolve-enum-leaf");
+ TypeDefinition<?> leafType = leaf.getType();
+ Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(result);
+ assertTrue(result instanceof Enumeration);
+
+ final Enumeration enumType = (Enumeration) result;
+ final List<Enumeration.Pair> enumValues = enumType.getValues();
+ assertTrue(!enumValues.isEmpty());
+ assertEquals("A", enumValues.get(0).getName());
+ assertEquals("B", enumValues.get(1).getName());
+
+ leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "resolve-direct-use-of-enum");
+ leafType = leaf.getType();
+ result = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(result);
+ assertTrue(result instanceof ConcreteType);
+
+ assertEquals("java.lang", result.getPackageName());
+ assertEquals("Enum", result.getName());
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionLeafrefExtTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "bar", "leafref-value");
+ TypeDefinition<?> leafType = leaf.getType();
+ final Type leafrefResolvedType1 = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(leafrefResolvedType1);
+ assertTrue(leafrefResolvedType1 instanceof GeneratedTransferObject);
+
+ final Module module = resolveModule("test-type-provider-b");
+ final DataSchemaNode rootNode = module.getDataChildByName("id");
+ assertNotNull("leaf id is not present in root of module "+ module.getName(), rootNode);
+ assertTrue(rootNode instanceof LeafSchemaNode);
+ leaf = (LeafSchemaNode) rootNode;
+ leafType = leaf.getType();
+
+ final Type leafrefResolvedType2 = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(leafrefResolvedType2);
+ assertTrue(leafrefResolvedType2 instanceof GeneratedTransferObject);
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionLeafrefToEnumTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ setReferencedTypeForTypeProvider(provider);
+
+ final Module module = resolveModule("test-type-provider-b");
+
+ final DataSchemaNode enumNode = module.getDataChildByName("enum");
+ assertNotNull("leaf enum is not present in root of module " + module.getName(), enumNode);
+ assertTrue(enumNode instanceof LeafSchemaNode);
+ LeafSchemaNode leaf = (LeafSchemaNode) enumNode;
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final Type leafrefResolvedType1 = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(leafrefResolvedType1);
+ assertTrue(leafrefResolvedType1 instanceof ReferencedTypeImpl);
+
+ final DataSchemaNode enumListNode = module.getDataChildByName("enums");
+ assertNotNull("leaf-list enums is not present in root of module "+ module.getName(), enumNode);
+ assertTrue(enumListNode instanceof LeafListSchemaNode);
+ LeafListSchemaNode leafList = (LeafListSchemaNode) enumListNode;
+ TypeDefinition<?> leafListType = leafList.getType();
+
+ final Type leafrefResolvedType2 = provider.javaTypeForSchemaDefinitionType(leafListType, leafList);
+ assertNotNull(leafrefResolvedType2);
+ assertTrue(leafrefResolvedType2 instanceof ParameterizedType);
+ }
+
+ private void setReferencedTypeForTypeProvider(TypeProvider provider) {
+ final LeafSchemaNode enumLeafNode = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo",
+ "resolve-direct-use-of-enum");
+ final TypeDefinition<?> enumLeafTypedef = enumLeafNode.getType();
+ Type enumType = provider.javaTypeForSchemaDefinitionType(enumLeafTypedef, enumLeafNode);
+
+ Type refType = new ReferencedTypeImpl(enumType.getPackageName(), enumType.getName());
+ ((TypeProviderImpl) provider).putReferencedType(enumLeafNode.getPath(), refType);
+
+ final LeafListSchemaNode enumListNode = provideLeafListNodeFromTopLevelContainer(testTypeProviderModule, "foo",
+ "list-of-enums");
+ final TypeDefinition<?> enumLeafListTypedef = enumListNode.getType();
+ enumType = provider.javaTypeForSchemaDefinitionType(enumLeafListTypedef, enumListNode);
+
+ refType = new ReferencedTypeImpl(enumType.getPackageName(), enumType.getPackageName());
+ ((TypeProviderImpl) provider).putReferencedType(enumListNode.getPath(), refType);
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionConditionalLeafrefTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final Module module = resolveModule("test-type-provider-b");
+
+ final DataSchemaNode condLeaf = module.getDataChildByName("conditional-leafref");
+ assertNotNull("leaf conditional-leafref is not present in root of module "+ module.getName(), condLeaf);
+ assertTrue(condLeaf instanceof LeafSchemaNode);
+ LeafSchemaNode leaf = (LeafSchemaNode) condLeaf;
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final Type resultType = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(resultType);
+ assertTrue(resultType instanceof ConcreteType);
+ assertEquals("java.lang", resultType.getPackageName());
+ assertEquals("Object", resultType.getName());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void javaTypeForSchemaDefinitionInvalidLeafrefPathTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final Module module = resolveModule("test-type-provider-b");
+
+ final DataSchemaNode condLeaf = module.getDataChildByName("unreslovable-leafref");
+ assertNotNull("leaf unreslovable-leafref is not present in root of module "+ module.getName(), condLeaf);
+ assertTrue(condLeaf instanceof LeafSchemaNode);
+ LeafSchemaNode leaf = (LeafSchemaNode) condLeaf;
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void provideTypeForLeafrefWithNullLeafrefTypeTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ provider.provideTypeForLeafref(null, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void provideTypeForLeafrefWithNullLeafrefTypePathStatementTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final LeafrefTypeWithNullXpath leafrePath = new LeafrefTypeWithNullXpath();
+ provider.provideTypeForLeafref(leafrePath, schemaNode);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void provideTypeForLeafrefWithNullRewisionAwareXPathTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final LeafrefTypeWithNullToStringInXpath leafrePath = new LeafrefTypeWithNullToStringInXpath();
+ provider.provideTypeForLeafref(leafrePath, schemaNode);
+ }
+
+ @Test(expected = IllegalStateException.class)
+ public void provideTypeForLeafrefWithNullParentModuleTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "bar", "leafref-value");
+ TypeDefinition<?> leafType = leaf.getType();
+ assertTrue(leafType instanceof LeafrefTypeDefinition);
+ provider.provideTypeForLeafref((LeafrefTypeDefinition) leafType, schemaNode);
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionIdentityrefExtTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "crypto");
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(result);
+ assertTrue(result instanceof ParameterizedType);
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionForExtUnionWithSimpleTypesTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "use-of-unions", "simple-int-types-union");
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+ assertEquals("YangUnion", result.getName());
+ //TODO: write additional asserts to compare whole GeneratedTrasnferObject against yang union definition
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionForExtComplexUnionWithInnerUnionTypesTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "use-of-unions", "complex-union");
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+ assertEquals("ComplexUnion", result.getName());
+ //TODO: write additional asserts to compare whole GeneratedTrasnferObject against yang union definition
+ }
+
+ @Test
+ public void javaTypeForSchemaDefinitionForExtUnionWithInnerUnionAndSimpleTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "use-of-unions", "complex-string-int-union");
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final Type result = provider.javaTypeForSchemaDefinitionType(leafType, leaf);
+ assertNotNull(result);
+ assertTrue(result instanceof GeneratedTransferObject);
+ assertEquals("ComplexStringIntUnion", result.getName());
+ //TODO: write additional asserts to compare whole GeneratedTrasnferObject against yang union definition
+ }
+
+ @Test
+ public void provideGeneratedTOBuilderForUnionTypeDefWithInnerUnionTypesTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final Module testTypeProvider = resolveModule("test-type-provider");
+ final TypeDefinition<?> unionTypeDef = resolveTypeDefinitionFromModule(testTypeProvider, "complex-union");
+
+ assertNotNull(unionTypeDef);
+ assertTrue(unionTypeDef.getBaseType() instanceof UnionTypeDefinition);
+ GeneratedTOBuilder unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name",
+ (UnionTypeDefinition)unionTypeDef.getBaseType(), "ComplexUnionType", unionTypeDef);
+
+ assertNotNull(unionTypeBuilder);
+
+ GeneratedTransferObject unionType = unionTypeBuilder.toInstance();
+ assertEquals("ComplexUnionType", unionType.getName());
+
+ unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name",
+ (UnionTypeDefinition)unionTypeDef.getBaseType(), "", unionTypeDef);
+
+ assertNotNull(unionTypeBuilder);
+
+ unionType = unionTypeBuilder.toInstance();
+ assertEquals("Union", unionType.getName());
+
+ unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name",
+ (UnionTypeDefinition)unionTypeDef.getBaseType(), null, unionTypeDef);
+
+ assertNotNull(unionTypeBuilder);
+
+ unionType = unionTypeBuilder.toInstance();
+ assertEquals("Union", unionType.getName());
+ }
+
+ @Test
+ public void provideGeneratedTOBuilderForUnionTypeDefWithInnerUnionAndSimpleTypeTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final Module testTypeProvider = resolveModule("test-type-provider");
+ final TypeDefinition<?> unionTypeDef = resolveTypeDefinitionFromModule(testTypeProvider, "complex-string-int-union");
+
+ assertNotNull(unionTypeDef);
+ assertTrue(unionTypeDef.getBaseType() instanceof UnionTypeDefinition);
+ final GeneratedTOBuilder unionTypeBuilder = provider.provideGeneratedTOBuilderForUnionTypeDef("test.package.name",
+ (UnionTypeDefinition)unionTypeDef.getBaseType(), "ComplexStringIntUnionType", unionTypeDef);
+
+ assertNotNull(unionTypeBuilder);
+
+ GeneratedTransferObject unionType = unionTypeBuilder.toInstance();
+ assertEquals("ComplexStringIntUnionType", unionType.getName());
+ }
+
+ @Test
+ public void generatedTypeForExtendedDefinitionTypeTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final Module baseYangTypes = resolveModule("base-yang-types");
+ final Set<TypeDefinition<?>> typeDefs = baseYangTypes.getTypeDefinitions();
+
+ Type yangBoolean = null;
+ Type yangEmpty = null;
+ Type yangEnumeration = null;
+ Type yangInt8 = null;
+ Type yangInt8Restricted = null;
+ Type yangInt16 = null;
+ Type yangInt32 = null;
+ Type yangInt64 = null;
+ Type yangString = null;
+ Type yangDecimal = null;
+ Type yangUint8 = null;
+ Type yangUint16 = null;
+ Type yangUint32 = null;
+ Type yangUint64 = null;
+ Type yangUnion = null;
+ Type yangBinary = null;
+ Type yangBits = null;
+ Type yangInstanceIdentifier = null;
+
+ for (TypeDefinition<?> typedef : typeDefs) {
+ Type type = provider.generatedTypeForExtendedDefinitionType(typedef, typedef);
+ if (type instanceof GeneratedTransferObject) {
+ if (type.getName().equals("YangBoolean")) {
+ yangBoolean = type;
+ } else if (type.getName().equals("YangEmpty")) {
+ yangEmpty = type;
+ } else if (type.getName().equals("YangInt8")) {
+ yangInt8 = type;
+ } else if (type.getName().equals("YangInt8Restricted")) {
+ yangInt8Restricted = type;
+ } else if (type.getName().equals("YangInt16")) {
+ yangInt16 = type;
+ } else if (type.getName().equals("YangInt32")) {
+ yangInt32 = type;
+ } else if (type.getName().equals("YangInt64")) {
+ yangInt64 = type;
+ } else if (type.getName().equals("YangString")) {
+ yangString = type;
+ } else if (type.getName().equals("YangDecimal64")) {
+ yangDecimal = type;
+ } else if (type.getName().equals("YangUint8")) {
+ yangUint8 = type;
+ } else if (type.getName().equals("YangUint16")) {
+ yangUint16 = type;
+ } else if (type.getName().equals("YangUint32")) {
+ yangUint32 = type;
+ } else if (type.getName().equals("YangUint64")) {
+ yangUint64 = type;
+ } else if (type.getName().equals("YangUnion")) {
+ yangUnion = type;
+ } else if (type.getName().equals("YangBinary")) {
+ yangBinary = type;
+ } else if (type.getName().equals("YangInstanceIdentifier")) {
+ yangInstanceIdentifier = type;
+ } else if (type.getName().equals("YangBits")) {
+ yangBits = type;
+ }
+ } else if (type instanceof Enumeration) {
+ if (type.getName().equals("YangEnumeration")) {
+ yangEnumeration = type;
+ }
+ }
+ }
+
+ assertNotNull(yangBoolean);
+ assertNotNull(yangEmpty);
+ assertNotNull(yangEnumeration);
+ assertNotNull(yangInt8);
+ assertNotNull(yangInt8Restricted);
+ assertNotNull(yangInt16);
+ assertNotNull(yangInt32);
+ assertNotNull(yangInt64);
+ assertNotNull(yangString);
+ assertNotNull(yangDecimal);
+ assertNotNull(yangUint8);
+ assertNotNull(yangUint16);
+ assertNotNull(yangUint32);
+ assertNotNull(yangUint64);
+ assertNotNull(yangUnion);
+ assertNotNull(yangBinary);
+ assertNotNull(yangBits);
+ assertNotNull(yangInstanceIdentifier);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void generatedTypeForExtendedDefinitionTypeWithTypedefNullTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ provider.generatedTypeForExtendedDefinitionType(null, null);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void generatedTypeForExtendedDefinitionTypeWithTypedefQNameNullTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ TestIntegerTypeDefinition testInt = new TestIntegerTypeDefinition();
+ provider.generatedTypeForExtendedDefinitionType(testInt, testInt);
+ }
+
+ @Test
+ public void generatedTypeForExtendedDefinitionTypeWithInnerExtendedTypeTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final Module baseYangTypes = resolveModule("test-type-provider");
+ TypeDefinition<?> extYangInt8Typedef = resolveTypeDefinitionFromModule(baseYangTypes, "extended-yang-int8");
+ assertNotNull(extYangInt8Typedef);
+ Type extType = provider.generatedTypeForExtendedDefinitionType(extYangInt8Typedef, extYangInt8Typedef);
+ assertNotNull(extType);
+ assertTrue(extType instanceof GeneratedTransferObject);
+ }
+
+ @Test
+ public void generatedTypeForExtendedDefinitionTypeWithLeafrefBaseTypeTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final Module baseYangTypes = resolveModule("test-type-provider");
+ TypeDefinition<?> barItemLeafrefId = resolveTypeDefinitionFromModule(baseYangTypes, "bar-item-leafref-id");
+ assertNotNull(barItemLeafrefId);
+ Type extType = provider.generatedTypeForExtendedDefinitionType(barItemLeafrefId, barItemLeafrefId);
+ assertEquals(null, extType);
+ }
+
+ @Test
+ public void generatedTypeForExtendedDefinitionTypeWithIdentityrefBaseTypeTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final Module baseYangTypes = resolveModule("test-type-provider");
+
+ TypeDefinition<?> aesIdentityrefType = resolveTypeDefinitionFromModule(baseYangTypes, "aes-identityref-type");
+
+ assertNotNull(aesIdentityrefType);
+ Type extType = provider.generatedTypeForExtendedDefinitionType(aesIdentityrefType, aesIdentityrefType);
+ assertEquals(null, extType);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void provideGeneratedTOBuilderForBitsTypeDefinitionWithNullTypedefTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ provider.provideGeneratedTOBuilderForBitsTypeDefinition("", null, "", "");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void provideGeneratedTOBuilderForBitsTypeDefinitionWithBasePackageNullTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type");
+ final TypeDefinition<?> leafType = leaf.getType();
+ provider.provideGeneratedTOBuilderForBitsTypeDefinition(null, leafType, "", "");
+ }
+
+ @Test
+ public void provideGeneratedTOBuilderForBitsTypeDefinitionWithNonBitsTypedefTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type");
+ final TypeDefinition<?> leafType = leaf.getType();
+ Type type = provider.provideGeneratedTOBuilderForBitsTypeDefinition("", leafType, "", "");
+
+ assertEquals(null, type);
+ }
+
+ @Test
+ public void getConstructorPropertyNameTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type");
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final String ctorPropertyName = provider.getConstructorPropertyName(leafType);
+ assertEquals("value", ctorPropertyName);
+
+ final String emptyStringName = provider.getConstructorPropertyName(leaf);
+ assertTrue(emptyStringName.isEmpty());
+ }
+
+ @Test
+ public void getParamNameFromTypeTest() {
+ final TypeProvider provider = new TypeProviderImpl(schemaContext);
+
+ final LeafSchemaNode leaf = provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "foo", "yang-int8-type");
+ final TypeDefinition<?> leafType = leaf.getType();
+
+ final String paramName = provider.getParamNameFromType(leafType);
+ assertEquals("yangInt8", paramName);
+ }
+
+ @Test
+ public void addUnitsToGenTOTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ GeneratedTOBuilder builder = new GeneratedTOBuilderImpl("test.package", "TestBuilder");
+
+ provider.addUnitsToGenTO(builder, null);
+ GeneratedTransferObject genTO = builder.toInstance();
+ assertTrue(genTO.getConstantDefinitions().isEmpty());
+
+ provider.addUnitsToGenTO(builder, "");
+ genTO = builder.toInstance();
+ assertTrue(genTO.getConstantDefinitions().isEmpty());
+
+ provider.addUnitsToGenTO(builder, "125");
+ genTO = builder.toInstance();
+ assertTrue(!genTO.getConstantDefinitions().isEmpty());
+ assertEquals(1, genTO.getConstantDefinitions().size());
+ assertEquals("_UNITS", genTO.getConstantDefinitions().get(0).getName());
+ assertEquals(genTO.getConstantDefinitions().get(0).getValue(), "\"125\"");
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getTypeDefaultConstructionLeafTypeNullTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ TestLeafSchemaNode leafSchemaNode = new TestLeafSchemaNode();
+ provider.getTypeDefaultConstruction(leafSchemaNode, null);
+ }
+
+ @Test(expected = NullPointerException.class)
+ public void getTypeDefaultConstructionDefaultValueNullTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ final LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("yang-boolean");
+ provider.getTypeDefaultConstruction(leaf, null);
+ }
+
+ private LeafSchemaNode provideLeafForGetDefaultConstructionTestCase(final String leafName) {
+ return provideLeafNodeFromTopLevelContainer(testTypeProviderModule, "construction-type-test",
+ leafName);
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getTypeDefaultConstructionDefaultValueForInstanceIdentifierTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("foo-container-id");
+ provider.getTypeDefaultConstruction(leaf, "NAN");
+ }
+
+ @Test(expected = UnsupportedOperationException.class)
+ public void getTypeDefaultConstructionDefaultValueForIdentityrefTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+ LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("aes-identityref-type");
+ provider.getTypeDefaultConstruction(leaf, "NAN");
+ }
+
+ @Test
+ public void getTypeDefaultConstructionDefaultValueTest() {
+ final TypeProviderImpl provider = new TypeProviderImpl(schemaContext);
+
+ LeafSchemaNode leaf = provideLeafForGetDefaultConstructionTestCase("yang-boolean");
+ String result = provider.getTypeDefaultConstruction(leaf, "true");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangBoolean(new java.lang.Boolean(\"true\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-empty");
+ result = provider.getTypeDefaultConstruction(leaf, "true");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangEmpty(new java.lang.Boolean(\"true\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-enumeration");
+ result = provider.getTypeDefaultConstruction(leaf, "a");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangEnumeration.A",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("direct-use-of-enum");
+ result = provider.getTypeDefaultConstruction(leaf, "y");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.construction.type.test.DirectUseOfEnum.Y",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-int8");
+ result = provider.getTypeDefaultConstruction(leaf, "17");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt8(new java.lang.Byte(\"17\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-int8-restricted");
+ result = provider.getTypeDefaultConstruction(leaf, "99");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt8Restricted(new java.lang.Byte(\"99\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-int16");
+ result = provider.getTypeDefaultConstruction(leaf, "1024");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt16(new java.lang.Short(\"1024\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-int32");
+ result = provider.getTypeDefaultConstruction(leaf, "1048576");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt32(new java.lang.Integer(\"1048576\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-int64");
+ result = provider.getTypeDefaultConstruction(leaf, "1099511627776");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt64(new java.lang.Long(\"1099511627776\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-string");
+ result = provider.getTypeDefaultConstruction(leaf, "TEST");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangString(\"TEST\")",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-decimal64");
+ result = provider.getTypeDefaultConstruction(leaf, "1274.25");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangDecimal64(new java.math.BigDecimal(\"1274.25\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint8");
+ result = provider.getTypeDefaultConstruction(leaf, "128");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint8(new java.lang.Short(\"128\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint16");
+ result = provider.getTypeDefaultConstruction(leaf, "1048576");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint16(new java.lang.Integer(\"1048576\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint32");
+ result = provider.getTypeDefaultConstruction(leaf, "1099511627776");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint32(new java.lang.Long(\"1099511627776\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-uint64");
+ result = provider.getTypeDefaultConstruction(leaf, "1208925819614629174706176");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUint64(new java.math.BigInteger(\"1208925819614629174706176\"))",
+ result);
+
+ //FIXME: Is this correct scenario and correct result?
+ leaf = provideLeafForGetDefaultConstructionTestCase("complex-union");
+ result = provider.getTypeDefaultConstruction(leaf, "75");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.ComplexUnion(\"null\".toCharArray())",
+ result);
+
+ //FIXME: Is this correct scenario and correct result?
+ leaf = provideLeafForGetDefaultConstructionTestCase("complex-string-int-union");
+ result = provider.getTypeDefaultConstruction(leaf, "TEST_UNION_STRING_DEFAULT");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.ComplexStringIntUnion(\"null\".toCharArray())",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("simple-int-types-union");
+ result = provider.getTypeDefaultConstruction(leaf, "2048");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangUnion(\"null\".toCharArray())",
+ result);
+
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("direct-union-leaf");
+ result = provider.getTypeDefaultConstruction(leaf);
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.DirectUnionLeaf(\"128\".toCharArray())",
+ result);
+
+ final Module module = resolveModule("test-type-provider");
+ DataSchemaNode rootNode = module.getDataChildByName("root-union-leaf");
+ assertNotNull("leaf root-union-leaf is not present in root of module "+ module.getName(), rootNode);
+ assertTrue(rootNode instanceof LeafSchemaNode);
+ leaf = (LeafSchemaNode) rootNode;
+ result = provider.getTypeDefaultConstruction(leaf);
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.TestTypeProviderData.RootUnionLeaf(\"256\".toCharArray())",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-binary");
+ result = provider.getTypeDefaultConstruction(leaf, "0xffffff");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangBinary(new byte[] {-45, 23, -33, 125, -9, -33})",
+ result);
+
+ rootNode = module.getDataChildByName("root-bits-leaf");
+ assertNotNull("leaf bits-leaf is not present in root of module "+ module.getName(), rootNode);
+ assertTrue(rootNode instanceof LeafSchemaNode);
+ leaf = (LeafSchemaNode) rootNode;
+ result = provider.getTypeDefaultConstruction(leaf);
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.type.provider.model.rev140912.TestTypeProviderData.RootBitsLeaf(false, true, false)",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("yang-bits");
+ result = provider.getTypeDefaultConstruction(leaf, "10-Mb-only");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangBits(true, false, false)",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("bar-id");
+ result = provider.getTypeDefaultConstruction(leaf, "128");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt16(new java.lang.Short(\"128\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("foo-leafref-value");
+ result = provider.getTypeDefaultConstruction(leaf, "32");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new org.opendaylight.yang.gen.v1.urn.opendaylight.org.test.base.yang.types.rev140914.YangInt8(new java.lang.Byte(\"32\"))",
+ result);
+
+ leaf = provideLeafForGetDefaultConstructionTestCase("foo-cond-bar-item");
+ result = provider.getTypeDefaultConstruction(leaf, "10");
+ assertNotNull(result);
+ assertTrue(!result.isEmpty());
+ assertEquals("new java.lang.Object()",
+ result);
+ }
+}
description "This module contains definitions of all Yang base types.";
- revision "2014-07-23"{
+ revision "2014-09-14" {
+ reference "Added yang-int8-restricted type.";
+ }
+
+ revision "2014-07-23" {
reference "Initial Revision.";
}
type int8;
}
+ typedef yang-int8-restricted {
+ type int8 {
+ range 1..100;
+ }
+ }
+
typedef yang-int16 {
type int16;
}
type binary;
}
+ typedef yang-bits {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit 10-Mb-only {
+ position 2;
+ }
+ }
+ default "auto-sense-speed";
+ }
+
typedef yang-instance-identifier {
type instance-identifier;
}
--- /dev/null
+module test-type-provider-b {
+ yang-version 1;
+ namespace "urn:opendaylight:org:test:type:provider:b:model";
+ prefix "tp";
+
+ import test-type-provider { prefix prov; }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ description "This module contains model for providing test data for Type Provider Test implementation.";
+
+ revision "2014-09-15" {
+ reference "Initial Revision.";
+ }
+
+ leaf id {
+ type leafref {
+ path "/prov:foo/prov:bars/prov:bar-item/prov:id";
+ }
+ }
+
+ leaf enum {
+ type leafref {
+ path "/prov:foo/prov:resolve-direct-use-of-enum";
+ }
+ }
+
+ leaf-list enums {
+ type leafref {
+ path "/prov:foo/prov:list-of-enums";
+ }
+ }
+
+ leaf conditional-leafref {
+ type leafref {
+ path "/prov:foo/prov:bars/prov:bar-item/[prov:id=10]";
+ }
+ }
+
+ leaf unreslovable-leafref {
+ type leafref {
+ path "/somewhere/i/bellong";
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module test-type-provider {
+ yang-version 1;
+ namespace "urn:opendaylight:org:test:type:provider:model";
+ prefix "tp";
+
+ import base-yang-types { prefix types; }
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ description "This module contains model for providing test data for Type Provider Test implementation.";
+
+ revision "2014-09-12" {
+ reference "Initial Revision.";
+ }
+
+ identity crypto-alg {
+ description
+ "Base identity from which all crypto algorithms
+ are derived.";
+ }
+
+ identity aes {
+ base "crypto-alg";
+ }
+
+ typedef extended-yang-int8 {
+ type types:yang-int8 {
+ range 1..100;
+ }
+ default 10;
+ }
+
+ typedef inner-union {
+ type union {
+ type int32;
+ type int16;
+ }
+ }
+
+ typedef restricted-string {
+ type string {
+ length "0..4";
+ pattern "[0-9a-fA-F]*";
+ }
+ }
+
+ typedef empty-pattern-string {
+ type string {
+ pattern "";
+ }
+ }
+
+ typedef complex-union {
+ type union {
+ type restricted-string;
+ type inner-union;
+ type union {
+ type enumeration {
+ enum a;
+ enum b;
+ enum c;
+ }
+ }
+ }
+ }
+
+ typedef complex-string-int-union {
+ type union {
+ type inner-union;
+ type string;
+ }
+ }
+
+ typedef aes-identityref-type {
+ type identityref {
+ base "aes";
+ }
+ }
+
+ typedef bar-item-leafref-id {
+ type leafref {
+ path "/foo/bars/bar-item/id";
+ }
+ }
+
+ container foo {
+ container bars {
+ list bar-item {
+ key "id";
+
+ leaf id {
+ type types:yang-int16;
+ }
+ }
+ }
+
+ leaf yang-int8-type {
+ type types:yang-int8;
+ }
+
+ leaf bug-1862-restricted-typedef {
+ type types:yang-int8 {
+ range "1..100";
+ }
+ }
+
+ leaf restricted-int8-type {
+ type types:yang-int8-restricted;
+ }
+
+ leaf restricted-int {
+ type int16 {
+ range "1..100";
+ }
+ }
+
+ leaf resolve-enum-leaf {
+ type types:yang-enumeration;
+ }
+
+ leaf resolve-direct-use-of-enum {
+ type enumeration {
+ enum x;
+ enum y;
+ enum z;
+ }
+ }
+
+ leaf-list list-of-enums {
+ type enumeration {
+ enum x;
+ enum y;
+ enum z;
+ }
+ }
+
+ leaf crypto {
+ type identityref {
+ base "crypto-alg";
+ }
+ }
+ }
+
+ container bar {
+ leaf leafref-value {
+ type leafref {
+ path "../../foo/yang-int8-type";
+ }
+ }
+ }
+
+ container use-of-unions {
+ leaf complex-union {
+ type complex-union;
+ }
+
+ leaf complex-string-int-union {
+ type complex-string-int-union;
+ }
+
+ leaf simple-int-types-union {
+ type types:yang-union;
+ }
+ }
+
+ container construction-type-test {
+ leaf yang-boolean {
+ type types:yang-boolean;
+ }
+
+ leaf yang-empty {
+ type types:yang-empty;
+ }
+
+ leaf yang-enumeration {
+ type types:yang-enumeration;
+ }
+
+ leaf direct-use-of-enum {
+ type enumeration {
+ enum x;
+ enum y;
+ enum z;
+ }
+ }
+
+ leaf yang-int8 {
+ type types:yang-int8;
+ }
+
+ leaf yang-int8-restricted {
+ type types:yang-int8-restricted;
+ }
+
+ leaf yang-int16 {
+ type types:yang-int16;
+ }
+
+ leaf yang-int32 {
+ type types:yang-int32;
+ }
+
+ leaf yang-int64 {
+ type types:yang-int64;
+ }
+
+ leaf yang-string {
+ type types:yang-string;
+ }
+
+ leaf yang-decimal64 {
+ type types:yang-decimal64;
+ }
+
+ leaf yang-uint8 {
+ type types:yang-uint8;
+ }
+
+ leaf yang-uint16 {
+ type types:yang-uint16;
+ }
+
+ leaf yang-uint32 {
+ type types:yang-uint32;
+ }
+
+ leaf yang-uint64 {
+ type types:yang-uint64;
+ }
+
+ leaf complex-union {
+ type complex-union;
+ }
+
+ leaf complex-string-int-union {
+ type complex-string-int-union;
+ }
+
+ leaf simple-int-types-union {
+ type types:yang-union;
+ }
+
+ leaf direct-union-leaf {
+ type union {
+ type int32;
+ type int64;
+ }
+ default "128";
+ }
+
+ leaf yang-binary {
+ type types:yang-binary;
+ }
+
+ leaf yang-bits {
+ type types:yang-bits;
+ }
+
+ leaf bar-id {
+ type bar-item-leafref-id;
+ default "128";
+ }
+
+ leaf foo-leafref-value {
+ type leafref {
+ path "../../foo/yang-int8-type";
+ }
+ }
+
+ leaf foo-cond-bar-item {
+ type leafref {
+ path "../../foo/bars/bar-item/[id=10]";
+ }
+ }
+
+ leaf aes-identityref-type {
+ type aes-identityref-type;
+ }
+
+ leaf foo-container-id {
+ type instance-identifier;
+ }
+ }
+
+ leaf root-bits-leaf {
+ type bits {
+ bit disable-nagle {
+ position 0;
+ }
+ bit auto-sense-speed {
+ position 1;
+ }
+ bit 10-Mb-only {
+ position 2;
+ }
+ }
+ default "auto-sense-speed";
+ }
+
+ leaf root-union-leaf {
+ type union {
+ type int32;
+ type int64;
+ }
+ default "256";
+ }
+}
\ No newline at end of file
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>maven-sal-api-gen-plugin</artifactId>
<artifactId>plexus-slf4j-logging</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.sonatype.sisu</groupId>
+ <artifactId>sisu-guava</artifactId>
+ <version>0.11.1</version>
+ <scope>runtime</scope>
+ </dependency>
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
*/
package org.opendaylight.yangtools.yang.unified.doc.generator
+import com.google.common.collect.Iterables
import java.io.BufferedWriter
import java.io.File
import java.io.IOException
import java.util.Map
import java.util.Set
import org.opendaylight.yangtools.yang.common.QName
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode
import org.opendaylight.yangtools.yang.model.api.AugmentationTarget
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode
import org.slf4j.LoggerFactory
import org.sonatype.plexus.build.incremental.BuildContext
import org.sonatype.plexus.build.incremental.DefaultBuildContext
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates
-import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier
-import com.google.common.collect.Iterables
class GeneratorImpl {
case reconnect-immediately-strategy-factory {
when "/config:modules/config:module/config:type = 'reconnect-immediately-strategy-factory'";
- leaf timeout {
+ leaf timeout2 {
mandatory true;
type int32;
}
- container executor {
+ container executor2 {
uses config:service-ref {
refine type {
mandatory true;
units "milliseconds";
}
- container executor {
+ container executor3 {
uses config:service-ref {
refine type {
mandatory true;
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../common/parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<module>binding-data-codec</module>
</modules>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.javassist</groupId>
- <artifactId>javassist</artifactId>
- <version>${javassist.version}</version>
- </dependency>
-
- <!-- Local Dependencies -->
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-test-model</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-model-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-spi</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-util</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-impl</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-java-api-generator</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>maven-sal-api-gen-plugin</artifactId>
- <version>${project.version}</version>
- </dependency>
-
- <!-- YANG Utilities and Parser -->
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-common</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-impl</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-util</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-util</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-binding</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-parser-api</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-parser-impl</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin</artifactId>
- <version>${project.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
- <version>${project.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
-
<build>
<pluginManagement>
<plugins>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>maven-code-gen-sample</artifactId>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-generator</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>modeling-sample</artifactId>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ 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
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-artifacts</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ <packaging>pom</packaging>
+
+ <prerequisites>
+ <maven>3.0.4</maven>
+ </prerequisites>
+
+ <properties>
+ <!-- Model versions -->
+ <ietf.topology.version>2013.10.21.7-SNAPSHOT</ietf.topology.version>
+ </properties>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>maven-sal-api-gen-plugin</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.thirdparty</groupId>
+ <artifactId>antlr4-runtime-osgi-nohead</artifactId>
+ <version>4.0</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.thirdparty</groupId>
+ <artifactId>xtend-lib-osgi</artifactId>
+ <version>2.4.3</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>concepts</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>object-cache-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>object-cache-guava</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>object-cache-noop</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-model-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-generator-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-generator-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-generator-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-generator-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-java-api-generator</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-codec-gson</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-model-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-binding</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-parser-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-parser-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-maven-plugin-spi</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-inet-types</artifactId>
+ <version>2010.09.24.7-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-yang-types</artifactId>
+ <version>2010.09.24.7-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-yang-types-20130715</artifactId>
+ <version>2013.07.15.7-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-restconf</artifactId>
+ <version>2013.10.19.7-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-ted</artifactId>
+ <version>${ietf.topology.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology</artifactId>
+ <version>${ietf.topology.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology-isis</artifactId>
+ <version>${ietf.topology.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology-l3-unicast-igp</artifactId>
+ <version>${ietf.topology.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology-ospf</artifactId>
+ <version>${ietf.topology.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology-l3-unicast</artifactId>
+ <version>${ietf.topology.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-composite-node</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>restconf-client-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>restconf-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>restconf-util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>restconf-test-service</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>restconf-client-impl</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>restconf-jaxrs-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>bug527-test-model</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>bug1196-test-model</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>websocket-client</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>object-cache-api</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>object-cache-guava</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>object-cache-noop</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>${project.groupId}</groupId>
+ <artifactId>util</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>opendaylight-l2-types</artifactId>
+ <version>2013.08.27.7-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>yang-ext</artifactId>
+ <version>2013.09.07.7-SNAPSHOT</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-type-provider</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yang-data-operations</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-data-codec</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>features-yangtools</artifactId>
+ <classifier>features</classifier>
+ <type>xml</type>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>mockito-configuration</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>binding-test-model</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>features-test</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+</project>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<artifactId>checkstyle-logging</artifactId>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
*
* @param <P> Product of builder
*
- * @author Tony Tkacik <ttkacik@cisco.com>
+ * @author Tony Tkacik <ttkacik@cisco.com>
*/
public interface Builder<P> extends Mutable {
* Multiple calls to this method are not required to return
* same instance if the state of the builder was changed.
*
- * @return
+ * @return Newly-built instance
*/
P toInstance();
}
public interface ClassBasedPropertyBuilder<P,T extends ClassBasedPropertyBuilder<P,T>> extends Builder<P> {
/**
- * Sets a value of property uniquely identified by it's
+ * Sets a value of property uniquely identified by its
* class.
*
* @param type Type of property to set
* @param value Value of property
- * @return
+ * @return Builder instance
*/
- <V> T set(Class<V> type,V value);
+ <V> T set(Class<V> type, V value);
/**
- * Gets a value of property based on it's type.
+ * Gets a value of property based on its type.
*
- * @param type
- * @return
+ * @param type Type of property to get
+ * @return Builder instance
*/
<V> V get(Class<V> type);
-
}
public interface ProductAwareBuilder<P> extends Builder<P> {
/**
* Return the hash code of the product. This has to be equivalent
- * of calling {@link #toInstance()}.{@link #hashCode()}.
+ * of calling {@link #toInstance()}.{@link Object#hashCode()}.
*
* @return the hash code of the product.
*/
/**
* Check whether an instance of the product that would be created
* by the builder is equal to an existing instance. This has to
- * be equivalent of calling {@link #toInstance()}.{@link #equals(Object)}.
+ * be equivalent of calling {@link #toInstance()}.{@link Object#equals(Object)}.
*
* @param product Product instance
* @return Return true if the product is equal to the would-be
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- vi: set et smarttab sw=4 tabstop=4: -->
+<!--
+ 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
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.opendaylight.odlparent</groupId>
+ <artifactId>odlparent</artifactId>
+ <version>1.5.0-SNAPSHOT</version>
+ </parent>
+
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>features-builder</artifactId>
+ <packaging>pom</packaging>
+ <version>0.7.0-SNAPSHOT</version>
+
+ <properties>
+ <features.file>features.xml</features.file>
+ </properties>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+
+ <pluginManagement>
+ <plugins>
+ <!-- generate dependencies versions -->
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals><goal>resolve</goal></goals>
+ <configuration>
+ <outputFile>${project.build.directory}/dependencies.txt</outputFile>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>com.alexecollins.maven.plugin</groupId>
+ <artifactId>script-maven-plugin</artifactId>
+ <version>1.0.0</version>
+ <executions>
+ <execution>
+ <id>add-version-to-features</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>execute</goal>
+ </goals>
+ <configuration>
+ <language>groovy</language>
+ <script>
+ /**
+ * Placeholder, which is used in src/feature/features.xml
+ * to mark version which should be inserted from dependencies.
+ * Currently works only for bundle and configfile tags
+ * with mvn: url schema, and needs to be used
+ * as third component of schema.
+ * eg. mvn:group/artefact/{{VERSION}}
+ */
+ def versionPlaceholder = "{{VERSION}}"
+ /**
+ * Path to features.xml which uses versionPlaceholder.
+ * This will be processed by this script.
+ *
+ */
+ def featureFilePath = "src/main/feature/features.xml"
+ // Contains mapping of groupID:artefactID to versoin
+ def versionMap = new HashMap();
+ /* Loads transitive dependency list generated from
+ * maven-dependency-plugin resolve goal
+ * and populates map
+ */
+ def dependencies = new File(project.build.directory,"dependencies.txt")
+ dependencies.eachLine {
+ def cmps = it.trim().split(":")
+ // 0 - groupId
+ // 1 - artifactId
+ // 2 - Type
+ // 3 - Version
+ if(cmps.length >= 4) {
+ def id = cmps[0] + ":" + cmps[1]
+ versionMap[id] = cmps[3]
+ }
+ }
+
+ /*
+ * Takes splitted mvn: URL, looks for placeholder
+ * and returns new mvn: URL with version learned
+ * from dependency plugin.
+ *
+ * If referenced bundle is not dependency (direct or transitive)
+ * throws an exception and fails build.
+ *
+ */
+ def updatedURLFromProject = { args ->
+ // 0 - groupID, 1 - artifactID
+ // 2 - version, 3 - type, 4 - Classifier
+
+ def groupId = args[0];
+ def artifactId = args[1];
+ def id = groupId + ":" + artifactId
+ def dependencyVersion = versionMap[id]
+ if(dependencyVersion != null) {
+ // Overriding version
+ args[2] = dependencyVersion
+ return "mvn:" + args.join("/")
+ }
+ throw new IllegalArgumentException("Feature dependency $groupId:$artifactId is not dependecy of project.")
+ }
+
+
+ def updateMavenDependency = { dep ->
+ def mvnUrl = dep.text()
+ if(mvnUrl.startsWith("mvn:")) {
+ def components = mvnUrl.substring(4).split("/")
+ if(components[2] == versionPlaceholder) {
+ dep.value = updatedURLFromProject(components)
+ }
+ }
+ }
+
+ def featureFile = new File(project.basedir,featureFilePath)
+ def root = new XmlParser().parse(featureFile)
+
+ root.feature.each { feature ->
+ println "[INFO] Processing feature: ${feature.@name}"
+ feature.bundle.each updateMavenDependency
+ feature.configfile.each updateMavenDependency
+ }
+
+ def outDir = new File(project.build.directory,"generated-resources/script")
+ outDir.mkdirs();
+ def outFile = new File(outDir,"features.xml")
+ def outWriter = outFile.newPrintWriter("ASCII");
+ xmlPrinter = new XmlNodePrinter(outWriter);
+ xmlPrinter.preserveWhitespace = true
+ xmlPrinter.print(root)
+ outWriter.close();
+ </script>
+ </configuration>
+ </execution>
+ </executions>
+ <dependencies>
+ <dependency>
+ <groupId>org.codehaus.groovy</groupId>
+ <artifactId>groovy</artifactId>
+ <version>1.8.6</version>
+ </dependency>
+ </dependencies>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
+ <version>${karaf.version}</version>
+ <extensions>true</extensions>
+ <executions>
+ <execution>
+ <id>features-create-kar</id>
+ <goals>
+ <goal>features-create-kar</goal>
+ </goals>
+ <configuration>
+ <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
+ </configuration>
+ </execution>
+ </executions>
+ <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
+ </plugin>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>build-helper-maven-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>generate-resources</phase>
+ <goals><goal>add-resource</goal></goals>
+ <configuration>
+ <resources>
+ <resource>
+ <directory>${project.build.directory}/generated-resources/script</directory>
+ <filtering>true</filtering>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ <execution>
+ <id>attach-artifacts</id>
+ <phase>package</phase>
+ <goals>
+ <goal>attach-artifact</goal>
+ </goals>
+ <configuration>
+ <artifacts>
+ <artifact>
+ <file>${project.build.directory}/classes/${features.file}</file>
+ <type>xml</type>
+ <classifier>features</classifier>
+ </artifact>
+ </artifacts>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>filter</id>
+ <phase>generate-resources</phase>
+ <goals>
+ <goal>resources</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-surefire-plugin</artifactId>
+ <configuration>
+ <dependenciesToScan>
+ <dependency>org.opendaylight.yangtools:features-test</dependency>
+ </dependenciesToScan>
+ </configuration>
+ </plugin>
+ </plugins>
+ </pluginManagement>
+ </build>
+
+ <dependencies>
+ <!-- test the features.xml -->
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>features-test</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+</project>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<artifactId>features-test</artifactId>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
- <relativePath>../parent/pom.xml</relativePath>
+ <artifactId>features-builder</artifactId>
+ <version>0.7.0-SNAPSHOT</version>
+ <relativePath>../features-builder/pom.xml</relativePath>
</parent>
- <artifactId>features-yangtools</artifactId>
+
+ <artifactId>yangtools-features</artifactId>
<packaging>jar</packaging>
- <properties>
- <features.file>features.xml</features.file>
- </properties>
+
<build>
- <resources>
- <resource>
- <directory>src/main/resources</directory>
- <filtering>true</filtering>
- </resource>
- </resources>
<plugins>
+ <!-- generate dependencies versions -->
<plugin>
- <groupId>org.apache.karaf.tooling</groupId>
- <artifactId>karaf-maven-plugin</artifactId>
- <version>${karaf.version}</version>
- <extensions>true</extensions>
- <executions>
- <execution>
- <id>features-create-kar</id>
- <goals>
- <goal>features-create-kar</goal>
- </goals>
- <configuration>
- <featuresFile>${project.build.directory}/classes/${features.file}</featuresFile>
- </configuration>
- </execution>
- </executions>
- <!-- There is no useful configuration for the kar mojo. The features-generate-descriptor mojo configuration may be useful -->
+ <artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <executions>
- <execution>
- <id>filter</id>
- <phase>generate-resources</phase>
- <goals>
- <goal>resources</goal>
- </goals>
- </execution>
- </executions>
+ <groupId>com.alexecollins.maven.plugin</groupId>
+ <artifactId>script-maven-plugin</artifactId>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.karaf.tooling</groupId>
+ <artifactId>karaf-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
- <executions>
- <execution>
- <id>attach-artifacts</id>
- <phase>package</phase>
- <goals>
- <goal>attach-artifact</goal>
- </goals>
- <configuration>
- <artifacts>
- <artifact>
- <file>${project.build.directory}/classes/${features.file}</file>
- <type>xml</type>
- <classifier>features</classifier>
- </artifact>
- </artifacts>
- </configuration>
- </execution>
- </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
</plugin>
</plugins>
</build>
+
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.opendaylight.yangtools</groupId>
+ <artifactId>yangtools-artifacts</artifactId>
+ <version>${project.version}</version>
+ <scope>import</scope>
+ <type>pom</type>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
<dependencies>
<dependency>
<groupId>org.opendaylight.yangtools.model</groupId>
<groupId>org.opendaylight.yangtools.model</groupId>
<artifactId>opendaylight-l2-types</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-ted</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools.model</groupId>
<artifactId>ietf-topology</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology-isis</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology-ospf</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.opendaylight.yangtools.model</groupId>
+ <artifactId>ietf-topology-l3-unicast-igp</artifactId>
+ </dependency>
<dependency>
<groupId>org.opendaylight.yangtools.thirdparty</groupId>
<artifactId>antlr4-runtime-osgi-nohead</artifactId>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-common</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>util</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>object-cache-api</artifactId>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-type-provider</artifactId>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-api</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-util</artifactId>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-parser-api</artifactId>
- </dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-client-api</artifactId>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
-
- <!-- test the features.xml -->
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>features-test</artifactId>
- <scope>test</scope>
- </dependency>
</dependencies>
</project>
<feature name='odl-yangtools-models' version='${project.version}' description='OpenDaylight :: Yangtools :: Models'>
<feature version='${project.version}'>odl-yangtools-binding</feature>
- <bundle>mvn:org.opendaylight.yangtools.model/ietf-inet-types/${ietf.inet.types.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools.model/ietf-yang-types/${ietf.yang.types.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools.model/ietf-yang-types-20130715/${ietf.yang.types.20130715.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools.model/ietf-restconf/${ietf.restconf.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools.model/yang-ext/${yang.ext.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools.model/opendaylight-l2-types/${opendaylight.l2.types.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools.model/ietf-topology/${ietf.topology.version}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-inet-types/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-yang-types/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-yang-types-20130715/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-restconf/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/yang-ext/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/opendaylight-l2-types/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-ted/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-topology/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-topology-isis/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-topology-ospf/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.model/ietf-topology-l3-unicast-igp/{{VERSION}}</bundle>
</feature>
<feature name='odl-yangtools-data-binding' version='${project.version}' description='OpenDaylight :: Yangtools :: Data Binding'>
<feature version='${project.version}'>odl-yangtools-binding</feature>
- <bundle>mvn:org.opendaylight.yangtools.thirdparty/antlr4-runtime-osgi-nohead/${antlr4.version}</bundle>
- <bundle>mvn:commons-io/commons-io/${commons.io.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-data-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-data-composite-node/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-data-impl/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-data-operations/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-data-util/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-model-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-model-util/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-parser-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-parser-impl/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.thirdparty/antlr4-runtime-osgi-nohead/{{VERSION}}</bundle>
+ <bundle>mvn:commons-io/commons-io/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-data-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-data-composite-node/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-data-impl/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-data-operations/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-data-util/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-model-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-model-util/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-parser-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-parser-impl/{{VERSION}}</bundle>
<!-- GSON-based JSON codec. Can be split out -->
- <bundle>mvn:com.google.code.gson/gson/${gson.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-data-codec-gson/${project.version}</bundle>
+ <bundle>mvn:com.google.code.gson/gson/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-data-codec-gson/{{VERSION}}</bundle>
</feature>
<feature name='odl-yangtools-binding' version='${project.version}' description='OpenDaylight :: Yangtools :: Binding'>
<feature version='${project.version}'>odl-yangtools-common</feature>
- <bundle>mvn:org.opendaylight.yangtools/yang-binding/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/util/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-binding/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/util/{{VERSION}}</bundle>
</feature>
<feature name='odl-yangtools-common' version='${project.version}' description='OpenDaylight :: Yangtools :: Common'>
- <bundle>mvn:com.google.guava/guava/${guava.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/concepts/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-common/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/util/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/object-cache-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/object-cache-guava/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/object-cache-noop/${project.version}</bundle>
+ <bundle>mvn:com.google.guava/guava/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/concepts/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-common/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/util/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/object-cache-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/object-cache-guava/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/object-cache-noop/{{VERSION}}</bundle>
</feature>
<feature name='odl-yangtools-binding-generator' version='${project.version}' description='OpenDaylight :: Yangtools :: Binding Generator'>
<feature version='${project.version}'>odl-yangtools-data-binding</feature>
- <bundle>mvn:org.javassist/javassist/${javassist.version}</bundle>
- <bundle>mvn:org.apache.commons/commons-lang3/${commons.lang3.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/binding-generator-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/binding-generator-impl/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/binding-generator-spi/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/binding-generator-util/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/binding-model-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/binding-type-provider/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/binding-data-codec/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools.thirdparty/xtend-lib-osgi/${xtend.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-model-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-model-util/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/yang-parser-api/${project.version}</bundle>
+ <bundle>mvn:org.javassist/javassist/{{VERSION}}</bundle>
+ <bundle>mvn:org.apache.commons/commons-lang3/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/binding-generator-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/binding-generator-impl/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/binding-generator-spi/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/binding-generator-util/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/binding-model-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/binding-type-provider/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/binding-data-codec/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools.thirdparty/xtend-lib-osgi/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-model-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-model-util/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/yang-parser-api/{{VERSION}}</bundle>
</feature>
<feature name='odl-yangtools-restconf' version='${project.version}' description='OpenDaylight :: Yangtools :: Restconf'>
- <bundle>mvn:org.opendaylight.yangtools/restconf-client-api/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/restconf-client-impl/${project.version}</bundle>
- <bundle>mvn:org.opendaylight.yangtools/restconf-common/${project.version}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/restconf-client-api/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/restconf-client-impl/{{VERSION}}</bundle>
+ <bundle>mvn:org.opendaylight.yangtools/restconf-common/{{VERSION}}</bundle>
</feature>
</features>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<packaging>bundle</packaging>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<packaging>bundle</packaging>
<parent>
<groupId>org.opendaylight.odlparent</groupId>
<artifactId>odlparent</artifactId>
- <version>1.4.2-SNAPSHOT</version>
+ <version>1.5.0-SNAPSHOT</version>
<relativePath></relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yangtools-parent</artifactId>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<packaging>pom</packaging>
<prerequisites>
<maven>3.0.4</maven>
</prerequisites>
<properties>
- <antlr4.version>4.0</antlr4.version>
<commons.io.version>2.4</commons.io.version>
<ctrie.version>0.2.0</ctrie.version>
<exam.version>3.0.0</exam.version>
<groovy.version>2.1.6</groovy.version>
- <yangtools.version>0.6.2-SNAPSHOT</yangtools.version>
- <ietf.topology.version>2013.10.21.2-SNAPSHOT</ietf.topology.version>
- <ietf.inet.types.version>2010.09.24.4-SNAPSHOT</ietf.inet.types.version>
- <ietf.yang.types.version>2010.09.24.4-SNAPSHOT</ietf.yang.types.version>
- <ietf.yang.types.20130715.version>2013.07.15.1-SNAPSHOT</ietf.yang.types.20130715.version>
- <ietf.restconf.version>2013.10.19.1-SNAPSHOT</ietf.restconf.version>
+ <yangtools.version>0.7.0-SNAPSHOT</yangtools.version>
<karaf.version>3.0.1</karaf.version>
<nexusproxy>http://nexus.opendaylight.org/content</nexusproxy>
- <opendaylight.l2.types.version>2013.08.27.4-SNAPSHOT</opendaylight.l2.types.version>
- <yang.ext.version>2013.09.07.4-SNAPSHOT</yang.ext.version>
<maven.javadoc.version>2.9.1</maven.javadoc.version>
<jsr305.version>2.0.1</jsr305.version>
+ <maven.depends.version>1.2</maven.depends.version>
<!-- Sonar config -->
<sonar-jacoco-listeners.version>2.4</sonar-jacoco-listeners.version>
<version>1.5</version>
<scope>test</scope>
</dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-util</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>maven-sal-api-gen-plugin</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.thirdparty</groupId>
- <artifactId>antlr4-runtime-osgi-nohead</artifactId>
- <version>4.0</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.thirdparty</groupId>
- <artifactId>xtend-lib-osgi</artifactId>
- <version>2.4.3</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>concepts</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>object-cache-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>object-cache-guava</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>object-cache-noop</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-model-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-spi</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-util</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-generator-impl</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-java-api-generator</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-common</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-impl</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-codec-gson</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-model-util</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-binding</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-parser-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-parser-impl</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-maven-plugin-spi</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-inet-types</artifactId>
- <version>${ietf.inet.types.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-yang-types</artifactId>
- <version>${ietf.yang.types.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-yang-types-20130715</artifactId>
- <version>${ietf.yang.types.20130715.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-restconf</artifactId>
- <version>${ietf.restconf.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-ted</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-topology</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-topology-isis</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-topology-l3-unicast-igp</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-topology-ospf</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-topology-l3-unicast</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-composite-node</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
- <artifactId>restconf-client-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>restconf-common</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>restconf-util</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>restconf-test-service</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>restconf-client-impl</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>restconf-jaxrs-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
-
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>bug527-test-model</artifactId>
+ <artifactId>yangtools-artifacts</artifactId>
<version>${yangtools.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>bug1196-test-model</artifactId>
- <version>${yangtools.version}</version>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>websocket-client</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
-
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>object-cache-api</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>object-cache-guava</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>object-cache-noop</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>util</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>opendaylight-l2-types</artifactId>
- <version>${opendaylight.l2.types.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>yang-ext</artifactId>
- <version>${yang.ext.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-type-provider</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>yang-data-operations</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>binding-data-codec</artifactId>
- <version>${yangtools.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools</groupId>
- <artifactId>features-test</artifactId>
- <version>${yangtools.version}</version>
- <scope>test</scope>
+ <scope>import</scope>
+ <type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<plugin>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-maven-plugin</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</execution>
</executions>
</plugin>
+ <plugin>
+ <groupId>org.eclipse.xtend</groupId>
+ <artifactId>xtend-maven-plugin</artifactId>
+ <version>${xtend.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>compile</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.servicemix.tooling</groupId>
+ <artifactId>depends-maven-plugin</artifactId>
+ <version>${maven.depends.version}</version>
+ <executions>
+ <execution>
+ <id>generate-depends-file</id>
+ <goals>
+ <goal>generate-depends-file</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</pluginManagement>
</executions>
</plugin>
-->
- <plugin>
- <groupId>org.eclipse.xtend</groupId>
- <artifactId>xtend-maven-plugin</artifactId>
- <version>${xtend.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>compile</goal>
- </goals>
- <configuration>
- <outputDirectory>${basedir}/src/main/xtend-gen</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>2.5</version>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
+ <version>0.7.2.201409121644</version>
<executions>
<execution>
<id>prepare-ut-agent</id>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>parent</relativePath>
</parent>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>common-aggregator</artifactId>
<packaging>pom</packaging>
<modules>
+ <module>artifacts</module>
<module>checkstyle-logging</module>
<module>concepts</module>
<module>features</module>
+ <module>features-builder</module>
<module>features-test</module>
<module>mockito-configuration</module>
<module>object-cache-api</module>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<packaging>bundle</packaging>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>mockito-configuration</artifactId>
<scope>test</scope>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
@Deprecated
public class DurationStatsTracker extends ConcurrentDurationStatisticsTracker {
/**
- * @deprecated Use {@link DurationStatisticsTracker#createConcurrent() instead.
+ * @deprecated Use {@link DurationStatisticsTracker#createConcurrent()} instead.
*/
@Deprecated
public DurationStatsTracker() {
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-binding</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yang-common</artifactId>
- <version>0.6.2-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>yang-ext</artifactId>
- <version>2013.09.07.4-SNAPSHOT</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-inet-types</artifactId>
- <version>2010.09.24.4-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</dependency>
</dependencies>
</plugin>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<artifactId>yangtools-parent</artifactId>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<dependency>
<groupId>org.opendaylight.yangtools.thirdparty</groupId>
<artifactId>antlr4-runtime-osgi-nohead</artifactId>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.opendaylight.yangtools.thirdparty</groupId>
<artifactId>xtend-lib-osgi</artifactId>
+ <scope>test</scope>
</dependency>
</dependencies>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../common/parent</relativePath>
</parent>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>integration-tests-aggregator</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<artifactId>yangtools-parent</artifactId>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<artifactId>model-iana</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iana-afn-safi</artifactId>
- <version>2013.07.04.4-SNAPSHOT</version>
+ <version>2013.07.04.7-SNAPSHOT</version>
<build>
<plugins>
<parent>
<artifactId>model-iana</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>iana-if-type</artifactId>
- <version>2013.07.04.4-SNAPSHOT</version>
+ <version>2013.07.04.7-SNAPSHOT</version>
<build>
<plugins>
<parent>
<artifactId>model-parent</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-inet-types</artifactId>
- <version>2010.09.24.4-SNAPSHOT</version>
+ <version>2010.09.24.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-restconf</artifactId>
- <version>2013.10.19.1-SNAPSHOT</version>
+ <version>2013.10.19.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<dependency>
<groupId>org.opendaylight.yangtools.model</groupId>
<artifactId>ietf-yang-types-20130715</artifactId>
- <version>2013.07.15.1-SNAPSHOT</version>
</dependency>
<dependency>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-ted</artifactId>
- <version>2013.10.21.2-SNAPSHOT</version>
+ <version>2013.10.21.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-topology-isis</artifactId>
- <version>2013.10.21.2-SNAPSHOT</version>
+ <version>2013.10.21.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-topology-l3-unicast-igp</artifactId>
- <version>2013.10.21.2-SNAPSHOT</version>
+ <version>2013.10.21.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-topology-ospf</artifactId>
- <version>2013.10.21.2-SNAPSHOT</version>
+ <version>2013.10.21.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-topology</artifactId>
- <version>2013.10.21.2-SNAPSHOT</version>
+ <version>2013.10.21.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-yang-types-20130715</artifactId>
- <version>2013.07.15.1-SNAPSHOT</version>
+ <version>2013.07.15.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-ietf</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>ietf-yang-types</artifactId>
- <version>2010.09.24.4-SNAPSHOT</version>
+ <version>2010.09.24.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<artifactId>model-parent</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<module>ietf-restconf</module>
<!--module>ietf-netconf</module -->
</modules>
-
- <dependencyManagement>
- <dependencies>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-inet-types</artifactId>
- <version>${ietf.inet.types.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-yang-types</artifactId>
- <version>${ietf.yang.types.version}</version>
- </dependency>
- <dependency>
- <groupId>org.opendaylight.yangtools.model</groupId>
- <artifactId>ietf-restconf</artifactId>
- <version>${ietf.restconf.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ietf-ted</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ietf-topology</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ietf-topology-isis</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ietf-topology-l3-unicast-igp</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- <dependency>
- <groupId>${project.groupId}</groupId>
- <artifactId>ietf-topology-ospf</artifactId>
- <version>${ietf.topology.version}</version>
- </dependency>
- </dependencies>
- </dependencyManagement>
- </project>
+</project>
<parent>
<artifactId>model-parent</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>opendaylight-l2-types</artifactId>
- <version>2013.08.27.4-SNAPSHOT</version>
+ <version>2013.08.27.7-SNAPSHOT</version>
<build>
<plugins>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../common/parent</relativePath>
</parent>
<groupId>org.opendaylight.yangtools.model</groupId>
- <!--<version>0.6.2-SNAPSHOT</version>-->
+ <!--<version>0.7.0-SNAPSHOT</version>-->
<modelVersion>4.0.0</modelVersion>
<artifactId>model-parent</artifactId>
<packaging>pom</packaging>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>maven-sal-api-gen-plugin</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
<parent>
<artifactId>model-parent</artifactId>
<groupId>org.opendaylight.yangtools.model</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yang-ext</artifactId>
- <version>2013.09.07.4-SNAPSHOT</version>
+ <version>2013.09.07.7-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>${project.artifactId}</description>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>common/parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>yangtools-aggregator</artifactId>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<packaging>pom</packaging>
<scm>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../common/parent</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>restconf-client-impl</artifactId>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>restconf-common</artifactId>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>restconf-jaxrs-api</artifactId>
<name>restconf-jaxrs-api</name>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>restconf-test-service</artifactId>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>restconf-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
</parent>
<artifactId>restconf-util</artifactId>
<dependency>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>binding-data-codec</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>third-party-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>third-party-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../common/parent</relativePath>
</parent>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<artifactId>websocket-aggregator</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>../common/parent</relativePath>
</parent>
<groupId>org.opendaylight.yangtools</groupId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<modelVersion>4.0.0</modelVersion>
<artifactId>yang-aggregator</artifactId>
<packaging>pom</packaging>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
* </ul>
*
*
- * @see http://tools.ietf.org/html/rfc6020#section-9.13
+ * @see <a href="http://tools.ietf.org/html/rfc6020#section-9.13">RFC6020</a>
*/
public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier>, Immutable, Serializable {
@SuppressWarnings("rawtypes")
return new BuilderImpl(origin.getPathArguments(), origin.hashCode());
}
- /**
- * Returns new builder for InstanceIdentifier with first path argument set to {@link NodeIdentifier}.
- *
- * @param node QName of first {@link NodeIdentifier} path argument.
- * @return new builder for InstanceIdentifier with first path argument set to {@link NodeIdentifier}.
- *
- * @deprecated Either use {@link #node(QName)} or instantiate an intermediate builder.
- */
- @Deprecated
- public static InstanceIdentifierBuilder builder(final QName node) {
- return builder().node(node);
- }
-
/**
* Path argument / component of InstanceIdentifier
*
* / module to the target node.
*
*
- * @see http://tools.ietf.org/html/rfc6020#section-7.15
+ * @see <a href="http://tools.ietf.org/html/rfc6020#section-7.15">RFC6020</a>
*/
public static final class AugmentationIdentifier implements PathArgument {
private static final long serialVersionUID = -8122335594681936939L;
this.childNames = ImmutableSet.copyOf(childNames);
}
- /**
- * Augmentation node has no QName
- *
- * @deprecated Use
- * {@link AugmentationIdentifier#AugmentationIdentifier(Set)}
- * instead.
- */
- @Deprecated
- public AugmentationIdentifier(final QName nodeType, final Set<QName> childNames) {
- this(childNames);
- }
-
/**
* Returns set of all possible child nodes
*
assertEquals( "PathArg 3 node type", nodeName3, it.next().getNodeType() );
assertEquals( "PathArg 4 node type", nodeName4, it.next().getNodeType() );
- newID = YangInstanceIdentifier.builder( nodeName1 ).build();
+ newID = YangInstanceIdentifier.builder().node( nodeName1 ).build();
assertNotNull( "InstanceIdentifier is null", newID );
assertEquals( "Path size", 1, Iterables.size(newID.getPathArguments()) );
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
import com.google.common.base.Preconditions;
import com.google.common.base.Strings;
import com.google.gson.stream.JsonWriter;
-import java.io.IOException;
-import java.io.Writer;
-import java.net.URI;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.AugmentationIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import java.io.IOException;
+import java.io.Writer;
+import java.net.URI;
+
/**
* This implementation will create JSON output as output stream.
*
/**
* Matcher used to check if a string needs to be escaped.
*/
- private static final CharMatcher QUOTES_OR_BACKSLASH = CharMatcher.anyOf("\\\"");
+ private static final CharMatcher JSON_ILLEGAL_STRING_CHARACTERS = CharMatcher.anyOf("\\\"\n\r");
private final SchemaTracker tracker;
private final JSONCodecFactory codecs;
if (needQuotes) {
writer.append('"');
- final int needEscape = QUOTES_OR_BACKSLASH.countIn(str);
+ final int needEscape = JSON_ILLEGAL_STRING_CHARACTERS.countIn(str);
if (needEscape != 0) {
final char[] escaped = new char[str.length() + needEscape];
int offset = 0;
for (int i = 0; i < str.length(); i++) {
final char c = str.charAt(i);
- if (QUOTES_OR_BACKSLASH.matches(c)) {
+ if (JSON_ILLEGAL_STRING_CHARACTERS.matches(c)) {
escaped[offset++] = '\\';
}
escaped[offset++] = c;
*/
package org.opendaylight.yangtools.yang.data.codec.gson;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.childArray;
-import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.childPrimitive;
-import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadModules;
-import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.resolveCont1;
-
import com.google.common.collect.Sets;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URISyntaxException;
-import java.util.HashSet;
-import java.util.Iterator;
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
import org.opendaylight.yangtools.yang.data.api.schema.stream.NormalizedNodeWriter;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URISyntaxException;
+import java.util.HashSet;
+import java.util.Iterator;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.childArray;
+import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.childPrimitive;
+import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.loadModules;
+import static org.opendaylight.yangtools.yang.data.codec.gson.TestUtils.resolveCont1;
+
/**
* Each test tests whether json output obtained after transformation contains is corect. The transformation takes
* normalized node data structure and transform it to json output. To make it easier validate json output it is loaded
}
+ @Test
+ public void leafListNodeInContainerMultiline() throws IOException, URISyntaxException {
+ Writer writer = new StringWriter();
+ NormalizedNode<?, ?> leafListNodeInContainer = TestingNormalizedNodeStructuresCreator.leafListNodeInContainerMultiline();
+ String jsonOutput = normalizedNodeToJsonStreamTransformation(writer, leafListNodeInContainer);
+ new JsonValidator() {
+
+ @Override
+ public void validate(String jsonOutput) {
+ JsonObject cont1 = resolveCont1(jsonOutput);
+ assertNotNull(cont1);
+ JsonArray lflst11 = childArray(cont1, "complexjson:lflst11", "lflst11");
+ assertNotNull(lflst11);
+
+ HashSet<Object> lflst11Values = Sets.newHashSet();
+ for (JsonElement jsonElement : lflst11) {
+ assertTrue(jsonElement instanceof JsonPrimitive);
+ lflst11Values.add(((JsonPrimitive) jsonElement).getAsString());
+ }
+
+ assertEquals(Sets.newHashSet("lflst11 value2\r\nanother line 2", "lflst11 value1\nanother line 1"), lflst11Values);
+ }
+ }.validate(jsonOutput);
+
+ }
+
@Test
public void leafNodeViaAugmentationInContainer() throws IOException, URISyntaxException {
Writer writer = new StringWriter();
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
-import java.util.HashMap;
-import java.util.Map;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.CompositeNode;
import org.opendaylight.yangtools.yang.data.api.SimpleNode;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
+import java.util.HashMap;
+import java.util.Map;
+
public class TestingNormalizedNodeStructuresCreator {
static NormalizedNode<?, ?> cont1Node(
return lflst11.build();
}
+ private static DataContainerChild<? extends PathArgument, ?> childLflst11Multiline() {
+ ListNodeBuilder<Object, LeafSetEntryNode<Object>> lflst11 = Builders.leafSetBuilder().withNodeIdentifier(
+ new NodeIdentifier(QName.create("ns:complex:json", "2014-08-11", "lflst11")));
+ lflst11.withChild(Builders
+ .leafSetEntryBuilder()
+ .withNodeIdentifier(
+ new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value1\nanother line 1"))
+ .withValue("lflst11 value1\nanother line 1").build());
+ lflst11.withChild(Builders
+ .leafSetEntryBuilder()
+ .withNodeIdentifier(
+ new NodeWithValue(QName.create("ns:complex:json", "2014-08-11", "lflst11"), "lflst11 value2\r\nanother line 2"))
+ .withValue("lflst11 value2\r\nanother line 2").build());
+ return lflst11.build();
+ }
+
private static CompositeNode prepareLf12Value() {
SimpleNode<?> anyxmlInData = NodeFactory.createImmutableSimpleNode(
QName.create("ns:complex:json", "2014-08-11", "anyxml-in-data"), null, "foo");
public static NormalizedNode<?, ?> leafListNodeInContainer() {
return cont1Node(childLflst11());
}
+ public static NormalizedNode<?, ?> leafListNodeInContainerMultiline() {
+ return cont1Node(childLflst11Multiline());
+ }
public static NormalizedNode<?, ?> keyedListNodeInContainer() {
return cont1Node(childLst11());
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Preconditions;
import java.net.URI;
+import java.util.Collection;
+import java.util.Collections;
import java.util.Map;
import java.util.Map.Entry;
import javax.annotation.Nonnull;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
}
} else {
// CompositeNode
- for (Node<?> child : ((CompositeNode) data).getValue()) {
- DataSchemaNode childSchema = null;
- if (schema instanceof DataNodeContainer) {
- childSchema = SchemaUtils.findFirstSchema(child.getNodeType(), ((DataNodeContainer) schema).getChildNodes()).orNull();
- } else if ((childSchema == null) && LOG.isDebugEnabled()) {
- LOG.debug("Probably the data node \"{}\" does not conform to schema", child == null ? "" : child.getNodeType().getLocalName());
+ final CompositeNode castedData = ((CompositeNode) data);
+ final DataNodeContainer castedSchema;
+ if (schema instanceof DataNodeContainer) {
+ castedSchema = (DataNodeContainer) schema;
+ } else {
+ castedSchema = null;
+ }
+ final Collection<QName> keyLeaves;
+ if (schema instanceof ListSchemaNode) {
+ keyLeaves = ((ListSchemaNode) schema).getKeyDefinition();
+
+ } else {
+ keyLeaves = Collections.emptyList();
+
+ }
+ for (QName key : keyLeaves) {
+ SimpleNode<?> keyLeaf = castedData.getFirstSimpleByName(key);
+ if(keyLeaf != null) {
+ writeChildElement(writer,keyLeaf,castedSchema);
}
- writeElement(writer, child, childSchema);
+ }
+
+ for (Node<?> child : castedData.getValue()) {
+ if(keyLeaves.contains(child.getNodeType())) {
+ // Skip key leaf which was written by previous for loop.
+ continue;
+ }
+ writeChildElement(writer,child,castedSchema);
+ }
+ }
+ }
+
+ private void writeChildElement(XMLStreamWriter writer, Node<?> child, DataNodeContainer parentSchema) throws XMLStreamException {
+ DataSchemaNode childSchema = null;
+ if (parentSchema != null) {
+ childSchema = SchemaUtils.findFirstSchema(child.getNodeType(), parentSchema.getChildNodes()).orNull();
+ if ((childSchema == null) && LOG.isDebugEnabled()) {
+ LOG.debug("Probably the data node \"{}\" does not conform to schema", child == null ? "" : child.getNodeType().getLocalName());
}
}
+ writeElement(writer, child, childSchema);
}
private static void writeAttributes(final XMLStreamWriter writer, final AttributesContainer data, final RandomPrefix randomPrefix) throws XMLStreamException {
*/
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
+import com.google.common.base.Objects;
+import com.google.common.base.Objects.ToStringHelper;
+import com.google.common.collect.ImmutableMap;
import java.util.Map;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.AttributesContainer;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
-import com.google.common.base.Objects.ToStringHelper;
-import com.google.common.collect.ImmutableMap;
-
public abstract class AbstractImmutableNormalizedValueAttrNode<K extends YangInstanceIdentifier.PathArgument,V>
extends AbstractImmutableNormalizedValueNode<K, V>
implements AttributesContainer {
@Override
protected int valueHashCode() {
- final int result = getValue().hashCode();
+ final int result = getValue() != null ? getValue().hashCode() : 1;
// FIXME: are attributes part of hashCode/equals?
// for (final Entry<?, ?> a : attributes.entrySet()) {
// result = 31 * result + a.hashCode();
@Override
protected boolean valueEquals(final AbstractImmutableNormalizedNode<?, ?> other) {
- if (!getValue().equals(other.getValue())) {
+ // We can not call directly getValue.equals because of Empty Type Definition leaves
+ // which allways have NULL value
+ if (!Objects.equal(getValue(), other.getValue())) {
return false;
}
*/
package org.opendaylight.yangtools.yang.data.impl.schema.nodes;
+import javax.annotation.Nullable;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
AbstractImmutableNormalizedNode<K, V> {
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractImmutableNormalizedValueNode.class);
+ @Nullable
private final V value;
protected AbstractImmutableNormalizedValueNode(final K nodeIdentifier, final V value) {
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
* grouping where it was defined.
*
* @return original node definition from grouping if this node is added by
- * uses, null otherwise
+ * uses, Optional.absent otherwise
*/
Optional<? extends SchemaNode> getOriginal();
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
* Revision Date
* @return Schema Path
*
- * @deprecated Use {@link SchemaPath#create(boolean, Iterable)} with QNames
+ * @deprecated Use {@link SchemaPath#create(Iterable, boolean)} with QNames
* manually constructed.
*/
@Deprecated
* Noop schema provider returns {@link Optional#absent()} for each call to
* query schema source.
*
- * @return
+ * @return A reusable no-operation provider.
*/
@SuppressWarnings("unchecked")
public static <T> SchemaSourceProvider<T> noopProvider() {
* supplied String based schema source provider.
*
* @param delegate
- * @return
+ * @return InputStream-based source provider.
*/
public static SchemaSourceProvider<InputStream> inputStreamProviderfromStringProvider(
final AdvancedSchemaSourceProvider<String> delegate) {
*
* This implementation is really simple <code>return input;</code>.
*
- * @return
+ * @return Identity transformation.
*/
@SuppressWarnings("unchecked")
public static <I> SchemaSourceTransformation<I, I> identityTransformation() {
--- /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.yang.model.util;
+
+import static org.junit.Assert.*;
+
+import java.util.Date;
+
+import org.opendaylight.yangtools.yang.model.api.ModuleImport;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ModuleImportImplTest {
+
+ private ModuleImport module1, module2, module3, module4, module5;
+ private int hash1, hash2;
+ private Date now;
+
+ @Before
+ public void setup() {
+ now = new Date();
+ module1 = new ModuleImportImpl("myModule", now, "myPrefix");
+ module2 = new ModuleImportImpl(null, null, null);
+ module3 = new ModuleImportImpl("myModule", null, "customPrefix");
+ module4 = new ModuleImportImpl("myModule", now, null);
+ module5 = new ModuleImportImpl("myModule", now, "myPrefix");
+ hash1 = module1.hashCode();
+ hash2 = module2.hashCode();
+ }
+
+ @Test
+ public void testModule() {
+ assertNotNull(module1);
+ assertTrue(module1.getModuleName().equals("myModule"));
+ assertTrue(module1.getPrefix().equals("myPrefix"));
+ assertTrue(module1.getRevision().equals(now));
+ assertFalse(module1.equals(module2));
+ }
+
+ @Test
+ public void testToString() {
+ String toString = module1.toString();
+ assertTrue(toString.contains("ModuleImport"));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertTrue(!(hash1 == hash2));
+ }
+
+ @Test
+ public void testEquals() {
+ assertTrue(module1.equals(module1));
+ assertFalse(module1.equals(module2));
+ assertFalse(module1.equals(""));
+ assertFalse(module2.equals(module1));
+ assertFalse(module1.equals(null));
+ assertFalse(module1.equals(module3));
+ assertFalse(module3.equals(module1));
+ assertFalse(module1.equals(module4));
+ assertFalse(module4.equals(module1));
+ assertTrue(module1.equals(module5));
+ }
+
+}
--- /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.yang.model.util;
+
+import com.google.common.base.Optional;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
+import org.mockito.MockitoAnnotations;
+import org.mockito.Mock;
+import org.junit.Before;
+import org.opendaylight.yangtools.yang.model.api.DerivableSchemaNode;
+import org.junit.Test;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doReturn;
+import static org.hamcrest.CoreMatchers.instanceOf;
+
+public class SchemaNodeUtilsTest {
+
+ @Mock
+ private DerivableSchemaNode derivableNode;
+
+ @Before
+ public void setup() {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testHandleNullGetOriginalIfPossible() {
+ Optional<SchemaNode> originalIfPossible = SchemaNodeUtils
+ .getOriginalIfPossible(null);
+ assertNotNull(originalIfPossible);
+ assertThat(originalIfPossible, instanceOf(Optional.class));
+ }
+
+ @Test
+ public void testHandleNodeGetOriginalIfPossible() {
+ Optional<DerivableSchemaNode> of = Optional.of(derivableNode);
+ doReturn(of).when(derivableNode).getOriginal();
+ Optional<SchemaNode> originalIfPossible = SchemaNodeUtils
+ .getOriginalIfPossible(derivableNode);
+ assertNotNull(originalIfPossible);
+ assertThat(originalIfPossible, instanceOf(Optional.class));
+ }
+
+ @Test
+ public void testHandleNullGetRootOriginalIfPossible() {
+ SchemaNode rootOriginalIfPossible = SchemaNodeUtils
+ .getRootOriginalIfPossible(null);
+ assertNull(rootOriginalIfPossible);
+ }
+}
--- /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.yang.model.util;
+
+import static org.junit.Assert.*;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import java.sql.Types;
+import org.opendaylight.yangtools.yang.model.api.Status;
+import org.junit.Before;
+import org.junit.Test;
+
+public class StringTypeTest {
+
+ private StringType string;
+ private int hash;
+
+ @Before
+ public void setup() {
+ string = StringType.getInstance();
+ hash = string.hashCode();
+ }
+
+ @Test
+ public void testGetBaseTypeShouldReturnNull() {
+ assertTrue(string.getBaseType() == null);
+ }
+
+ @Test
+ public void testGetters() {
+ assertEquals(string.getUnits(), "");
+ assertEquals(string.getDefaultValue(), "");
+ assertEquals(string.getDescription(), "");
+ assertEquals(string.getReference(), "");
+ assertEquals(string.getQName(), BaseTypes.STRING_QNAME);
+ assertEquals(string.getStatus(), Status.CURRENT);
+
+ SchemaPath path = SchemaPath.create(true, string.getQName());
+ assertEquals(string.getPath(), path);
+
+ assertNotNull(string.getLengthConstraints());
+ assertNotNull(string.getPatternConstraints());
+ assertNotNull(string.getUnknownSchemaNodes());
+ }
+
+ @Test
+ public void testToString() {
+ String toString = string.toString();
+ assertTrue(toString.contains("StringType"));
+ }
+
+ @Test
+ public void testEquals() {
+ assertTrue(string.equals(string));
+ assertFalse(string.equals(null));
+ assertFalse(string.equals(Types.DOUBLE));
+ }
+}
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
<parent>
<groupId>org.opendaylight.yangtools</groupId>
<artifactId>yangtools-parent</artifactId>
- <version>0.6.2-SNAPSHOT</version>
+ <version>0.7.0-SNAPSHOT</version>
<relativePath>/../../common/parent/pom.xml</relativePath>
</parent>
*/
int getOrder();
+ /**
+ * Set true if target of augment is unsupported (e.g. node in body of extension).
+ * In such case, augmentation is skipped and AugmentationSchema is not built.
+ */
+ public void setUnsupportedTarget(boolean unsupportedTarget);
+
+ /**
+ * Return true if target of augment is unsupported (e.g. node in body of extension).
+ * In such case, augmentation is skipped and AugmentationSchema is not built.
+ */
+ public boolean isUnsupportedTarget();
+
}
private final SchemaPath targetPath;
private boolean resolved;
+ private boolean unsupportedTarget = false;
+
private AugmentationSchemaBuilder copyOf;
public AugmentationSchemaBuilderImpl(final String moduleName, final int line, final String augmentTargetStr,
this.resolved = resolved;
}
+ /**
+ * Set true if target of augment is unsupported (e.g. node in body of extension).
+ * In such case, augmentation is skipped and AugmentationSchema is not built.
+ */
+ @Override
+ public void setUnsupportedTarget(boolean unsupportedTarget) {
+ this.unsupportedTarget = unsupportedTarget;
+ }
+
+ /**
+ * Return true if target of augment is unsupported (e.g. node in body of extension).
+ * In such case, augmentation is skipped and AugmentationSchema is not built.
+ */
+ @Override
+ public boolean isUnsupportedTarget() {
+ return unsupportedTarget;
+ }
+
@Override
public String getWhenCondition() {
return whenCondition;
*/
package org.opendaylight.yangtools.yang.parser.builder.impl;
+import com.google.common.base.Optional;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableSet;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationTargetBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.ConstraintsBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.DataSchemaNodeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.api.GroupingBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.SchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
import org.opendaylight.yangtools.yang.parser.builder.api.UnknownSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.util.AbstractDocumentedDataNodeContainerBuilder;
import org.opendaylight.yangtools.yang.parser.util.YangParseException;
-import com.google.common.base.Optional;
-import com.google.common.base.Preconditions;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableSet;
-
public final class ChoiceCaseBuilder extends AbstractDocumentedDataNodeContainerBuilder implements DataSchemaNodeBuilder,
AugmentationTargetBuilder {
private ChoiceCaseNodeImpl instance;
throw new YangParseException(getModuleName(), typedefBuilder.getLine(), "Can not add type definition to choice case.");
}
+ @Override
+ public void addGrouping(GroupingBuilder groupingBuilder) {
+ throw new YangParseException(getModuleName(), groupingBuilder.getLine(), "Can not add grouping to choice case.");
+ }
+
@Override
public boolean isConfiguration() {
return false;
for (DataSchemaNodeBuilder childNode : old.getChildNodeBuilders()) {
copy.addChildNode(copy(childNode, copy, updateQName));
}
- copy.getGroupings().addAll(old.getGroupings());
- for (GroupingBuilder grouping : old.getGroupingBuilders()) {
- copy.addGrouping(copy(grouping, copy, updateQName));
- }
- for (TypeDefinitionBuilder tdb : old.getTypeDefinitionBuilders()) {
- copy.addTypedef(copy(tdb, copy, updateQName));
- }
for (UsesNodeBuilder oldUses : old.getUsesNodeBuilders()) {
copy.addUsesNode(copyUses(oldUses, copy));
}
private static DataBean getdata(final SchemaNodeBuilder old, final Builder newParent, final boolean updateQName) {
final SchemaPath newSchemaPath;
+ // this check avoid NPE because if old is IdentityrefTypeBuilder, old.getQNname() return null
+ final boolean identityrefTypeCheck = old instanceof IdentityrefTypeBuilder ? false : updateQName;
+
QName newQName = null;
if (newParent instanceof ModuleBuilder) {
ModuleBuilder parent = (ModuleBuilder) newParent;
- if (updateQName) {
+ if (identityrefTypeCheck) {
newQName = QName.create(parent.getQNameModule(), parent.getPrefix(), old.getQName()
.getLocalName());
} else {
} else if (newParent instanceof AugmentationSchemaBuilder) {
AugmentationSchemaBuilder augment = (AugmentationSchemaBuilder) newParent;
ModuleBuilder parent = BuilderUtils.getParentModule(newParent);
- if (updateQName) {
+ if (identityrefTypeCheck) {
newQName = QName.create(parent.getQNameModule(), parent.getPrefix(), old.getQName()
.getLocalName());
} else {
} else if (newParent instanceof SchemaNodeBuilder) {
SchemaNodeBuilder parent = (SchemaNodeBuilder) newParent;
QName parentQName = parent.getQName();
- if (updateQName) {
+ if (identityrefTypeCheck) {
newQName = QName.create(parentQName, old.getQName().getLocalName());
} else {
newQName = old.getQName();
// AUGMENTATIONS
final Set<AugmentationSchema> augments = new HashSet<>();
for (AugmentationSchemaBuilder builder : augmentationBuilders) {
- augments.add(builder.build());
+ if (!builder.isUnsupportedTarget())
+ augments.add(builder.build());
}
instance.augmentations = ImmutableSet.copyOf(augments);
}
@Override
- public final void addGrouping(final GroupingBuilder grouping) {
+ public void addGrouping(final GroupingBuilder grouping) {
checkNotSealed();
QName groupingName = grouping.getQName();
for (GroupingBuilder addedGrouping : addedGroupings) {
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
-import com.google.common.base.Splitter;
import com.google.common.collect.HashBiMap;
import com.google.common.io.ByteSource;
import java.io.File;
import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.YangContext;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
+import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ExtensionDefinition;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
import org.opendaylight.yangtools.yang.parser.builder.api.AugmentationSchemaBuilder;
@Immutable
public final class YangParserImpl implements YangContextParser {
private static final Logger LOG = LoggerFactory.getLogger(YangParserImpl.class);
- private static final Splitter COLON_SPLITTER = Splitter.on(':');
private static final YangParserImpl INSTANCE = new YangParserImpl();
public static YangParserImpl getInstance() {
resolveUsesForNodes(modules);
resolveAugments(modules);
resolveIdentities(modules);
+ checkChoiceCasesForDuplicityQNames(modules);
// build
final Map<ModuleBuilder, Module> result = new LinkedHashMap<>();
"Error in module {} at line {}: Unsupported augment target: {}. Augmentation process skipped.",
module.getName(), augment.getLine(), potentialTargetNode);
augment.setResolved(true);
+ augment.setUnsupportedTarget(true);
return true;
}
} else {
return null;
}
+
+ /**
+ * Traverse through modules and check if choice has choice cases with the
+ * same qname.
+ *
+ * @param modules
+ * all loaded modules
+ */
+ private void checkChoiceCasesForDuplicityQNames(final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ for (Map.Entry<URI, TreeMap<Date, ModuleBuilder>> entry : modules.entrySet()) {
+ for (Map.Entry<Date, ModuleBuilder> childEntry : entry.getValue().entrySet()) {
+ final ModuleBuilder moduleBuilder = childEntry.getValue();
+ final Module module = moduleBuilder.build();
+ final List<ChoiceNode> allChoicesFromModule = getChoicesFrom(module);
+
+ for (ChoiceNode choiceNode : allChoicesFromModule) {
+ findDuplicityNodesIn(choiceNode, module, moduleBuilder, modules);
+ }
+ }
+ }
+ }
+
+ private void findDuplicityNodesIn(final ChoiceNode choiceNode, final Module module, final ModuleBuilder moduleBuilder,
+ final Map<URI, TreeMap<Date, ModuleBuilder>> modules) {
+ final Set<QName> duplicityTestSet = new HashSet<QName>();
+
+ for (ChoiceCaseNode choiceCaseNode : choiceNode.getCases()) {
+
+ for (DataSchemaNode childSchemaNode : choiceCaseNode.getChildNodes()) {
+ if (!duplicityTestSet.add(childSchemaNode.getQName())) {
+ final Optional<SchemaNodeBuilder> schemaNodeBuilder = BuilderUtils.findSchemaNodeInModule(childSchemaNode.getPath(), moduleBuilder);
+ final String nameOfSchemaNode = childSchemaNode.getQName().getLocalName();
+ int lineOfSchemaNode = 0;
+
+ if (schemaNodeBuilder.isPresent()) {
+ lineOfSchemaNode = schemaNodeBuilder.get().getLine();
+ }
+ throw new YangParseException(module.getName(), lineOfSchemaNode,
+ String.format("Choice has two nodes case with same qnames - %s", nameOfSchemaNode));
+ }
+ }
+ }
+ }
+
+ private List<ChoiceNode> getChoicesFrom(final Module module) {
+ final List<ChoiceNode> allChoices = new ArrayList<ChoiceNode>();
+
+ for (DataSchemaNode dataSchemaNode : module.getChildNodes()) {
+ findChoicesIn(dataSchemaNode, allChoices);
+ }
+ return allChoices;
+ }
+
+ private void findChoicesIn(final SchemaNode schemaNode, final Collection<ChoiceNode> choiceNodes) {
+ if (schemaNode instanceof ContainerSchemaNode) {
+ final ContainerSchemaNode contSchemaNode = (ContainerSchemaNode) schemaNode;
+ for (DataSchemaNode dataSchemaNode : contSchemaNode.getChildNodes()) {
+ findChoicesIn(dataSchemaNode, choiceNodes);
+ }
+ } else if (schemaNode instanceof ListSchemaNode) {
+ final ListSchemaNode listSchemaNode = (ListSchemaNode) schemaNode;
+ for (DataSchemaNode dataSchemaNode : listSchemaNode.getChildNodes()) {
+ findChoicesIn(dataSchemaNode, choiceNodes);
+ }
+ } else if (schemaNode instanceof ChoiceNode) {
+ choiceNodes.add((ChoiceNode) schemaNode);
+ }
+ }
+
}
import java.util.Date;
import java.util.Iterator;
import java.util.Map;
+import java.util.Map.Entry;
import java.util.Set;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
} while (progress);
/// Additional check only for belongs-to statement
- for (final SourceIdentifier sourceIdentifier : submodules.keySet()) {
- final BelongsToDependency belongs = submodules.get(sourceIdentifier);
+ for (final Entry<SourceIdentifier, BelongsToDependency> submodule : submodules.entrySet()) {
+ final BelongsToDependency belongs = submodule.getValue();
+ final SourceIdentifier sourceIdentifier = submodule.getKey();
if (!isKnown(resolved, belongs)) {
LOG.debug("Source {} is missing parent {}", sourceIdentifier, belongs);
pending.add(sourceIdentifier);
import com.google.common.base.Function;
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
+import com.google.common.base.Predicate;
import com.google.common.cache.Cache;
import com.google.common.cache.CacheBuilder;
import com.google.common.collect.Collections2;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
+import com.google.common.collect.Sets;
import com.google.common.util.concurrent.AsyncFunction;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.ListenableFuture;
import java.net.URI;
import java.util.Collection;
+import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import java.util.Set;
import java.util.TreeMap;
+import javax.annotation.Nullable;
import org.antlr.v4.runtime.ParserRuleContext;
import org.antlr.v4.runtime.tree.ParseTreeWalker;
import org.opendaylight.yangtools.util.concurrent.ExceptionMapper;
final Map<SourceIdentifier, ParserRuleContext> asts =
Maps.transformValues(srcs, ASTSchemaSource.GET_AST);
final Map<String, TreeMap<Date, URI>> namespaceContext = BuilderUtils.createYangNamespaceContext(
- asts.values(), Optional.<SchemaContext> absent());
+ asts.values(), Optional.<SchemaContext>absent());
final ParseTreeWalker walker = new ParseTreeWalker();
final Map<SourceIdentifier, ModuleBuilder> sourceToBuilder = new LinkedHashMap<>();
- for (Entry<SourceIdentifier, ParserRuleContext> entry : asts.entrySet()) {
- ModuleBuilder moduleBuilder = YangParserListenerImpl.create(namespaceContext, entry.getKey().getName(),
+ for (final Entry<SourceIdentifier, ParserRuleContext> entry : asts.entrySet()) {
+ final ModuleBuilder moduleBuilder = YangParserListenerImpl.create(namespaceContext, entry.getKey().getName(),
walker, entry.getValue()).getModuleBuilder();
moduleBuilder.setSource(srcs.get(entry.getKey()).getYangText());
// FIXME: ignored right now
private final SchemaSourceFilter filter;
+ // FIXME SchemaRepository should be the type for repository parameter instead of SharedSchemaRepository (final implementation)
public SharedSchemaContextFactory(final SharedSchemaRepository repository, final SchemaSourceFilter filter) {
this.repository = Preconditions.checkNotNull(repository);
this.filter = Preconditions.checkNotNull(filter);
@Override
public CheckedFuture<SchemaContext, SchemaResolutionException> createSchemaContext(final Collection<SourceIdentifier> requiredSources) {
- final SchemaContext existing = cache.getIfPresent(requiredSources);
+ // Make sources unique
+ final List<SourceIdentifier> uniqueSourceIdentifiers = deDuplicateSources(requiredSources);
+
+ final SchemaContext existing = cache.getIfPresent(uniqueSourceIdentifiers);
if (existing != null) {
LOG.debug("Returning cached context {}", existing);
return Futures.immediateCheckedFuture(existing);
}
// Request all sources be loaded
- final ListenableFuture<List<ASTSchemaSource>> sf = Futures.allAsList(Collections2.transform(requiredSources, requestSources));
+ ListenableFuture<List<ASTSchemaSource>> sf = Futures.allAsList(Collections2.transform(uniqueSourceIdentifiers, requestSources));
+
+ // Detect mismatch between requested Source IDs and IDs that are extracted from parsed source
+ // Also remove duplicates if present
+ // We are relying on preserved order of uniqueSourceIdentifiers as well as sf
+ sf = Futures.transform(sf, new SourceIdMismatchDetector(uniqueSourceIdentifiers));
// Assemble sources into a schema context
final ListenableFuture<SchemaContext> cf = Futures.transform(sf, assembleSources);
Futures.addCallback(cf, new FutureCallback<SchemaContext>() {
@Override
public void onSuccess(final SchemaContext result) {
- cache.put(requiredSources, result);
+ cache.put(uniqueSourceIdentifiers, result);
}
@Override
return Futures.makeChecked(cf, MAPPER);
}
+
+ /**
+ * @return set (preserving ordering) from the input collection
+ */
+ private List<SourceIdentifier> deDuplicateSources(final Collection<SourceIdentifier> requiredSources) {
+ final Set<SourceIdentifier> uniqueSourceIdentifiers = Collections.unmodifiableSet(Sets.newLinkedHashSet(requiredSources));
+ if(uniqueSourceIdentifiers.size() != requiredSources.size()) {
+ LOG.warn("Duplicate sources requested for schema context, removed duplicate sources: {}", Collections2.filter(uniqueSourceIdentifiers, new Predicate<SourceIdentifier>() {
+ @Override
+ public boolean apply(@Nullable final SourceIdentifier input) {
+ return Iterables.frequency(requiredSources, input) > 1;
+ }
+ }));
+ }
+ return Lists.newArrayList(uniqueSourceIdentifiers);
+ }
+
+ private static final class SourceIdMismatchDetector implements Function<List<ASTSchemaSource>, List<ASTSchemaSource>> {
+ private final List<SourceIdentifier> sourceIdentifiers;
+
+ public SourceIdMismatchDetector(final List<SourceIdentifier> sourceIdentifiers) {
+ this.sourceIdentifiers = sourceIdentifiers;
+ }
+
+ @Override
+ public List<ASTSchemaSource> apply(final List<ASTSchemaSource> input) {
+ final Map<SourceIdentifier, ASTSchemaSource> filtered = Maps.newLinkedHashMap();
+
+ for (int i = 0; i < input.size(); i++) {
+
+ final SourceIdentifier expectedSId = sourceIdentifiers.get(i);
+ final ASTSchemaSource astSchemaSource = input.get(i);
+ final SourceIdentifier realSId = astSchemaSource.getIdentifier();
+
+ if (expectedSId.equals(realSId) == false) {
+ LOG.warn("Source identifier mismatch for module \"{}\", requested as {} but actually is {}. Using actual id", expectedSId.getName(), expectedSId, realSId);
+ }
+
+ if (filtered.containsKey(realSId)) {
+ LOG.warn("Duplicate source for module {} detected in reactor", realSId);
+ }
+
+ filtered.put(realSId, astSchemaSource);
+
+ }
+ return Lists.newArrayList(filtered.values());
+ }
+ }
}
--- /dev/null
+/**
+ * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ */
+package org.opendaylight.yangtools.yang.parser.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URISyntaxException;
+import java.util.Set;
+
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.UsesNode;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+public class AugmentToExtensionTest {
+ private Set<Module> modules;
+
+ @Test(expected = YangParseException.class)
+ public void testIncorrectPath() throws IOException, URISyntaxException {
+ modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/incorrect-path").toURI());
+
+ }
+
+ @Test
+ public void testCorrectPathIntoUnsupportedTarget() throws IOException, URISyntaxException {
+ modules = TestUtils.loadModules(getClass().getResource(
+ "/augment-to-extension-test/correct-path-into-unsupported-target").toURI());
+
+ Module devicesModul = TestUtils.findModule(modules, "augment-module");
+
+ ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModul.getDataChildByName("my-container");
+ Set<UsesNode> uses = devicesContainer.getUses();
+
+ boolean augmentationIsInContainer = false;
+ for (UsesNode usesNode : uses) {
+ Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
+ for (AugmentationSchema augmentationSchema : augmentations) {
+ augmentationIsInContainer = true;
+ }
+ }
+
+ assertFalse(augmentationIsInContainer);
+ }
+
+ @Test
+ public void testCorrectAugment() throws IOException, URISyntaxException {
+ modules = TestUtils.loadModules(getClass().getResource("/augment-to-extension-test/correct-augment").toURI());
+
+ Module devicesModul = TestUtils.findModule(modules, "augment-module");
+
+ ContainerSchemaNode devicesContainer = (ContainerSchemaNode) devicesModul.getDataChildByName("my-container");
+ Set<UsesNode> uses = devicesContainer.getUses();
+
+ boolean augmentationIsInContainer = false;
+ for (UsesNode usesNode : uses) {
+ Set<AugmentationSchema> augmentations = usesNode.getAugmentations();
+ for (AugmentationSchema augmentationSchema : augmentations) {
+ augmentationIsInContainer = true;
+ }
+ }
+
+ assertTrue(augmentationIsInContainer);
+ }
+
+}
--- /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.yang.parser.impl;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Optional;
+import com.google.common.collect.Iterables;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.builder.impl.AugmentationSchemaBuilderImpl;
+
+public class AugmentationSchemaBuilderImplTest {
+
+ private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl;
+ private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl2;
+ private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl3;
+ private AugmentationSchemaBuilderImpl augmentSchemaBuilderImpl4;
+ private AugmentationSchema augmentSchema;
+
+ @Before
+ public void init() {
+ augmentSchemaBuilderImpl = new AugmentationSchemaBuilderImpl("test-module", 10, "augment-test/rpc", SchemaPath.ROOT, 1);
+ augmentSchemaBuilderImpl2 = new AugmentationSchemaBuilderImpl("test-module", 10, "augment-test/rpc2", SchemaPath.ROOT, 1);
+ augmentSchemaBuilderImpl3 = augmentSchemaBuilderImpl;
+ augmentSchemaBuilderImpl4 = new AugmentationSchemaBuilderImpl("test-module", 10, null, SchemaPath.ROOT, 1);
+ augmentSchema = augmentSchemaBuilderImpl.build();
+ }
+
+ @Test
+ public void testgetPath() {
+ assertTrue(Iterables.isEmpty(augmentSchemaBuilderImpl.getPath().getPathFromRoot()));
+ }
+
+ @Test
+ public void testEquals() {
+ assertFalse(augmentSchemaBuilderImpl.equals("test"));
+ assertFalse(augmentSchemaBuilderImpl.equals(null));
+ assertTrue(augmentSchemaBuilderImpl.equals(augmentSchemaBuilderImpl3));
+ assertFalse(augmentSchemaBuilderImpl4.equals(augmentSchemaBuilderImpl));
+ assertFalse(augmentSchemaBuilderImpl.equals(augmentSchemaBuilderImpl2));
+ }
+
+ @Test
+ public void testGetOriginalDefinition() {
+ augmentSchema = augmentSchemaBuilderImpl.build();
+ Optional<AugmentationSchema> origDefinition = augmentSchema.getOriginalDefinition();
+ assertFalse(origDefinition.isPresent());
+ }
+
+ @Test
+ public void testGetUnknownSchemaNodes() {
+ assertTrue(Iterables.isEmpty(augmentSchema.getUnknownSchemaNodes()));
+ }
+}
--- /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.yang.parser.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.common.QName;
+import org.opendaylight.yangtools.yang.model.api.SchemaPath;
+import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils;
+import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
+
+/**
+ * NPE is rised during use of CopyUtils.copy operation for IdentityrefTypeBuilder.
+ * NPE occours in private getData method in CopyUtils.java during QName.create.
+ *
+ * The reason for exception is the old.getQName returns null since IdentityrefTypeBuilder.getQName()
+ * by implementation returns always null.
+ *
+ */
+public class Bug2219Test {
+
+ private ModuleBuilder moduleBuilder;
+
+ @Before
+ public void init() {
+ moduleBuilder = new ModuleBuilder("test-module", "somePath");
+ }
+
+ @Test
+ public void testCopyIdentityrefTypeBuilder() {
+ final String typedefLocalName = "identity-ref-test-type";
+ final QName typedefQname = QName.create(moduleBuilder.getNamespace(), moduleBuilder.getRevision(), typedefLocalName);
+ final SchemaPath typedefPath = SchemaPath.create(true, typedefQname);
+ final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(moduleBuilder.getModuleName(), 12,
+ "base:parent-identity", typedefPath);
+
+ final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, moduleBuilder, true);
+ assertNotNull(copy);
+ }
+}
--- /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.yang.parser.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import com.google.common.base.Optional;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.util.Date;
+import org.junit.Before;
+import org.junit.Test;
+import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
+import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl;
+
+public class ModuleIdentifierTest {
+
+ private ModuleIdentifier moduleIdentifier;
+ private ModuleIdentifier moduleIdentifier2;
+ private ModuleIdentifier moduleIdentifier3;
+ private ModuleIdentifier moduleIdentifier4;
+ private ModuleIdentifier moduleIdentifier5;
+
+ @Before
+ public void init() throws URISyntaxException {
+ Optional<URI> uri = Optional.of(new URI("testURI"));
+ Optional<URI> uri2 = Optional.of(new URI("testURI2"));
+ Optional<Date> revision = Optional.absent();
+ moduleIdentifier = new ModuleIdentifierImpl("test-modulue", uri, revision);
+ moduleIdentifier2 = new ModuleIdentifierImpl("test-modulue2", uri, revision);
+ moduleIdentifier3 = moduleIdentifier;
+ moduleIdentifier4 = new ModuleIdentifierImpl("test-modulue", uri2, revision);
+ moduleIdentifier5 = new ModuleIdentifierImpl("test-modulue", uri, revision);
+ }
+
+ @Test
+ public void testGetQNameModule() {
+ assertEquals(null, moduleIdentifier.getQNameModule().getRevision());
+ }
+
+ @Test
+ public void testGetRevision() {
+ assertEquals(null, moduleIdentifier.getRevision());
+ }
+
+ @Test
+ public void testGetName() {
+ assertEquals("test-modulue", moduleIdentifier.getName());
+ }
+
+ @Test
+ public void getNamespace() throws URISyntaxException {
+ assertEquals(new URI("testURI"), moduleIdentifier.getNamespace());
+ }
+
+ @Test
+ public void toStringTest() {
+ assertTrue(moduleIdentifier.toString().contains("ModuleIdentifier"));
+ }
+
+ @Test
+ public void testHashCode() {
+ assertFalse(moduleIdentifier.hashCode() == moduleIdentifier2.hashCode());
+ }
+
+ @Test
+ public void testEquals() {
+ assertTrue(moduleIdentifier.equals(moduleIdentifier3));
+ assertFalse(moduleIdentifier.equals(null));
+ assertFalse(moduleIdentifier.equals("test"));
+ assertFalse(moduleIdentifier.equals(moduleIdentifier2));
+ assertFalse(moduleIdentifier.equals(moduleIdentifier4));
+ assertTrue(moduleIdentifier.equals(moduleIdentifier5));
+ }
+}
--- /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.yang.parser.impl;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.File;
+import java.net.URI;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.opendaylight.yangtools.yang.model.api.Module;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser;
+import org.opendaylight.yangtools.yang.parser.util.YangParseException;
+
+public class SameQNamesInChoiceTest {
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Test
+ public void testSameQNameInChoice() throws Exception {
+ thrown.expect(YangParseException.class);
+ thrown.expectMessage("Choice has two nodes case with same qnames");
+
+ SchemaContext context;
+ File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice/two-same-nodes-in-choice-case.yang").toURI());
+ File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/two-same-node-in-choice").toURI());
+ YangContextParser parser = new YangParserImpl();
+ context = parser.parseFile(yangFile, dependenciesDir);
+
+ Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:same-nodes-in-choice-case")).iterator().next();
+ assertNotNull(testModule);
+ }
+
+
+ @Test
+ public void testAugmentedNodeIntoChoiceCase() throws Exception {
+ thrown.expect(YangParseException.class);
+ thrown.expectMessage("Choice has two nodes case with same qnames");
+
+ SchemaContext context;
+ File yangFile = new File(getClass().getResource("/bugs/qnameDuplicity/augment/two-cases.yang").toURI());
+ File dependenciesDir = new File(getClass().getResource("/bugs/qnameDuplicity/augment").toURI());
+ YangContextParser parser = new YangParserImpl();
+ context = parser.parseFile(yangFile, dependenciesDir);
+
+ Module testModule = context.findModuleByNamespace(URI.create("urn:test:two:cases")).iterator().next();
+ assertNotNull(testModule);
+ }
+}
--- /dev/null
+package org.opendaylight.yangtools.yang.parser.repo;
+
+import static org.junit.Assert.assertNotNull;
+
+import com.google.common.collect.Lists;
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.Futures;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaResolutionException;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceException;
+import org.opendaylight.yangtools.yang.model.repo.api.SchemaSourceFilter;
+import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
+import org.opendaylight.yangtools.yang.model.repo.api.YangTextSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
+import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceProvider;
+import org.opendaylight.yangtools.yang.parser.util.ASTSchemaSource;
+import org.opendaylight.yangtools.yang.parser.util.TextToASTTransformer;
+
+public class SharedSchemaContextFactoryTest {
+
+ private final SharedSchemaRepository repository = new SharedSchemaRepository("test");
+
+ @Mock
+ private SchemaSourceFilter filter;
+ private SourceIdentifier s1;
+ private SourceIdentifier s2;
+
+ @Before
+ public void setUp() throws Exception {
+ MockitoAnnotations.initMocks(this);
+
+ final ResourceYangSource source1 = new ResourceYangSource("/ietf/ietf-inet-types@2010-09-24.yang");
+ final ResourceYangSource source2 = new ResourceYangSource("/ietf/iana-timezones@2012-07-09.yang");
+ s1 = new SourceIdentifier("ietf-inet-types", "2010-09-24");
+ s2 = new SourceIdentifier("iana-timezones", "2012-07-09");
+
+ final TextToASTTransformer transformer = TextToASTTransformer.create(repository, repository);
+ repository.registerSchemaSourceListener(transformer);
+
+ repository.registerSchemaSource(new SchemaSourceProvider<YangTextSchemaSource>() {
+ @Override
+ public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
+ return Futures.<YangTextSchemaSource, SchemaSourceException>immediateCheckedFuture(source1);
+ }
+ }, PotentialSchemaSource.create(s1, YangTextSchemaSource.class, 1));
+
+ repository.registerSchemaSource(new SchemaSourceProvider<YangTextSchemaSource>() {
+ @Override
+ public CheckedFuture<YangTextSchemaSource, SchemaSourceException> getSource(final SourceIdentifier sourceIdentifier) {
+ return Futures.<YangTextSchemaSource, SchemaSourceException>immediateCheckedFuture(source2);
+ }
+ }, PotentialSchemaSource.create(s2, YangTextSchemaSource.class, 1));
+ }
+
+ @Test
+ public void testCreateSchemaContextWithDuplicateRequiredSources() throws Exception {
+ final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository, filter);
+ final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContext = sharedSchemaContextFactory.createSchemaContext(Lists.newArrayList(s1, s1, s2));
+ assertNotNull(schemaContext.checkedGet());
+ }
+
+ @Test
+ public void testSourceRegisteredWithDifferentSI() throws Exception {
+ final ResourceYangSource source1 = new ResourceYangSource("/ietf/ietf-inet-types@2010-09-24.yang");
+ final ResourceYangSource source2 = new ResourceYangSource("/ietf/iana-timezones@2012-07-09.yang");
+ s1 = source1.getIdentifier();
+ s2 = source2.getIdentifier();
+
+ final SettableSchemaProvider<ASTSchemaSource> provider = SharedSchemaRepositoryTest.getImmediateYangSourceProviderFromResource("/no-revision/imported@2012-12-12.yang");
+ provider.setResult();
+ provider.register(repository);
+
+ // Register the same provider under source id without revision
+ final SourceIdentifier sIdWithoutRevision = new SourceIdentifier(provider.getId().getName());
+ repository.registerSchemaSource(provider, PotentialSchemaSource.create(
+ sIdWithoutRevision, ASTSchemaSource.class, PotentialSchemaSource.Costs.IMMEDIATE.getValue()));
+
+ final SharedSchemaContextFactory sharedSchemaContextFactory = new SharedSchemaContextFactory(repository, filter);
+ final CheckedFuture<SchemaContext, SchemaResolutionException> schemaContext = sharedSchemaContextFactory.createSchemaContext(Lists.newArrayList(sIdWithoutRevision, provider.getId()));
+ assertNotNull(schemaContext.checkedGet());
+ }
+}
public class SharedSchemaRepositoryTest {
+ @Test
+ public void testSourceWithAndWithoutRevision() throws Exception {
+ final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
+
+ final SourceIdentifier idNoRevision = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported.yang");
+ final SourceIdentifier id2 = loadAndRegisterSource(sharedSchemaRepository, "/no-revision/imported@2012-12-12.yang");
+
+ CheckedFuture<ASTSchemaSource, SchemaSourceException> source = sharedSchemaRepository.getSchemaSource(idNoRevision, ASTSchemaSource.class);
+ assertEquals(idNoRevision, source.checkedGet().getIdentifier());
+ source = sharedSchemaRepository.getSchemaSource(id2, ASTSchemaSource.class);
+ assertEquals(id2, source.checkedGet().getIdentifier());
+ }
+
+ private SourceIdentifier loadAndRegisterSource(final SharedSchemaRepository sharedSchemaRepository, final String resourceName) throws Exception {
+ final SettableSchemaProvider<ASTSchemaSource> sourceProvider = getImmediateYangSourceProviderFromResource(resourceName);
+ sourceProvider.setResult();
+ final SourceIdentifier idNoRevision = sourceProvider.getId();
+ sourceProvider.register(sharedSchemaRepository);
+ return idNoRevision;
+ }
+
@Test
public void testSimpleSchemaContext() throws Exception {
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository("netconf-mounts");
assertEquals(moduleSize, schemaContext.getModules().size());
}
- private SettableSchemaProvider<ASTSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName) throws Exception {
+ static SettableSchemaProvider<ASTSchemaSource> getRemoteYangSourceProviderFromResource(final String resourceName) throws Exception {
final ResourceYangSource yangSource = new ResourceYangSource(resourceName);
final CheckedFuture<ASTSchemaSource, SchemaSourceException> aSTSchemaSource = TextToASTTransformer.TRANSFORMATION.apply(yangSource);
return SettableSchemaProvider.createRemote(aSTSchemaSource.get(), ASTSchemaSource.class);
}
- private SettableSchemaProvider<ASTSchemaSource> getImmediateYangSourceProviderFromResource(final String resourceName) throws Exception {
+ static SettableSchemaProvider<ASTSchemaSource> getImmediateYangSourceProviderFromResource(final String resourceName) throws Exception {
final ResourceYangSource yangSource = new ResourceYangSource(resourceName);
final CheckedFuture<ASTSchemaSource, SchemaSourceException> aSTSchemaSource = TextToASTTransformer.TRANSFORMATION.apply(yangSource);
return SettableSchemaProvider.createImmediate(aSTSchemaSource.get(), ASTSchemaSource.class);
--- /dev/null
+module augment-module {
+ yang-version 1;
+ namespace "uri:augment-module";
+ prefix aug;
+
+ import extension-module { prefix ext; }
+
+ revision 2014-10-07 {
+ description
+ "Yang model with augment into extension";
+ }
+
+ grouping my-grouping {
+ ext:my-extension my-extension-name {
+ description
+ "Extension.";
+ input {
+ leaf my-leaf {
+ type string;
+ description
+ "my-leaf in extension body.";
+ }
+ }
+ }
+ container my-container-in-gruping {
+ }
+ }
+
+ container my-container {
+ uses my-grouping {
+ augment "my-container-in-gruping" {
+ leaf-list my-leaf-list {
+ type string;
+ }
+ }
+ }
+ }
+}
+
--- /dev/null
+module extension-module {
+ yang-version 1;
+ namespace "uri:extension-module";
+ prefix ext;
+
+ revision 2014-10-07 {
+ description
+ "Yang model with extension definition";
+ }
+
+ extension my-extension {
+ argument name {
+ }
+ }
+}
--- /dev/null
+module augment-module {
+ yang-version 1;
+ namespace "uri:augment-module";
+ prefix aug;
+
+ import extension-module { prefix ext; }
+
+ revision 2014-10-07 {
+ description
+ "Yang model with augment into extension";
+ }
+
+ grouping my-grouping {
+ ext:my-extension my-extension-name {
+ description
+ "Extension.";
+ input {
+ leaf my-leaf {
+ type string;
+ description
+ "my-leaf in extension body.";
+ }
+ }
+ }
+ container my-container-in-gruping {
+ }
+ }
+
+ container my-container {
+ uses my-grouping {
+ augment "my-extension-name/input" {
+ leaf-list my-leaf-list {
+ type string;
+ }
+ }
+ }
+ }
+}
+
--- /dev/null
+module extension-module {
+ yang-version 1;
+ namespace "uri:extension-module";
+ prefix ext;
+
+ revision 2014-10-07 {
+ description
+ "Yang model with extension definition";
+ }
+
+ extension my-extension {
+ argument name {
+ }
+ }
+}
--- /dev/null
+module augment-module {
+ yang-version 1;
+ namespace "uri:augment-module";
+ prefix aug;
+
+ import extension-module { prefix ext; }
+
+ revision 2014-10-07 {
+ description
+ "Yang model with augment into extension";
+ }
+
+ grouping my-grouping {
+ ext:my-extension my-extension-name {
+ description
+ "Extension.";
+ input {
+ leaf my-leaf {
+ type string;
+ description
+ "my-leaf in extension body.";
+ }
+ }
+ }
+ container my-container-in-gruping {
+ }
+ }
+
+ container my-container {
+ uses my-grouping {
+ augment "my-extension-name/input/a" {
+ leaf-list my-leaf-list {
+ type string;
+ }
+ }
+ }
+ }
+}
+
--- /dev/null
+module extension-module {
+ yang-version 1;
+ namespace "uri:extension-module";
+ prefix ext;
+
+ revision 2014-10-07 {
+ description
+ "Yang model with extension definition";
+ }
+
+ extension my-extension {
+ argument name {
+ }
+ }
+}
--- /dev/null
+module two-cases {
+
+ namespace "urn:test:two:cases";
+ prefix "two";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-07-09 {
+
+ }
+
+ container cont {
+ choice choice {
+ default second;
+ case first {
+ leaf leaf-case1 {
+ type int32;
+ }
+ }
+ }
+ }
+
+ augment "/cont/choice/" {
+ case forth {
+ leaf leaf-case1 {
+ type string;
+ }
+ }
+ }
+}
\ No newline at end of file
--- /dev/null
+module two-same-nodes-in-choice-case {
+
+ namespace "urn:test:two:same-nodes-in-choice-case";
+ prefix "two";
+
+ organization "OPEN DAYLIGHT";
+ contact "http://www.opendaylight.org/";
+
+ revision 2013-07-09 {
+
+ }
+
+ container cont3 {
+ choice choice3 {
+ default second;
+ case first {
+ leaf leaf-case1 {
+ type int32;
+ }
+ }
+ case second {
+ leaf leaf-case1 {
+ type int32;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
namespace "urn:simple.demo.test1";
prefix "imp";
- organization "opendaylight";
- contact "WILL-BE-DEFINED-LATER";
+ //organization "opendaylight";
+ //contact "WILL-BE-DEFINED-LATER";
}
revision 2012-12-12 {}
- organization "opendaylight";
- contact "WILL-BE-DEFINED-LATER";
+ //organization "opendaylight";
+ //contact "WILL-BE-DEFINED-LATER";
}