}
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);
*/
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) 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) 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.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));
+ }
+
+}
* @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;
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) {
}
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);
<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>
<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>
*
* @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
<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>
<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'>
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
*
this.childNames = ImmutableSet.copyOf(childNames);
}
- /**
- * Augmentation node has no QName
- *
- * @deprecated Use {@link #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()) );
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());
* 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();
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);