public void testCreateAbstractBaseTypeWithNullPackagename() {
expException.expect(IllegalArgumentException.class);
expException.expectMessage("Package Name for Generated Type cannot be null!");
- AbstractBaseType baseTypeNullpackagename = new AbstractBaseType(null, "Test");
+ new AbstractBaseType(null, "Test");
}
@Test
public void testCreateAbstractBaseTypeWithNullTypeName() {
expException.expect(IllegalArgumentException.class);
expException.expectMessage("Name of Generated Type cannot be null!");
- AbstractBaseType baseTypeNullTypeName = new AbstractBaseType("org.opendaylight.yangtools.test", null);
+ new AbstractBaseType("org.opendaylight.yangtools.test", null);
}
@Test
*/
package org.opendaylight.yangtools.binding.generator.util;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import com.google.common.base.Optional;
import java.io.File;
import java.io.IOException;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
-
-import com.google.common.base.Optional;
-
+import org.junit.Rule;
import org.junit.Test;
+import org.junit.rules.ExpectedException;
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.GeneratedTypeBuilder;
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;
public class BindingGeneratorUtilTest {
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
private static List<File> loadTestResources(String testFile) {
final List<File> testModels = new ArrayList<File>();
File listModelFile;
// test of the method packageNameForTypeDefinition
Set<TypeDefinition<?>> typeDefinitions = module.getTypeDefinitions();
String subPackageNameForTypeDefinition = "";
+ TypeDefinition<?> firstTypeDef = null;
+
for (TypeDefinition<?> tpDef : typeDefinitions) {
if (tpDef.getQName().getLocalName().equals("tpdf")) {
subPackageNameForTypeDefinition = BindingGeneratorUtil.packageNameForTypeDefinition(packageName, tpDef);
+ firstTypeDef = tpDef;
break;
}
}
"org.opendaylight.yang.gen.v1.urn.m.o.d.u.l.e.n.a.m.e.t.e.s.t._case._1digit.rev130910",
subPackageNameForTypeDefinition);
+ // test method getRestrictions
+ Restrictions restriction = BindingGeneratorUtil.getRestrictions(firstTypeDef);
+ assertNotNull(restriction);
+
+ // test method computeDefaultSUID
+ GeneratedTypeBuilder genTypeBuilder = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType");
+ genTypeBuilder.addMethod("testMethod");
+ genTypeBuilder.addAnnotation("org.opendaylight.yangtools.test.annotation", "AnnotationTest");
+ genTypeBuilder.addEnclosingTransferObject("testObject");
+ genTypeBuilder.addProperty("newProp");
+ GeneratedTypeBuilder genType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "Type2");
+ genTypeBuilder.addImplementsType(genType);
+ long computedSUID = BindingGeneratorUtil.computeDefaultSUID(genTypeBuilder);
+
+ GeneratedTypeBuilder genTypeBuilder2 = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test2", "TestType2");
+ long computedSUID2 = BindingGeneratorUtil.computeDefaultSUID(genTypeBuilder2);
+ assertNotEquals(computedSUID, computedSUID2);
+
// test of exception part of the method moduleNamespaceToPackageName()
ModuleBuilder moduleBuilder = new ModuleBuilder("module-withut-revision", null);
moduleBuilder.setSource("");
}
+ /**
+ * Test for the method
+ * <ul>
+ * <li>{@link BindingGeneratorUtil#packageNameForTypeDefinition()
+ * packageNameForTypeDefinition()}</li>
+ * </ul>
+ */
+ @Test
+ public void testPackageNameForTypeDefinitionNullBasePackageName() {
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Base Package Name cannot be NULL!");
+ BindingGeneratorUtil.packageNameForTypeDefinition(null, null);
+ }
+
+ /**
+ * Test for the method
+ * <ul>
+ * <li>{@link BindingGeneratorUtil#packageNameForTypeDefinition()
+ * packageNameForTypeDefinition()}</li>
+ * </ul>
+ */
+ @Test
+ public void testPackageNameForTypeDefinitionNullTypeDefinition() {
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Type Definition reference cannot be NULL!");
+ BindingGeneratorUtil.packageNameForTypeDefinition("test.package", null);
+ }
+
+ /**
+ * Test for the method
+ * <ul>
+ * <li>{@link BindingGeneratorUtil#packageNameForGeneratedType()
+ * packageNameForGeneratedType()}</li>
+ * </ul>
+ */
+ @Test
+ public void testPackageNameForGeneratedTypeNullBasePackageName() {
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Base Package Name cannot be NULL!");
+ BindingGeneratorUtil.packageNameForGeneratedType(null, null);
+ }
+
+ /**
+ * Test for the method
+ * <ul>
+ * <li>{@link BindingGeneratorUtil#packageNameForGeneratedType()
+ * packageNameForGeneratedType()}</li>
+ * </ul>
+ */
+ @Test
+ public void testPackageNameForGeneratedTypeNullSchemaPath() {
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Schema Path cannot be NULL!");
+ BindingGeneratorUtil.packageNameForGeneratedType("test.package", null);
+ }
+
+ /**
+ * Test for the method
+ * <ul>
+ * <li>{@link BindingGeneratorUtil#parseToClassName()
+ * parseToClassName()}</li>
+ * </ul>
+ */
+ @Test
+ public void testParseToClassNameNullValue() {
+ String className = BindingGeneratorUtil.parseToClassName("test-class-name");
+ assertEquals("TestClassName", className);
+
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Name can not be null");
+ className = BindingGeneratorUtil.parseToClassName(null);
+ }
+
+ /**
+ * Test for the method
+ * <ul>
+ * <li>{@link BindingGeneratorUtil#parseToClassName()
+ * parseToClassName()}</li>
+ * </ul>
+ */
+ @Test
+ public void testParseToClassNameEmptyValue() {
+ String className = BindingGeneratorUtil.parseToClassName("test-class-name");
+ assertEquals("TestClassName", className);
+
+ expectedEx.expect(IllegalArgumentException.class);
+ expectedEx.expectMessage("Name can not be empty");
+ className = BindingGeneratorUtil.parseToClassName("");
+ }
+
/**
* Test for the method
* <ul>
*/
package org.opendaylight.yangtools.binding.generator.util;
-import org.junit.Test;
-import org.opendaylight.yangtools.yang.binding.*;
-
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import static org.opendaylight.yangtools.binding.generator.util.Types.typeForClass;
+import org.junit.Test;
+import org.opendaylight.yangtools.sal.binding.model.api.ParameterizedType;
+import org.opendaylight.yangtools.yang.binding.Augmentable;
+import org.opendaylight.yangtools.yang.binding.Augmentation;
+import org.opendaylight.yangtools.yang.binding.BaseIdentity;
+import org.opendaylight.yangtools.yang.binding.DataObject;
+import org.opendaylight.yangtools.yang.binding.DataRoot;
+import org.opendaylight.yangtools.yang.binding.Identifiable;
+import org.opendaylight.yangtools.yang.binding.Identifier;
+import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
+import org.opendaylight.yangtools.yang.binding.Notification;
+import org.opendaylight.yangtools.yang.binding.NotificationListener;
+import org.opendaylight.yangtools.yang.binding.RpcService;
+
public class BindingTypesTest {
@Test
assertEquals("NOTIFICATION_LISTENER", typeForClass(NotificationListener.class), BindingTypes.NOTIFICATION_LISTENER);
assertEquals("RPC_SERVICE", typeForClass(RpcService.class), BindingTypes.RPC_SERVICE);
}
+
+ @Test
+ public void testAugmentable() {
+ ParameterizedType augmentType = BindingTypes.augmentable(null);
+ assertNotNull(augmentType);
+ }
+
+ @Test
+ public void testChildOf() {
+ ParameterizedType childOfType = BindingTypes.childOf(null);
+ assertNotNull(childOfType);
+ }
}
\ No newline at end of file
package org.opendaylight.yangtools.binding.generator.util;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
import org.junit.Test;
import org.opendaylight.yangtools.sal.binding.model.api.ConcreteType;
public void testVoidType() {
final ConcreteType voidType = Types.voidType();
assertEquals("Void", voidType.getName());
+ assertNotNull(voidType);
}
@Test
public void testPrimitiveType() {
final Type primitiveType = Types.primitiveType("newType", null);
assertEquals("newType", primitiveType.getName());
+ assertNotNull(primitiveType);
}
@Test
public void testMapTypeFor() {
final ParameterizedType mapType = Types.mapTypeFor(null, null);
assertEquals("Map", mapType.getName());
+ assertNotNull(mapType);
}
@Test
public void testSetTypeFor() {
final ParameterizedType setType = Types.setTypeFor(null);
assertEquals("Set", setType.getName());
+ assertNotNull(setType);
}
@Test
public void testListTypeFor() {
final ParameterizedType listType = Types.listTypeFor(null);
assertEquals("List", listType.getName());
+ assertNotNull(listType);
}
@Test
public void testWildcardTypeFor() {
final WildcardType wildcardType = Types.wildcardTypeFor("org.opendaylight.yangtools.test", "WildcardTypeTest");
assertEquals("WildcardTypeTest", wildcardType.getName());
+ assertNotNull(wildcardType);
}
@Test
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.Test;
assertTrue(genProperty.isFinal());
assertTrue(genProperty.isStatic());
assertEquals(genProperty.hashCode(), genProperty2.hashCode());
- String pom = genProperty.toString();
assertTrue(genProperty.toString().contains("org.opendaylight.yangtools.test.TestType"));
+ assertNotNull(genProperty.toString());
assertTrue(genProperty.equals(genProperty2));
assertFalse(genProperty.equals(null));
/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * 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,
*/
package org.opendaylight.yangtools.binding.generator.util.generated.type.builder;
-import static org.junit.Assert.*;
+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.assertTrue;
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;
}
+ public void testAddAnnotation() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ annotBuilderImpl.addAnnotation("org.opedaylight.yangtools.test.v1", "AnnotationTest2");
+ annotBuilderImpl.addAnnotation(null, "AnnotationTest2");
+ assertFalse(annotBuilderImpl.toInstance().getAnnotations().isEmpty());
+ }
+
+ @Test
+ public void testAddParameterMethod() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ annotBuilderImpl.addParameter("testParam", "test value");
+ annotBuilderImpl.addParameter(null, "test value");
+ final AnnotationType annotType = annotBuilderImpl.toInstance();
+ assertEquals(1, annotType.getParameters().size());
+ }
+
+ @Test
+ public void testAddParametersMethod() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+
+ final List<String> values = new ArrayList<>();
+ values.add("test1");
+ values.add("test2");
+ values.add("test3");
+ annotBuilderImpl.addParameters("testParam", values);
+
+ AnnotationType annotType = annotBuilderImpl.toInstance();
+ assertEquals(1, annotType.getParameters().size());
+
+ annotBuilderImpl.addParameters("testParam", null);
+
+ annotType = annotBuilderImpl.toInstance();
+ assertEquals(1, annotType.getParameters().size());
+ }
+
+ @Test
+ public void testHashCode() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ final AnnotationTypeBuilderImpl annotBuilderImpl2 = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest2");
+ assertFalse(annotBuilderImpl.hashCode() == annotBuilderImpl2.hashCode());
+ }
+
+ @Test
+ public void testEquals() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ final AnnotationTypeBuilderImpl annotBuilderImpl2 = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ final AnnotationTypeBuilderImpl annotBuilderImpl3 = annotBuilderImpl2;
+
+ assertTrue(annotBuilderImpl.equals(annotBuilderImpl2));
+ assertTrue(annotBuilderImpl2.equals(annotBuilderImpl3));
+ assertFalse(annotBuilderImpl2.equals(null));
+ assertFalse(annotBuilderImpl2.equals("test"));
+ }
+
+ @Test
+ public void testToString() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ assertNotNull(annotBuilderImpl.toString());
+ }
+
+ @Test
+ public void testMethodsForAnnotationTypeImpl() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ annotBuilderImpl.addParameter("testParam", "test value");
+ final AnnotationType annotationType = annotBuilderImpl.toInstance();
+
+ final AnnotationTypeBuilderImpl annotBuilderImpl2 = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ final AnnotationType annotationType2 = annotBuilderImpl2.toInstance();
+
+ assertTrue(annotationType.containsParameters());
+ assertTrue(annotationType.getAnnotations().isEmpty());
+ assertNotNull(annotationType.getFullyQualifiedName());
+ assertNotNull(annotationType.getName());
+ assertNotNull(annotationType.getPackageName());
+ assertNull(annotationType.getParameter(null));
+ assertNotNull(annotationType.getParameter("testParam"));
+ assertFalse(annotationType.getParameterNames().isEmpty());
+ assertFalse(annotationType.getParameters().isEmpty());
+
+ assertTrue(annotationType.hashCode() == annotationType2.hashCode());
+ assertTrue(annotationType.equals(annotationType2));
+ assertNotNull(annotationType.toString());
+ }
+
+ @Test
+ public void testMethodsForParameterImpl() {
+ final AnnotationTypeBuilderImpl annotBuilderImpl = new AnnotationTypeBuilderImpl("org.opedaylight.yangtools.test", "AnnotationTest");
+ annotBuilderImpl.addParameter("testParam", "test value");
+ annotBuilderImpl.addParameter("testParam", "test value");
+ annotBuilderImpl.addParameter("", "test value");
+ annotBuilderImpl.addParameter(null, "test value");
+ annotBuilderImpl.addParameter("", null);
+ final AnnotationType annotationType = annotBuilderImpl.toInstance();
+
+ final Parameter testParam = annotationType.getParameter("testParam");
+ assertEquals("testParam", testParam.getName());
+ assertEquals("test value", testParam.getValue());
+ assertEquals(0, testParam.getValues().size());
+
+ final List<Parameter> testParams = annotationType.getParameters();
+ final Parameter sameParam = testParams.get(0);
+
+ assertFalse(testParams.get(0).equals(testParams.get(1)));
+ assertFalse(testParams.get(0).equals(null));
+ assertFalse(testParams.get(0).equals("test"));
+ assertTrue(testParams.get(0).equals(sameParam));
+ assertFalse(testParams.get(0).hashCode() == testParams.get(1).hashCode());
+ assertTrue(testParams.get(0).hashCode() == testParams.get(0).hashCode());
+ }
}
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.Test;
public class ConstantImplTest {
@Test
- public void testAllMethods() {
+ public void testMethodsOfConstantImpl() {
final GeneratedTypeBuilderImpl definingType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test",
"DefiningType");
final GeneratedTypeBuilderImpl type = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test.v1",
assertTrue(constImpl.toFormattedString().contains("GeneratedTransferObject"));
assertTrue(constImpl.toString().contains("GeneratedTransferObject"));
assertEquals(constImpl.hashCode(), constImpl2.hashCode());
+ assertNotNull(constImpl.getDefiningType());
+ assertNotNull(constImpl.getType());
+ assertNotNull(constImpl.getName());
+ assertNotNull(constImpl.getValue());
+ assertNotNull(constImpl.toFormattedString());
+ assertNotNull(constImpl.toString());
+ assertNotNull(constImpl.hashCode());
assertFalse(constImpl.equals(null));
assertFalse(constImpl.equals("test"));
*/
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.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
import com.google.common.base.Optional;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.sal.binding.model.api.Enumeration;
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 final String reference = "TestRef";
private final String valueName = "TestValue";
private final String valueDescription = "Value used for test";
- private int value = 12;
+ private final int value = 12;
private Enumeration enumeration;
- private QName qName = QName.create("TestQName", "10-10-2014", "TestLocalQName");
+ private final QName qName = QName.create("TestQName", "10-10-2014", "TestLocalQName");
@Before
* 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 QName qname;
+ private final SchemaPath path;
+ private final String description;
+ private final String reference;
+ private final Status status;
private final List<UnknownSchemaNode> unknownNodes = Collections.emptyList();
- private String name;
- private Integer value;
+ private final String name;
+ private final Integer value;
private EnumPairImpl(QName qName) {
qname = qName;
return EnumTypeDefinition.EnumPair.class.getSimpleName() + "[name=" + name + ", value=" + value + "]";
}
}
-}
\ No newline at end of file
+}
-/**
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+/*
+ * 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.*;
+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 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;
@Test(expected = IllegalArgumentException.class)
public void addConstantIllegalArgumentTest() {
GeneratedTypeBuilder generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
-
- Constant constant = generatedTypeBuilder.addConstant(Types.typeForClass(String.class), null, "myConstantValue");
+ 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");
+ generatedTypeBuilder.addConstant(null, "myConstantName", "myConstantValue");
}
@Test
@Test(expected = IllegalArgumentException.class)
public void addMethodIllegalArgumentTest() {
GeneratedTypeBuilderImpl generatedTypeBuilder = new GeneratedTypeBuilderImpl("my.package", "MyName");
-
generatedTypeBuilder.addMethod(null);
}
assertEquals(SchemaPath.create(true, QName.create("/path")).getPathFromRoot(), instance.getSchemaPath());
assertEquals("My comment..", instance.getComment());
}
-
}
assertTrue(!(hash1 == hash3));
assertTrue(!(hash1 == hash4));
}
-
}
+