import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
-import javax.annotation.Nullable;
import org.junit.Test;
import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
+import org.opendaylight.yangtools.yang.common.Empty;
/**
* Test correct code generation.
assertTrue(nodeList.exists());
assertTrue(nodeListBuilder.exists());
assertTrue(nodesType.exists());
- CompilationTestUtils.assertFilesCount(parent, 7);
+ CompilationTestUtils.assertFilesCount(parent, 8);
// Test if sources are compilable
CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
assertTrue(keyArgsClass.isInterface());
CompilationTestUtils.assertContainsMethod(keyArgsClass, String.class, "getName");
CompilationTestUtils.assertContainsMethod(keyArgsClass, Integer.class, "getSize");
- assertEquals(2, abstractMethods(keyArgsClass).size());
+ assertEquals(3, abstractMethods(keyArgsClass).size());
// Test generated 'list links'
assertTrue(linksClass.isInterface());
CompilationTestUtils.assertImplementsIfc(linksClass, keyArgsClass);
- // TODO: anyxml
- assertEquals(6, abstractMethods(linksClass).size());
+ assertEquals(7, abstractMethods(linksClass).size());
// Test list key constructor arguments ordering
CompilationTestUtils.assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class);
CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader);
CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean");
CompilationTestUtils.assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64");
- CompilationTestUtils.assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Empty.class, "getIdEmpty");
CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader);
testReturnTypeIdentityref(nodesClass, "getIdIdentityref", pkg + ".Alg");
testReturnTypeInstanceIdentitifer(loader, nodesClass, "getIdInstanceIdentifier");
CompilationTestUtils.assertContainsMethod(nodesClass, BigInteger.class, "getIdU64");
CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader);
- final Object builderObj = builderClass.newInstance();
+ final Object builderObj = builderClass.getDeclaredConstructor().newInstance();
- Method m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass());
+ Method method = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdBinary",
+ b.getClass());
final List<Range<Integer>> lengthConstraints = new ArrayList<>();
lengthConstraints.add(Range.closed(1, 10));
byte[] arg = new byte[] {};
String expectedMsg = String.format("Invalid length: %s, expected: %s.", Arrays.toString(arg),
lengthConstraints);
- CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg);
+ CompilationTestUtils.assertContainsRestrictionCheck(builderObj, method, expectedMsg, arg);
- m = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class);
+ method = CompilationTestUtils.assertContainsMethod(builderClass, builderClass, "setIdDecimal64",
+ BigDecimal.class);
final List<Range<BigDecimal>> rangeConstraints = new ArrayList<>();
rangeConstraints.add(Range.closed(new BigDecimal("1.5"), new BigDecimal("5.5")));
Object arg1 = new BigDecimal("1.4");
expectedMsg = String.format("Invalid range: %s, expected: %s.", arg1, rangeConstraints);
- CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1);
+ CompilationTestUtils.assertContainsRestrictionCheck(builderObj, method, expectedMsg, arg1);
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
throw new AssertionError("Method getId() not found", e);
}
- assertEquals(ImmutableSet.of(RoutingContext.class, Nullable.class), Arrays.stream(getId.getAnnotations())
+ assertEquals(ImmutableSet.of(RoutingContext.class), Arrays.stream(getId.getAnnotations())
.map(Annotation::annotationType).collect(Collectors.toSet()));
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
/**
* Test handling nested uses-augmentations.
- *
- * @throws Exception
*/
@Test
public void testBug1172() throws Exception {
assertTrue(new File(parent, "TypedefCurrent.java").exists());
assertTrue(new File(parent, "TypedefDeprecated.java").exists());
- final String pkg = CompilationTestUtils.BASE_PKG + ".urn.yang.foo.rev160102";
- final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
- final Class<?> cls = loader.loadClass(pkg + ".FooData");
- final Class<?> clsContainer = loader.loadClass(pkg + ".ContainerMain");
- final Class<?> clsTypedefDepr = loader.loadClass(pkg + ".TypedefDeprecated");
- final Class<?> clsTypedefCur = loader.loadClass(pkg + ".TypedefCurrent");
- final Class<?> clsGroupingDepr = loader.loadClass(pkg + ".GroupingDeprecated");
- final Class<?> clsGroupingCur = loader.loadClass(pkg + ".GroupingCurrent");
- final Class<?> clsTypeDef1 = loader.loadClass(pkg + ".Typedef1");
- final Class<?> clsTypeDef2 = loader.loadClass(pkg + ".Typedef2");
- final Class<?> clsTypeDef3 = loader.loadClass(pkg + ".Typedef3");
- assertTrue(clsTypedefDepr.getAnnotations()[0].toString().contains("Deprecated"));
- assertTrue(clsTypedefCur.getAnnotations().length == 0);
- assertTrue(clsGroupingDepr.getAnnotations()[0].toString().contains("Deprecated"));
- assertTrue(clsGroupingCur.getAnnotations().length == 0);
- assertTrue(clsTypeDef1.getAnnotations().length == 0);
- assertTrue(clsTypeDef3.getAnnotations().length == 0);
- assertTrue(clsTypeDef2.getAnnotations()[0].toString().contains("Deprecated"));
-
- /*methods inside container*/
- assertTrue(clsContainer.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
- assertTrue(clsContainer.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
- assertTrue(clsContainer.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
- assertFalse(clsContainer.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
- assertFalse(clsContainer.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
- assertFalse(clsContainer.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
-
- /*methods inside module*/
- assertTrue(cls.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
- assertTrue(cls.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
- assertTrue(cls.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
- assertFalse(cls.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
- assertFalse(cls.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
- assertFalse(cls.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
- assertTrue(cls.getMethod("getLeafDeprecated").isAnnotationPresent(Deprecated.class));
+ try (URLClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() })) {
+ final String pkg = CompilationTestUtils.BASE_PKG + ".urn.yang.foo.rev160102";
+ final Class<?> cls = loader.loadClass(pkg + ".FooData");
+ final Class<?> clsContainer = loader.loadClass(pkg + ".ContainerMain");
+ final Class<?> clsTypedefDepr = loader.loadClass(pkg + ".TypedefDeprecated");
+ final Class<?> clsTypedefCur = loader.loadClass(pkg + ".TypedefCurrent");
+ final Class<?> clsGroupingDepr = loader.loadClass(pkg + ".GroupingDeprecated");
+ final Class<?> clsGroupingCur = loader.loadClass(pkg + ".GroupingCurrent");
+ final Class<?> clsTypeDef1 = loader.loadClass(pkg + ".Typedef1");
+ final Class<?> clsTypeDef2 = loader.loadClass(pkg + ".Typedef2");
+ final Class<?> clsTypeDef3 = loader.loadClass(pkg + ".Typedef3");
+ assertTrue(clsTypedefDepr.getAnnotations()[0].toString().contains("Deprecated"));
+ assertTrue(clsTypedefCur.getAnnotations().length == 0);
+ assertTrue(clsGroupingDepr.getAnnotations()[0].toString().contains("Deprecated"));
+ assertTrue(clsGroupingCur.getAnnotations().length == 0);
+ assertTrue(clsTypeDef1.getAnnotations().length == 0);
+ assertTrue(clsTypeDef3.getAnnotations().length == 0);
+ assertTrue(clsTypeDef2.getAnnotations()[0].toString().contains("Deprecated"));
+
+ /*methods inside container*/
+ assertTrue(clsContainer.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(clsContainer.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(clsContainer.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
+ assertFalse(clsContainer.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(clsContainer.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(clsContainer.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
+
+ /*methods inside module*/
+ assertTrue(cls.getMethod("getContainerMainLeafDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(cls.getMethod("getContainerMainListDepr").isAnnotationPresent(Deprecated.class));
+ assertTrue(cls.getMethod("getContainerMainChoiceDepr").isAnnotationPresent(Deprecated.class));
+ assertFalse(cls.getMethod("getContainerMainLeafCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(cls.getMethod("getContainerMainListCurrent").isAnnotationPresent(Deprecated.class));
+ assertFalse(cls.getMethod("getContainerMainChoiceCur").isAnnotationPresent(Deprecated.class));
+ assertTrue(cls.getMethod("getLeafDeprecated").isAnnotationPresent(Deprecated.class));
+ }
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
/**
* Test if class generated for node from grouping implements ChildOf.
- *
- * @throws Exception
*/
@Test
public void testBug1377() throws Exception {
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
+ @Test
+ public void testMdsal395() throws Exception {
+ final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal395");
+ final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal395");
+ generateTestSources("/compilation/mdsal395", sourcesOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
@Test
public void classNamesColisionTest() throws Exception {
final File sourcesOutputDir = CompilationTestUtils.generatorOutput("class-name-collision");
CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
+ @Test
+ public void testMdsal425() throws Exception {
+ final File sourcesOutputDir = CompilationTestUtils.generatorOutput("mdsal425");
+ final File compiledOutputDir = CompilationTestUtils.compilerOutput("mdsal425");
+ generateTestSources("/compilation/mdsal425", sourcesOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
private static void testReturnTypeIdentityref(final Class<?> clazz, final String methodName,
final String returnTypeStr) throws NoSuchMethodException {
Method method = clazz.getMethod(methodName);
private static void testReturnTypeInstanceIdentitifer(final ClassLoader loader, final Class<?> clazz,
final String methodName) throws ClassNotFoundException, NoSuchMethodException, SecurityException {
- Method method;
- Class<?> rawReturnType;
- java.lang.reflect.Type returnType;
- method = clazz.getMethod(methodName);
- rawReturnType = Class.forName("org.opendaylight.yangtools.yang.binding.InstanceIdentifier", true, loader);
+ final Method method = clazz.getMethod(methodName);
+ final Class<?> rawReturnType = Class.forName("org.opendaylight.yangtools.yang.binding.InstanceIdentifier", true,
+ loader);
assertEquals(rawReturnType, method.getReturnType());
- returnType = method.getGenericReturnType();
+ final java.lang.reflect.Type returnType = method.getGenericReturnType();
assertTrue(returnType instanceof ParameterizedType);
final ParameterizedType pt = (ParameterizedType) returnType;
final java.lang.reflect.Type[] parameters = pt.getActualTypeArguments();