assertTrue(linksBuilder.exists());
assertTrue(linksKey.exists());
assertTrue(testData.exists());
- testFilesCount(parent, 6);
+ assertFilesCount(parent, 6);
parent = new File(sourcesOutputDir, NS_TEST + FS + "links");
File level = new File(parent, "Level.java");
assertTrue(nodeList.exists());
assertTrue(nodeListBuilder.exists());
assertTrue(nodesType.exists());
- testFilesCount(parent, 7);
+ assertFilesCount(parent, 7);
// Test if sources are compilable
testCompilation(sourcesOutputDir, compiledOutputDir);
assertTrue(linksClass.isInterface());
// TODO: anyxml
assertEquals(6, linksClass.getDeclaredMethods().length);
- testImplementsIfc(linksClass, keyArgsClass);
+ assertImplementsIfc(linksClass, keyArgsClass);
// Test list key constructor arguments ordering
assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class);
assertTrue(new File(parent, "OpenObject.java").exists());
assertTrue(new File(parent, "ExplicitRouteObject.java").exists());
assertTrue(new File(parent, "PathKeySubobject.java").exists());
- testFilesCount(parent, 7);
+ assertFilesCount(parent, 7);
parent = new File(parent, "object");
assertTrue(new File(parent, "Nodes.java").exists());
assertTrue(new File(parent, "NodesBuilder.java").exists());
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
parent = new File(sourcesOutputDir, NS_FOO + FS + "open");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "object");
assertTrue(new File(parent, "Nodes1.java").exists());
assertTrue(new File(parent, "Nodes1Builder.java").exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "nodes");
assertTrue(new File(parent, "Links.java").exists());
assertTrue(new File(parent, "LinksBuilder.java").exists());
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
parent = new File(sourcesOutputDir, NS_FOO + FS + "explicit");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "route");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "object");
assertTrue(new File(parent, "Subobjects.java").exists());
assertTrue(new File(parent, "SubobjectsBuilder.java").exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "subobjects");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "subobject");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "type");
assertTrue(new File(parent, "PathKey.java").exists());
assertTrue(new File(parent, "PathKeyBuilder.java").exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "path");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "key");
assertTrue(new File(parent, "PathKey.java").exists());
assertTrue(new File(parent, "PathKeyBuilder.java").exists());
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
// Test if all sources were generated from 'module bar'
parent = new File(sourcesOutputDir, NS_BAR);
assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists());
assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "basic");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "explicit");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "route");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "subobjects");
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
assertTrue(new File(parent, "SubobjectType.java").exists());
parent = new File(parent, "subobject");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "type");
assertTrue(new File(parent, "IpPrefix.java").exists());
assertTrue(new File(parent, "IpPrefixBuilder.java").exists());
assertTrue(new File(parent, "Label.java").exists());
assertTrue(new File(parent, "LabelBuilder.java").exists());
- testFilesCount(parent, 4);
+ assertFilesCount(parent, 4);
// Test if sources are compilable
testCompilation(sourcesOutputDir, compiledOutputDir);
assertTrue(pathAttributes.exists());
assertTrue(update.exists());
assertTrue(updateBuilder.exists());
- testFilesCount(parent, 6);
+ assertFilesCount(parent, 6);
parent = new File(sourcesOutputDir, NS_FOO + FS + "path");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "attributes");
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
File origin = new File(parent, "Origin.java");
File originBuilder = new File(parent, "OriginBuilder.java");
assertTrue(origin.exists());
assertTrue(originBuilder.exists());
parent = new File(sourcesOutputDir, NS_FOO + FS + "update");
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
pathAttributes = new File(parent, "PathAttributes.java");
File pathAttributesBuilder = new File(parent, "PathAttributesBuilder.java");
assertTrue(pathAttributes.exists());
assertTrue(destination.exists());
assertTrue(pathAttributes1.exists());
assertTrue(pathAttributes1Builder.exists());
- testFilesCount(parent, 5);
+ assertFilesCount(parent, 5);
parent = new File(sourcesOutputDir, NS_BAR + FS + "destination");
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
File destinationType = new File(parent, "DestinationType.java");
assertTrue(destinationType.exists());
parent = new File(parent, "destination");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "type");
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
File destinationIpv4 = new File(parent, "DestinationIp.java");
File destinationIpv4Builder = new File(parent, "DestinationIpBuilder.java");
assertTrue(destinationIpv4.exists());
assertTrue(destinationIpv4Builder.exists());
parent = new File(sourcesOutputDir, NS_BAR + FS + "update");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "path");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "attributes");
File mpUnreachNlri = new File(parent, "MpUnreachNlri.java");
File mpUnreachNlriBuilder = new File(parent, "MpUnreachNlriBuilder.java");
assertTrue(mpUnreachNlri.exists());
assertTrue(mpUnreachNlriBuilder.exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "mp");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "unreach");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "nlri");
File withdrawnRoutes = new File(parent, "WithdrawnRoutes.java");
File withdrawnRoutesBuilder = new File(parent, "WithdrawnRoutesBuilder.java");
assertTrue(withdrawnRoutes.exists());
assertTrue(withdrawnRoutesBuilder.exists());
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
// Test if all sources were generated from 'module baz'
parent = new File(sourcesOutputDir, NS_BAZ);
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
File linkstateDestination = new File(parent, "LinkstateDestination.java");
assertTrue(linkstateDestination.exists());
parent = new File(sourcesOutputDir, NS_BAZ + FS + "update");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "path");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "attributes");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "mp");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "unreach");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "nlri");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "withdrawn");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "routes");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "destination");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "type");
File destinationLinkstate = new File(parent, "DestinationLinkstate.java");
File destinationLinkstateBuilder = new File(parent, "DestinationLinkstateBuilder.java");
assertTrue(destinationLinkstate.exists());
assertTrue(destinationLinkstateBuilder.exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "destination");
- testFilesCount(parent, 1);
+ assertFilesCount(parent, 1);
parent = new File(parent, "linkstate");
File links = new File(parent, "Links.java");
File linksBuilder = new File(parent, "LinksBuilder.java");
assertTrue(links.exists());
assertTrue(linksBuilder.exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "links");
File source = new File(parent, "Source.java");
File sourceBuilder = new File(parent, "SourceBuilder.java");
assertTrue(source.exists());
assertTrue(sourceBuilder.exists());
- testFilesCount(parent, 3);
+ assertFilesCount(parent, 3);
parent = new File(parent, "source");
File address = new File(parent, "Address.java");
File addressBuilder = new File(parent, "AddressBuilder.java");
assertTrue(address.exists());
assertTrue(addressBuilder.exists());
- testFilesCount(parent, 2);
+ assertFilesCount(parent, 2);
// Test if sources are compilable
testCompilation(sourcesOutputDir, compiledOutputDir);
generator.generateToFile(sourcesOutputDir);
File parent = new File(sourcesOutputDir, NS_TEST);
- testFilesCount(parent, 4);
+ assertFilesCount(parent, 4);
assertTrue(new File(parent, "TestData.java").exists());
assertTrue(new File(parent, "Nodes.java").exists());
assertTrue(new File(parent, "NodesBuilder.java").exists());
// Test if all sources are generated
File fooParent = new File(sourcesOutputDir, NS_FOO);
- testFilesCount(fooParent, 3);
+ assertFilesCount(fooParent, 3);
assertTrue(new File(fooParent, "FooData.java").exists());
assertTrue(new File(fooParent, "Nodes.java").exists());
assertTrue(new File(fooParent, "NodesBuilder.java").exists());
File barParent = new File(sourcesOutputDir, NS_BAR);
- testFilesCount(barParent, 1);
+ assertFilesCount(barParent, 1);
assertTrue(new File(barParent, "IdentityClass.java").exists());
// Test if sources are compilable
import java.io.File;
import java.io.FileNotFoundException;
+import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.ParameterizedType;
}
}
+ /**
+ * Asserts that class contains field with fiven name and type.
+ *
+ * @param clazz
+ * class to test
+ * @param name
+ * field name
+ * @param type
+ * field type
+ * @return field with given name if present in class
+ */
static Field assertContainsField(Class<?> clazz, String name, Class<?> type) {
try {
Field f = clazz.getDeclaredField(name);
}
}
+ /**
+ * Asserts that class contains field with given name and value. Method tries
+ * to create new instance of class and get value of field. If class
+ * constructor contains any arguments, class is instantiated with null
+ * values.
+ *
+ * @param clazz
+ * class to test
+ * @param name
+ * name of field
+ * @param returnType
+ * return type of field
+ * @param expectedValue
+ * expected value of field
+ * @param constructorArgs
+ * constructor arguments of class to test
+ */
+ static void assertContainsFieldWithValue(Class<?> clazz, String name, Class<?> returnType, Object expectedValue,
+ Class<?>... constructorArgs) {
+ Object[] initargs = null;
+ if (constructorArgs != null && constructorArgs.length > 0) {
+ initargs = new Object[constructorArgs.length];
+ for (int i = 0; i < constructorArgs.length; i++) {
+ initargs[i] = null;
+ }
+ }
+ assertContainsFieldWithValue(clazz, name, returnType, expectedValue, constructorArgs, initargs);
+ }
+
+ /**
+ * Asserts that class contains field with given name, return type and value.
+ *
+ * @param clazz
+ * class to test
+ * @param name
+ * name of field
+ * @param returnType
+ * return type of field
+ * @param expectedValue
+ * expected value of field
+ * @param constructorArgs
+ * array of constructor arguments classes
+ * @param initargs
+ * array of constructor values
+ */
+ static void assertContainsFieldWithValue(Class<?> clazz, String name, Class<?> returnType, Object expectedValue,
+ Class<?>[] constructorArgs, Object... initargs) {
+ Field f = assertContainsField(clazz, name, returnType);
+ try {
+ Constructor<?> c = clazz.getDeclaredConstructor(constructorArgs);
+ Object o = c.newInstance(initargs);
+ assertEquals(expectedValue, f.get(o));
+ } catch (Exception e) {
+ throw new AssertionError("Failed to perform " + name + " field test", e);
+ }
+ }
+
+ /**
+ * Asserts that class contains constructor with parameter types.
+ *
+ * @param clazz
+ * class to test
+ * @param args
+ * array of argument classes
+ */
static void assertContainsConstructor(Class<?> clazz, Class<?>... args) {
try {
clazz.getDeclaredConstructor(args);
}
}
+ /**
+ * Asserts that class contains method with given name, return type and
+ * parameter types.
+ *
+ * @param clazz
+ * class to test
+ * @param returnType
+ * method return type
+ * @param name
+ * method name
+ * @param args
+ * array of parameter type classes
+ */
static void assertContainsMethod(Class<?> clazz, Class<?> returnType, String name, Class<?>... args) {
try {
Method m = clazz.getDeclaredMethod(name, args);
}
}
- static void assertContainsMethod(Class<?> clazz, String returnTypeStr, String name, ClassLoader loader)
- throws Exception {
+ /**
+ * Asserts that class contains method with given name and return type.
+ *
+ * @param clazz
+ * class to test
+ * @param returnTypeStr
+ * name of method return type
+ * @param name
+ * method name
+ * @param loader
+ * current class loader
+ */
+ static void assertContainsMethod(Class<?> clazz, String returnTypeStr, String name, ClassLoader loader) {
Class<?> returnType;
try {
returnType = Class.forName(returnTypeStr, true, loader);
assertEquals(returnType, method.getReturnType());
} catch (ClassNotFoundException e) {
throw new AssertionError("Return type of method '" + name + "' not found");
+ } catch (NoSuchMethodException e) {
+ throw new AssertionError("Method " + name + " does not exists in class " + clazz.getSimpleName());
}
}
/**
- * Check for presence of hashCode, equals and toString methods.
+ * Asserts that class containes hashCode, equals and toString methods.
*
* @param clazz
- * class to check
+ * class to test
*/
static void assertContainsDefaultMethods(Class<?> clazz) {
assertContainsMethod(clazz, Integer.TYPE, "hashCode");
}
/**
- * Check for presence of 'public static
+ * Asserts that class contains 'public static
* java.util.List<com.google.common.collect.Range<java.lang.Integer>>
* getLength()' method.
*
* @param clazz
- * class to check
+ * class to test
*/
static void assertContainsGetLength(Class<?> clazz) {
try {
}
/**
- * Test if generated source implements interface.
+ * Asserts that class implements given interface.
*
- * @param classToTest
+ * @param clazz
* source to test
- * @param ifcClass
- * expected interface type
+ * @param ifc
+ * expected interface
*/
- static void testImplementsIfc(Class<?> classToTest, Class<?> ifcClass) {
- Class<?>[] interfaces = classToTest.getInterfaces();
+ static void assertImplementsIfc(Class<?> clazz, Class<?> ifc) {
+ Class<?>[] interfaces = clazz.getInterfaces();
List<Class<?>> ifcsList = Arrays.asList(interfaces);
- if (!ifcsList.contains(ifcClass)) {
- throw new AssertionError(classToTest + " should implement " + ifcClass);
+ if (!ifcsList.contains(ifc)) {
+ throw new AssertionError(clazz + " should implement " + ifc);
}
}
* Test if interface generated from augment extends Augmentation interface
* with correct generic type.
*
- * @param classToTest
+ * @param clazz
* interface generated from augment
- * @param genericType
+ * @param genericTypeName
* fully qualified name of expected parameter type
*/
- static void testAugmentation(Class<?> classToTest, String genericType) {
- final String ifcToImplement = "interface org.opendaylight.yangtools.yang.binding.Augmentation";
- testImplementParameterizedIfc(classToTest, ifcToImplement, genericType);
+ static void testAugmentation(Class<?> clazz, String genericTypeName) {
+ final String ifcName = "interface org.opendaylight.yangtools.yang.binding.Augmentation";
+ assertImplementsParameterizedIfc(clazz, ifcName, genericTypeName);
}
- static void testImplementParameterizedIfc(Class<?> classToTest, String ifcToImplement, String genericType) {
- ParameterizedType augmentation = null;
- for (java.lang.reflect.Type ifc : classToTest.getGenericInterfaces()) {
+ /**
+ * Asserts that class implements interface with given name and generic type
+ * parameter.
+ *
+ * @param clazz
+ * class to test
+ * @param ifcName
+ * name of interface
+ * @param genericTypeName
+ * name of generic type
+ */
+ static void assertImplementsParameterizedIfc(Class<?> clazz, String ifcName, String genericTypeName) {
+ ParameterizedType ifcType = null;
+ for (java.lang.reflect.Type ifc : clazz.getGenericInterfaces()) {
if (ifc instanceof ParameterizedType) {
ParameterizedType pt = (ParameterizedType) ifc;
- if (ifcToImplement.equals(pt.getRawType().toString())) {
- augmentation = pt;
+ if (ifcName.equals(pt.getRawType().toString())) {
+ ifcType = pt;
}
}
}
- assertNotNull(augmentation);
+ assertNotNull(ifcType);
- java.lang.reflect.Type[] typeArguments = augmentation.getActualTypeArguments();
+ java.lang.reflect.Type[] typeArguments = ifcType.getActualTypeArguments();
assertEquals(1, typeArguments.length);
- assertEquals("interface " + genericType, typeArguments[0].toString());
+ assertEquals("interface " + genericTypeName, typeArguments[0].toString());
}
/**
assertTrue(compiled);
}
- static void testFilesCount(File dir, int count) {
+ /**
+ * Asserts that directory contains exactly given count of files.
+ *
+ * @param dir
+ * directory to test
+ * @param count
+ * expected count of files in directory
+ */
+ static void assertFilesCount(File dir, int count) {
File[] dirContent = dir.listFiles();
if (dirContent == null) {
throw new AssertionError("File " + dir + " doesn't exists or it's not a directory");