/*
- * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
+ * Copyright (c) 2016 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,
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.BASE_PKG;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.COMPILER_OUTPUT_PATH;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.FS;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.GENERATOR_OUTPUT_PATH;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAR;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_BAZ;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_FOO;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.NS_TEST;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsConstructor;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsField;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsMethod;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertContainsRestrictionCheck;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertFilesCount;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsIfc;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.assertImplementsParameterizedIfc;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.cleanUp;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.getSourceFiles;
-import static org.opendaylight.yangtools.sal.java.api.generator.test.CompilationTestUtils.testCompilation;
import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import org.junit.Test;
import org.opendaylight.yangtools.sal.binding.model.api.Type;
import org.opendaylight.yangtools.sal.java.api.generator.GeneratorJavaFile;
+import org.opendaylight.yangtools.sal.java.api.generator.stmt.parser.retest.RetestUtils;
import org.opendaylight.yangtools.yang.binding.ChildOf;
import org.opendaylight.yangtools.yang.binding.annotations.RoutingContext;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
@Test
public void testListGeneration() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "list-gen");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "list-gen");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "list-gen");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/list-gen", sourcesOutputDir);
// Test if all sources are generated
- File parent = new File(sourcesOutputDir, NS_TEST);
+ File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST);
final File keyArgs = new File(parent, "KeyArgs.java");
final File links = new File(parent, "Links.java");
final File linksBuilder = new File(parent, "LinksBuilder.java");
assertTrue(linksBuilder.exists());
assertTrue(linksKey.exists());
assertTrue(testData.exists());
- assertFilesCount(parent, 6);
+ CompilationTestUtils.assertFilesCount(parent, 6);
- parent = new File(sourcesOutputDir, NS_TEST + FS + "links");
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST + CompilationTestUtils.FS + "links");
final File level = new File(parent, "Level.java");
final File linkGroup = new File(parent, "LinkGroup.java");
final File node = new File(parent, "Node.java");
assertTrue(nodeList.exists());
assertTrue(nodeListBuilder.exists());
assertTrue(nodesType.exists());
- assertFilesCount(parent, 7);
+ CompilationTestUtils.assertFilesCount(parent, 7);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
- final Class<?> keyArgsClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader);
- final Class<?> linksClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader);
- final Class<?> linksKeyClass = Class.forName(BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader);
+ final Class<?> keyArgsClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.KeyArgs", true, loader);
+ final Class<?> linksClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.Links", true, loader);
+ final Class<?> linksKeyClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008.LinksKey", true, loader);
// Test generated 'grouping key-args'
assertTrue(keyArgsClass.isInterface());
- assertContainsMethod(keyArgsClass, String.class, "getName");
- assertContainsMethod(keyArgsClass, Integer.class, "getSize");
+ CompilationTestUtils.assertContainsMethod(keyArgsClass, String.class, "getName");
+ CompilationTestUtils.assertContainsMethod(keyArgsClass, Integer.class, "getSize");
assertEquals(2, abstractMethods(keyArgsClass).size());
// Test generated 'list links'
assertTrue(linksClass.isInterface());
- assertImplementsIfc(linksClass, keyArgsClass);
+ CompilationTestUtils.assertImplementsIfc(linksClass, keyArgsClass);
// TODO: anyxml
assertEquals(6, abstractMethods(linksClass).size());
// Test list key constructor arguments ordering
- assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class);
+ CompilationTestUtils.assertContainsConstructor(linksKeyClass, Byte.class, String.class, Integer.class);
// Test serialVersionUID generation
- final Field suid = assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE);
+ final Field suid = CompilationTestUtils.assertContainsField(linksKeyClass, "serialVersionUID", Long.TYPE);
suid.setAccessible(true);
assertEquals(-8829501012356283881L, suid.getLong(null));
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
public void testAugmentUnderUsesGeneration() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "augment-under-uses");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "augment-under-uses");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "augment-under-uses");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/augment-under-uses", sourcesOutputDir);
// Test if all sources were generated from 'module foo'
- File parent = new File(sourcesOutputDir, NS_FOO);
+ File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
assertTrue(new File(parent, "Object.java").exists());
assertTrue(new File(parent, "ClosedObject.java").exists());
assertTrue(new File(parent, "OpenObject.java").exists());
assertTrue(new File(parent, "ExplicitRouteObject.java").exists());
assertTrue(new File(parent, "PathKeySubobject.java").exists());
- assertFilesCount(parent, 9);
+ CompilationTestUtils.assertFilesCount(parent, 9);
parent = new File(parent, "object");
assertTrue(new File(parent, "Nodes.java").exists());
assertTrue(new File(parent, "NodesBuilder.java").exists());
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
- parent = new File(sourcesOutputDir, NS_FOO + FS + "closed");
- assertFilesCount(parent, 1);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "closed");
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "object");
assertTrue(new File(parent, "Link1.java").exists());
assertTrue(new File(parent, "Link1Builder.java").exists());
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
- parent = new File(sourcesOutputDir, NS_FOO + FS + "open");
- assertFilesCount(parent, 1);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "open");
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "object");
assertTrue(new File(parent, "Nodes1.java").exists());
assertTrue(new File(parent, "Nodes1Builder.java").exists());
- assertFilesCount(parent, 3);
+ CompilationTestUtils.assertFilesCount(parent, 3);
parent = new File(parent, "nodes");
assertTrue(new File(parent, "Links.java").exists());
assertTrue(new File(parent, "LinksBuilder.java").exists());
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
- parent = new File(sourcesOutputDir, NS_FOO + FS + "explicit");
- assertFilesCount(parent, 1);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "explicit");
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "route");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "object");
assertTrue(new File(parent, "Subobjects.java").exists());
assertTrue(new File(parent, "SubobjectsBuilder.java").exists());
- assertFilesCount(parent, 3);
+ CompilationTestUtils.assertFilesCount(parent, 3);
parent = new File(parent, "subobjects");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "subobject");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "type");
assertTrue(new File(parent, "PathKey.java").exists());
assertTrue(new File(parent, "PathKeyBuilder.java").exists());
- assertFilesCount(parent, 3);
+ CompilationTestUtils.assertFilesCount(parent, 3);
parent = new File(parent, "path");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "key");
assertTrue(new File(parent, "PathKey.java").exists());
assertTrue(new File(parent, "PathKeyBuilder.java").exists());
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
// Test if all sources were generated from 'module bar'
- parent = new File(sourcesOutputDir, NS_BAR);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
assertTrue(new File(parent, "BasicExplicitRouteSubobjects.java").exists());
assertTrue(new File(parent, "ExplicitRouteSubobjects.java").exists());
assertTrue(new File(parent, "RouteSubobjects.java").exists());
- assertFilesCount(parent, 5);
+ CompilationTestUtils.assertFilesCount(parent, 5);
parent = new File(parent, "route");
- assertFilesCount(parent, 1);
- parent = new File(new File(sourcesOutputDir, NS_BAR), "basic");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
+ parent = new File(new File(sourcesOutputDir, CompilationTestUtils.NS_BAR), "basic");
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "explicit");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "route");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "subobjects");
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
assertTrue(new File(parent, "SubobjectType.java").exists());
parent = new File(parent, "subobject");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.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());
- assertFilesCount(parent, 4);
+ CompilationTestUtils.assertFilesCount(parent, 4);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
public void testAugmentOfAugmentGeneration() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "aug-of-aug");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "aug-of-aug");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "aug-of-aug");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/augment-of-augment", sourcesOutputDir);
// Test if all sources were generated from 'module foo'
- File parent = new File(sourcesOutputDir, NS_FOO);
+ File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
final File fooListener = new File(parent, "FooListener.java");
File pathAttributes = new File(parent, "PathAttributes.java");
final File update = new File(parent, "Update.java");
assertTrue(pathAttributes.exists());
assertTrue(update.exists());
assertTrue(updateBuilder.exists());
- assertFilesCount(parent, 6);
+ CompilationTestUtils.assertFilesCount(parent, 6);
- parent = new File(sourcesOutputDir, NS_FOO + FS + "path");
- assertFilesCount(parent, 1);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "path");
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "attributes");
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
final File origin = new File(parent, "Origin.java");
final File originBuilder = new File(parent, "OriginBuilder.java");
assertTrue(origin.exists());
assertTrue(originBuilder.exists());
- parent = new File(sourcesOutputDir, NS_FOO + FS + "update");
- assertFilesCount(parent, 2);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO + CompilationTestUtils.FS + "update");
+ CompilationTestUtils.assertFilesCount(parent, 2);
pathAttributes = new File(parent, "PathAttributes.java");
final File pathAttributesBuilder = new File(parent, "PathAttributesBuilder.java");
assertTrue(pathAttributes.exists());
assertTrue(pathAttributesBuilder.exists());
// Test if all sources were generated from 'module bar'
- parent = new File(sourcesOutputDir, NS_BAR);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
final File destination = new File(parent, "Destination.java");
final File pathAttributes1 = new File(parent, "PathAttributes1.java");
final File pathAttributes1Builder = new File(parent, "PathAttributes1Builder.java");
assertTrue(destination.exists());
assertTrue(pathAttributes1.exists());
assertTrue(pathAttributes1Builder.exists());
- assertFilesCount(parent, 5);
+ CompilationTestUtils.assertFilesCount(parent, 5);
- parent = new File(sourcesOutputDir, NS_BAR + FS + "destination");
- assertFilesCount(parent, 2);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "destination");
+ CompilationTestUtils.assertFilesCount(parent, 2);
final File destinationType = new File(parent, "DestinationType.java");
assertTrue(destinationType.exists());
parent = new File(parent, "destination");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "type");
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
final File destinationIpv4 = new File(parent, "DestinationIp.java");
final File destinationIpv4Builder = new File(parent, "DestinationIpBuilder.java");
assertTrue(destinationIpv4.exists());
assertTrue(destinationIpv4Builder.exists());
- parent = new File(sourcesOutputDir, NS_BAR + FS + "update");
- assertFilesCount(parent, 1);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR + CompilationTestUtils.FS + "update");
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "path");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "attributes");
final File mpUnreachNlri = new File(parent, "MpUnreachNlri.java");
final File mpUnreachNlriBuilder = new File(parent, "MpUnreachNlriBuilder.java");
assertTrue(mpUnreachNlri.exists());
assertTrue(mpUnreachNlriBuilder.exists());
- assertFilesCount(parent, 3);
+ CompilationTestUtils.assertFilesCount(parent, 3);
parent = new File(parent, "mp");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "unreach");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "nlri");
final File withdrawnRoutes = new File(parent, "WithdrawnRoutes.java");
final File withdrawnRoutesBuilder = new File(parent, "WithdrawnRoutesBuilder.java");
assertTrue(withdrawnRoutes.exists());
assertTrue(withdrawnRoutesBuilder.exists());
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
// Test if all sources were generated from 'module baz'
- parent = new File(sourcesOutputDir, NS_BAZ);
- assertFilesCount(parent, 2);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ);
+ CompilationTestUtils.assertFilesCount(parent, 2);
final File linkstateDestination = new File(parent, "LinkstateDestination.java");
assertTrue(linkstateDestination.exists());
- parent = new File(sourcesOutputDir, NS_BAZ + FS + "update");
- assertFilesCount(parent, 1);
+ parent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAZ + CompilationTestUtils.FS + "update");
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "path");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "attributes");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "mp");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "unreach");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "nlri");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "withdrawn");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "routes");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "destination");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "type");
final File destinationLinkstate = new File(parent, "DestinationLinkstate.java");
final File destinationLinkstateBuilder = new File(parent, "DestinationLinkstateBuilder.java");
assertTrue(destinationLinkstate.exists());
assertTrue(destinationLinkstateBuilder.exists());
- assertFilesCount(parent, 3);
+ CompilationTestUtils.assertFilesCount(parent, 3);
parent = new File(parent, "destination");
- assertFilesCount(parent, 1);
+ CompilationTestUtils.assertFilesCount(parent, 1);
parent = new File(parent, "linkstate");
final File links = new File(parent, "Links.java");
final File linksBuilder = new File(parent, "LinksBuilder.java");
assertTrue(links.exists());
assertTrue(linksBuilder.exists());
- assertFilesCount(parent, 3);
+ CompilationTestUtils.assertFilesCount(parent, 3);
parent = new File(parent, "links");
final File source = new File(parent, "Source.java");
final File sourceBuilder = new File(parent, "SourceBuilder.java");
assertTrue(source.exists());
assertTrue(sourceBuilder.exists());
- assertFilesCount(parent, 3);
+ CompilationTestUtils.assertFilesCount(parent, 3);
parent = new File(parent, "source");
final File address = new File(parent, "Address.java");
final File addressBuilder = new File(parent, "AddressBuilder.java");
assertTrue(address.exists());
assertTrue(addressBuilder.exists());
- assertFilesCount(parent, 2);
+ CompilationTestUtils.assertFilesCount(parent, 2);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
public void testLeafReturnTypes() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "leaf-return-types");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "leaf-return-types");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "leaf-return-types");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/leaf-return-types", sourcesOutputDir);
- final File parent = new File(sourcesOutputDir, NS_TEST);
+ final File parent = new File(sourcesOutputDir, CompilationTestUtils.NS_TEST);
assertTrue(new File(parent, "TestData.java").exists());
assertTrue(new File(parent, "Nodes.java").exists());
assertTrue(new File(parent, "NodesBuilder.java").exists());
assertTrue(new File(parent, "Alg.java").exists());
assertTrue(new File(parent, "NodesIdUnionBuilder.java").exists());
- assertFilesCount(parent, 5);
+ CompilationTestUtils.assertFilesCount(parent, 5);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
- final String pkg = BASE_PKG + ".urn.opendaylight.test.rev131008";
+ final String pkg = CompilationTestUtils.BASE_PKG + ".urn.opendaylight.test.rev131008";
final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
final Class<?> nodesClass = Class.forName(pkg + ".Nodes", true, loader);
final Class<?> builderClass = Class.forName(pkg + ".NodesBuilder", true, loader);
// Test methods return type
final byte[] b = new byte[] {};
- assertContainsMethod(nodesClass, b.getClass(), "getIdBinary");
- assertContainsMethod(nodesClass, pkg + ".Nodes$IdBits", "getIdBits", loader);
- assertContainsMethod(nodesClass, Boolean.class, "isIdBoolean");
- assertContainsMethod(nodesClass, BigDecimal.class, "getIdDecimal64");
- assertContainsMethod(nodesClass, Boolean.class, "isIdEmpty");
- assertContainsMethod(nodesClass, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader);
+ CompilationTestUtils.assertContainsMethod(nodesClass, b.getClass(), "getIdBinary");
+ 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, pkg + ".Nodes$IdEnumeration", "getIdEnumeration", loader);
testReturnTypeIdentityref(nodesClass, "getIdIdentityref", pkg + ".Alg");
testReturnTypeInstanceIdentitifer(loader, nodesClass, "getIdInstanceIdentifier");
- assertContainsMethod(nodesClass, Byte.class, "getId8");
- assertContainsMethod(nodesClass, Short.class, "getId16");
- assertContainsMethod(nodesClass, Integer.class, "getId32");
- assertContainsMethod(nodesClass, Long.class, "getId64");
- assertContainsMethod(nodesClass, Long.class, "getIdLeafref");
- assertContainsMethod(nodesClass, String.class, "getIdString");
- assertContainsMethod(nodesClass, Short.class, "getIdU8");
- assertContainsMethod(nodesClass, Integer.class, "getIdU16");
- assertContainsMethod(nodesClass, Long.class, "getIdU32");
- assertContainsMethod(nodesClass, BigInteger.class, "getIdU64");
- assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader);
+ CompilationTestUtils.assertContainsMethod(nodesClass, Byte.class, "getId8");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getId16");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getId32");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getId64");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdLeafref");
+ CompilationTestUtils.assertContainsMethod(nodesClass, String.class, "getIdString");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Short.class, "getIdU8");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Integer.class, "getIdU16");
+ CompilationTestUtils.assertContainsMethod(nodesClass, Long.class, "getIdU32");
+ CompilationTestUtils.assertContainsMethod(nodesClass, BigInteger.class, "getIdU64");
+ CompilationTestUtils.assertContainsMethod(nodesClass, pkg + ".Nodes$IdUnion", "getIdUnion", loader);
final Object builderObj = builderClass.newInstance();
- Method m = assertContainsMethod(builderClass, builderClass, "setIdBinary", b.getClass());
+ Method m = 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);
- assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg);
+ CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg);
- m = assertContainsMethod(builderClass, builderClass, "setIdDecimal64", BigDecimal.class);
+ m = 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);
- assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1);
+ CompilationTestUtils.assertContainsRestrictionCheck(builderObj, m, expectedMsg, arg1);
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
public void testGenerationContextReferenceExtension() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "context-reference");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "context-reference");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "context-reference");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/context-reference", sourcesOutputDir);
// Test if all sources are generated
- final File fooParent = new File(sourcesOutputDir, NS_FOO);
- assertFilesCount(fooParent, 3);
+ final File fooParent = new File(sourcesOutputDir, CompilationTestUtils.NS_FOO);
+ CompilationTestUtils.assertFilesCount(fooParent, 3);
assertTrue(new File(fooParent, "FooData.java").exists());
assertTrue(new File(fooParent, "Nodes.java").exists());
assertTrue(new File(fooParent, "NodesBuilder.java").exists());
- final File barParent = new File(sourcesOutputDir, NS_BAR);
- assertFilesCount(barParent, 1);
+ final File barParent = new File(sourcesOutputDir, CompilationTestUtils.NS_BAR);
+ CompilationTestUtils.assertFilesCount(barParent, 1);
assertTrue(new File(barParent, "IdentityClass.java").exists());
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
- final Class<?> nodesClass = Class.forName(BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader);
+ final Class<?> nodesClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.foo.rev131008.Nodes", true, loader);
final Class<?> identityClass = Class
- .forName(BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader);
+ .forName(CompilationTestUtils.BASE_PKG + ".urn.opendaylight.bar.rev131008.IdentityClass", true, loader);
// test identity
try {
throw new AssertionError("Method getId() not found");
}
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
public void compilationTest() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "yang");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "yang");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "yang");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "yang");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/yang", sourcesOutputDir);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
public void testBug586() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug586");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug586");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug586");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug586");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/bug586", sourcesOutputDir);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
+ @Test
+ public void testBug4760() throws Exception {
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760");
+ assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug4760");
+ assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+
+ generateTestSources("/compilation/bug4760", sourcesOutputDir);
+
+ // Test if sources are compilable
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
/**
*/
@Test
public void testBug1172() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1172");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1172");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1172");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/bug1172", sourcesOutputDir);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
+ @Test
+ public void testBug5461() throws Exception {
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461");
+ assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5461");
+ assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+
+ generateTestSources("/compilation/bug5461", sourcesOutputDir);
+
+ // Test if sources are compilable
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
+ }
+
+ @Test
+ public void testBug5788() throws Exception {
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788");
+ assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug5788");
+ assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
+
+ generateTestSources("/compilation/bug5788", sourcesOutputDir);
+
+ // Test if sources are compilable
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
/**
*/
@Test
public void testBug1377() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "bug1377");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "bug1377");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "bug1377");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/bug1377", sourcesOutputDir);
// Test if sources are compilable
- testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
final ClassLoader loader = new URLClassLoader(new URL[] { compiledOutputDir.toURI().toURL() });
- final Class<?> outputActionClass = Class.forName(BASE_PKG
+ final Class<?> outputActionClass = Class.forName(CompilationTestUtils.BASE_PKG
+ ".urn.test.foo.rev140717.action.action.output.action._case.OutputAction", true, loader);
- final Class<?> actionClass = Class.forName(BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader);
+ final Class<?> actionClass = Class.forName(CompilationTestUtils.BASE_PKG + ".urn.test.foo.rev140717.Action", true, loader);
// Test generated 'container output-action'
assertTrue(outputActionClass.isInterface());
- assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName());
+ CompilationTestUtils.assertImplementsParameterizedIfc(outputActionClass, ChildOf.class.toString(), actionClass.getCanonicalName());
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
@Test
public void classNamesColisionTest() throws Exception {
- final File sourcesOutputDir = new File(GENERATOR_OUTPUT_PATH + FS + "class-name-collision");
+ final File sourcesOutputDir = new File(CompilationTestUtils.GENERATOR_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision");
assertTrue("Failed to create test file '" + sourcesOutputDir + "'", sourcesOutputDir.mkdir());
- final File compiledOutputDir = new File(COMPILER_OUTPUT_PATH + FS + "class-name-collision");
+ final File compiledOutputDir = new File(CompilationTestUtils.COMPILER_OUTPUT_PATH + CompilationTestUtils.FS + "class-name-collision");
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
generateTestSources("/compilation/class-name-collision", sourcesOutputDir);
- testCompilation(sourcesOutputDir, compiledOutputDir);
- cleanUp(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.testCompilation(sourcesOutputDir, compiledOutputDir);
+ CompilationTestUtils.cleanUp(sourcesOutputDir, compiledOutputDir);
}
private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
- final List<File> sourceFiles = getSourceFiles(resourceDirPath);
- final SchemaContext context = parser.parseFiles(sourceFiles);
+ final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
+ final SchemaContext context = RetestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
Collections.sort(types, new Comparator<Type>() {
@Override